Použití trvalého svazku v AKS ve Azure Stack clusteru HCIUse persistent volume in an AKS on Azure Stack HCI cluster
Platí pro: AKS on Azure Stack HCI, AKS runtime na Windows serveru 2019 DatacenterApplies to: AKS on Azure Stack HCI, AKS runtime on Windows Server 2019 Datacenter
Trvalý svazek představuje část úložiště, která byla zřízena pro použití s Kubernetes lusky.A persistent volume represents a piece of storage that has been provisioned for use with Kubernetes pods. Trvalý svazek lze použít v jednom nebo více luskech a je určen pro dlouhodobé uložení.A persistent volume can be used by one or more pods and is meant for long-term storage. Je také nezávislá na životním cyklu pod nebo Node.It's also independent of pod or node lifecycle. I když můžete zřídit okruh PVC pro uzly Windows i Linux, v této části se dozvíte, jak vytvořit trvalý svazek a jak tento svazek použít v aplikaci pro Windows.While you can provision a PVC for both Windows and Linux nodes, in this section, you'll see how to create a persistent volume and how to use this volume in your Windows application. Další informace najdete v tématu trvalé svazky v Kubernetes.For more information, see Persistent volumes in Kubernetes.
Než začneteBefore you begin
Tady je přehled toho, co potřebujete, abyste mohli začít:Here's what you need to get started:
- Cluster Kubernetes s alespoň jedním pracovním uzlem systému Windows.A Kubernetes cluster with at least one Windows worker node.
- Soubor kubeconfig pro přístup ke clusteru Kubernetes.A kubeconfig file to access the Kubernetes cluster.
Vytvoření deklarace identity trvalého svazkuCreate a persistent volume claim
Deklarace identity trvalého svazku se používá k automatickému zřízení úložiště na základě třídy úložiště.A persistent volume claim is used to automatically provision storage based on a storage class. Chcete-li vytvořit deklaraci identity svazku, nejprve vytvořte soubor s názvem pvc-akshci-csi.yaml
a zkopírujte následující definici YAML.To create a volume claim, first create a file named pvc-akshci-csi.yaml
and copy in the following YAML definition. Deklarace identity vyžaduje disk o velikosti 10 GB s přístupem ReadWriteOnce .The claim requests a disk that is 10 GB in size with ReadWriteOnce access. *Výchozí* třída úložiště je zadána jako třída úložiště (VHDX).The default storage class is specified as the storage class (vhdx).
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-akshci-csi
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Vytvořte svazek spuštěním následujících příkazů v relaci PowerShellu pro správu na jednom ze serverů v clusteru Azure Stack HCI (pomocí metody, jako je například Enter-PSSession nebo Vzdálená plocha pro připojení k serveru):Create the volume by running the following commands in an administrative PowerShell session on one of the servers in the Azure Stack HCI cluster (using a method such as Enter-PSSession or Remote Desktop to connect to the server):
kubectl create -f pvc-akshci-csi.yaml
Následující výstup zobrazí, že se úspěšně vytvořila deklarace identity trvalého svazku:The following output will show that your persistent volume claim has been created successfully:
VýkonemOutput:
persistentvolumeclaim/pvc-akshci-csi created
Použít trvalý svazekUse persistent volume
Chcete-li použít trvalý svazek, vytvořte soubor s názvem winwebserver. yaml a zkopírujte následující definici YAML.To use a persistent volume, create a file named winwebserver.yaml and copy in the following YAML definition. Pak vytvoříte pod tím, že budete mít přístup k deklaraci identity trvalého svazku a VHDX.You will then create a pod with access to the persistent volume claim and vhdx.
V níže uvedené definici YAML je mountPath cesta k připojení svazku uvnitř kontejneru.In the yaml definition below, mountPath is the path to mount a volume inside a container. Po úspěšném vytvoření pod se zobrazí podadresář mnt vytvořený v C \ : a podadresář akshciscsi vytvořený v mnt.After a successful pod creation, you will see the subdirectory mnt created in C:\ and the subdirectory akshciscsi created inside mnt.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
replicas: 1
selector:
matchLabels:
app: win-webserver
template:
metadata:
labels:
app: win-webserver
name: win-webserver
spec:
containers:
- name: windowswebserver
image: mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
ports:
- containerPort: 80
volumeMounts:
- name: akshciscsi
mountPath: "/mnt/akshciscsi"
volumes:
- name: akshciscsi
persistentVolumeClaim:
claimName: pvc-akshci-csi
nodeSelector:
kubernetes.io/os: windows
Pokud chcete vytvořit pod výše uvedenou definicí YAML, spusťte:To create a pod with the above yaml definition, run:
kubectl create -f winwebserver.yaml
Chcete-li se ujistit, že je pod ním spuštěný, spusťte následující příkaz.To make sure the pod is running, run the following command. Počkejte několik minut, než je v běžícím stavu, protože načítání image trvá déle.Wait a few minutes until the pod is in a running state, since pulling the image takes time.
kubectl get pods -o wide
Jakmile je spuštěno, zobrazte stav pod spuštěním následujícího příkazu:Once your pod is running, view the pod status by running the following command:
kubectl.exe describe pod %podName%
Chcete-li ověřit, zda byl svazek připojen v části pod, spusťte následující příkaz:To verify your volume has been mounted in the pod, run the following command:
kubectl exec -it %podname% cmd.exe
Odstranění deklarace identity trvalého svazkuDelete a persistent volume claim
Před odstraněním deklarace identity trvalého svazku je nutné nasazení aplikace odstranit spuštěním:Before deleting a persistent volume claim, you must delete the app deployment by running:
kubectl delete deployments win-webserver
Pak můžete odstranit vynucenou deklaraci identity trvalého svazku spuštěním:You can then delete a persistent volume claim by running:
kubectl delete PersistentVolumeClaim pvc-akshci-csi