1。通过acs-engine创建k8s。
2。SSH k8s master,创建secret,通过k8s文件创建secret:
在这个yaml文件中,我们应该在其中写入存储帐户和密钥,我们应该使用base64编码的Azure存储帐户和密钥,如下所示:
root@k8s-master-37117435-0:~# echo -n imagesdisks845 |base64
root@k8s-master-37117435-0:~# echo -n XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |base64
root@k8s-master-37117435-0:~# cd /azure_file/
root@k8s-master-37117435-0:/azure_file# vim azure-secret.yaml
root@k8s-master-37117435-0:/azure_file# cat azure-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: azure-secret
type: Opaque
data:
azurestorageaccountname: aW1hZ2VzZGlza3M4NDU=
azurestorageaccountkey: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create pod: create azure.yaml:
root@k8s-master-37117435-0:/azure_file# kubectl create -f /azure_file/azure-secret.yaml
secret "azure-secret01" created
root@k8s-master-37117435-0:/azure_file# kubectl get secret
NAME TYPE DATA AGE
azure-secret Opaque 2 3d
azure-secret01 Opaque 2 11s
default-token-7w4s9 kubernetes.io/service-account-token 3 4d
Create pod: create azure.yaml:
root@k8s-master-37117435-0:/azure_file# touch azure.yaml
root@k8s-master-37117435-0:/azure_file# ls
root@k8s-master-37117435-0:/azure_file# vim azure.yaml
root@k8s-master-37117435-0:/azure_file# cat azure.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- name: azure
mountPath: /mnt/azure
volumes:
- name: azure
azureFile:
secretName: azure-secret01
shareName: azurefile
readOnly: false
Use this file to create pod:
root@k8s-master-37117435-0:/azure_file# kubectl create -f /azure_file/azure.yaml
pod "nginx" created
root@k8s-master-37117435-0:/azure_file# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 34s
Now, pod create is completed, we can use this script to check file,like this:
root@k8s-master-37117435-0:/azure_file# kubectl exec -it nginx bash
root@nginx:/# cd /mnt
root@nginx:/mnt# ls
azure
root@nginx:/mnt# cd azure
root@nginx:/mnt/azure# ls
2.2.jpg a
root@nginx:/mnt/azure# df -Th
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 30G 4.1G 25G 15% /
tmpfs tmpfs 966M 0 966M 0% /dev
tmpfs tmpfs 966M 0 966M 0% /sys/fs/cgroup
//imagesdisks845.file.core.chinacloudapi.cn/azurefile cifs 5.0T 128K 5.0T 1% /mnt/azure
/dev/sda1 ext4 30G 4.1G 25G 15% /etc/hosts
shm tmpfs 64M 0 64M 0% /dev/shm
tmpfs tmpfs 966M 12K 966M 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs tmpfs 966M 0 966M 0% /sys/firmware
root@nginx:/mnt/azure# touch k8stest
root@nginx:/mnt/azure# ls
2.2.jpg a k8stest
root@nginx:/mnt/azure#
管理门户中验证,确认将正确的文件共享名写入azure.yaml中,与下图保持一致: