Container Service for Kubernetes (ACK) allows you to mount dynamically provisioned disk volumes and statically provisioned Server Message Block (SMB) volumes to Windows pods. This topic describes how to create and mount disk volumes or SMB volumes to pods on Windows nodes.
Prerequisites
- You have the permissions to use FlexVolume.
If you do not have the permissions to use FlexVolume, Submit a ticket and apply to be added to a whitelist.
- An ACK cluster is created and FlexVolume is selected as the volume plug-in of the cluster. For more information, see Create a managed Kubernetes cluster.
- A Windows node pool is created. For more information, see Create a Windows node pool.
- A kubectl client is connected to the cluster. For more information, see Connect to ACK clusters by using kubectl.
Create and mount disk volumes to Windows pods
Alibaba Cloud disks are block storage resources for Elastic Compute Service (ECS) instances. Alibaba Cloud disks provide low latency, high performance, high durability, and high reliability.
You can perform the following steps to create and mount disk volumes to Windows pods:
Step 1: Create a StorageClass
- If the value of fstype is set to ext3, ext4, or xfs, the StorageClass is intended for the Linux file system.
- If the value of fstype is set to ntfs, the StorageClass is intended for the Windows file system.
By default, if FlexVolume is selected as the volume plug-in, the system defines StorageClasses that are intended for the Linux file system when you create an ACK cluster. You must manually define StorageClasses intended for the Windows file system.
Step 2: Install FlexVolume on Windows nodes
Step 3: Create a disk volume and mount it to a Windows pod
A StatefulSet is used as an example. You can specify the required StorageClass in the volumeClaimTemplates field. Then, the FlexVolume plug-in on the Windows worker node automatically performs the following operations: verifies your credentials, creates a disk, attaches the disk to an ECS instance, and then creates and mounts a disk volume to a Windows pod.
apiVersion: v1 kind: Service metadata: labels: app: web-windows-disk name: web-windows-disk spec: type: LoadBalancer ports: - port: 80 protocol: TCP targetPort: 80 selector: app: web-windows-disk --- apiVersion: v1 kind: Service metadata: name: web-windows-disk-headless labels: app: web-windows-disk spec: ports: - port: 80 protocol: TCP targetPort: 80 clusterIP: None selector: app: web-windows-disk --- apiVersion: apps/v1 kind: StatefulSet metadata: name: web-windows-disk spec: serviceName: "web-windows-disk-headless" selector: matchLabels: app: web-windows-disk replicas: 1 template: metadata: labels: app: web-windows-disk spec: restartPolicy: Always terminationGracePeriodSeconds: 30 tolerations: - key: os value: windows affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: beta.kubernetes.io/os operator: In values: - windows - matchExpressions: - key: kubernetes.io/os operator: In values: - windows containers: - name: windows /* Replace cn-hangzhou in the following image address with the region where your cluster is deployed. */ image: registry-vpc.cn-hangzhou.aliyuncs.com/acs/sample-web-windows:v1.0.1 volumeMounts: - name: ssd mountPath: c:/openresty/logs volumeClaimTemplates: - metadata: name: ssd spec: accessModes: - ReadWriteOnce /* Specify the supported disk type based on the zone and region where your cluster is deployed. */ storageClassName: alicloud-disk-ssd-windows resources: requests: storage: 50Gi
kubectl get pv
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
ssd-web-windows-disk-0 Bound d-wz9dihqdkusysc56**** 50Gi RWO alicloud-disk-ssd-windows 5s
Step 4: Verify that the disk volume can be used to persist data
- Run the following command to access the deployed Window application web-windows-disk:
for i in {1..2}; do; curl $(kubectl get svc web-windows-disk --template '{{ (index .status.loadBalancer.ingress 0).ip }}'); done
- Run the following command to print the log of the web-windows-disk-0 container:
kubectl logs web-windows-disk-0
Expected output:openresty started... x.x.x.x - - [14/Aug/2021:18:28:28 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:28:32 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1"
- Run the following command to delete the web-windows-disk-0 container:
kubectl delete pod web-windows-disk-0
- Run the following command to access the redeployed Windows application web-windows-disk:
for i in {1..3}; do; curl $(kubectl get svc web-windows-disk --template '{{ (index .status.loadBalancer.ingress 0).ip }}'); done
- Run the following command to print the log of the web-windows-disk-0 container:
kubectl logs web-windows-disk-0
Expected output:openresty started... x.x.x.x - - [14/Aug/2021:18:28:28 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:28:32 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" openresty started... x.x.x.x - - [14/Aug/2021:18:56:40 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:56:40 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:56:41 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1"
The log data of the redeployed web-windows-disk-0 container indicates that the log file is retained after the container for the web-windows-disk application is deleted.
Create and mount SMB volumes to Windows pods
Apsara File Storage NAS (NAS) is a distributed file system that is provided for ECS instances. NAS uses Portable Operating System Interface of UNIX (POSIX)-based APIs and is compatible with native operating systems. NAS provides shared access, ensures data consistency, and implements mutual exclusion by using locks.
SMB is a protocol that can be used by NAS and works well in Windows. Different from alicloud-disk-controller, the SMB FlexVolume plug-in is not reliant on Linux worker nodes or Kubernetes controllers.
If Kubernetes controllers are not used, the SMB FlexVolume plug-in can only statically provision PVs and cannot use StorageClasses to dynamically provision PVs.
Step 1: Install FlexVolume on Windows nodes
Install FlexVolume on all of the Windows worker nodes. For more information, see Step 2: Install FlexVolume on Windows nodes of Create and mount disk volumes to Windows pods.
Step 2: Create an SMB PV and mount the PV to a Windows pod
Step 4: Verify that the NAS file system can be used to persist data
- Run the following command to access the deployed Windows application web-windows-smb:
for i in {1..2}; do; curl $(kubectl get svc web-windows-smb --template '{{ (index .status.loadBalancer.ingress 0).ip }}'); done
- Run the following command to print the log of the web-windows-smb-584676df65-t4mmh container:
kubectl logs web-windows-smb-584676df65-t4mmh
Expected output:openresty started... x.x.x.x - - [14/Aug/2021:18:28:28 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:28:32 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1"
- Run the following command to delete the web-windows-smb-584676df65-t4mmh container:
kubectl delete pod web-windows-smb-584676df65-t4mmh
- Run the following command to access the redeployed Windows application web-windows-smb:
for i in {1..3}; do; curl $(kubectl get svc web-windows-smb --template '{{ (index .status.loadBalancer.ingress 0).ip }}'); done
- Run the following command to query the pod:
kubectl get pod
Expected output:NAME READY STATUS RESTARTS AGE web-windows-smb-584676df65-87bpz 1/1 Running 0 26d
- Run the following command to print the log of the web-windows-smb-584676df65-87bpz container:
kubectl logs web-windows-smb-584676df65-87bpz
Expected output:openresty started... x.x.x.x - - [14/Aug/2021:18:28:28 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:28:32 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" openresty started... x.x.x.x - - [14/Aug/2021:18:56:40 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:56:40 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1" x.x.x.x - - [14/Aug/2021:18:56:41 +0800] "GET / HTTP/1.1" 200 674 "-" "curl/7.64.1"
The log data of the redeployed web-windows-smb-**** container indicates that the log file is retained after the web-windows-smb-584676df65-t4mmh container is deleted.