1。經過acs-engine建立k8s。nginx
2。SSH k8s master,建立secret,經過k8s文件建立secret:vim
在這個yaml文件中,咱們應該在其中寫入存儲賬戶和密鑰,咱們應該使用base64編碼的Azure存儲賬戶和密鑰,以下所示:api
root@k8s-master-37117435-0:~# echo -n imagesdisks845 |base64bash
root@k8s-master-37117435-0:~# echo -n XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |base64ide
root@k8s-master-37117435-0:~# cd /azure_file/this
root@k8s-master-37117435-0:/azure_file# vim azure-secret.yaml編碼
root@k8s-master-37117435-0:/azure_file# cat azure-secret.yamlspa
apiVersion: v13d
kind: Secretrest
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中,與下圖保持一致: