1。通过acs-engine创建k8s。
2。SSH k8s master,创建secret,通过k8s文件创建secret:
在这个yaml文件中,我们应该在其中写入存储帐户和**,我们应该使用base64编码的Azure存储帐户和**,如下所示:
[email protected]:~# echo -n imagesdisks845 |base64
[email protected]:~# echo -n XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |base64
[email protected]:~# cd /azure_file/
[email protected]:/azure_file# vim azure-secret.yaml
[email protected]:/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:
[email protected]:/azure_file# kubectl create -f /azure_file/azure-secret.yaml
secret "azure-secret01" created
[email protected]:/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:
[email protected]:/azure_file# touch azure.yaml
[email protected]:/azure_file# ls
[email protected]:/azure_file# vim azure.yaml
[email protected]:/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:
[email protected]:/azure_file# kubectl create -f /azure_file/azure.yaml
pod "nginx" created
[email protected]:/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:
[email protected]:/azure_file# kubectl exec -it nginx bash
[email protected]:/# cd /mnt
[email protected]:/mnt# ls
azure
[email protected]:/mnt# cd azure
[email protected]:/mnt/azure# ls
2.2.jpg a
[email protected]:/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
[email protected]:/mnt/azure# touch k8stest
[email protected]:/mnt/azure# ls
2.2.jpg a k8stest
[email protected]:/mnt/azure#
管理门户中验证,确认将正确的文件共享名写入azure.yaml中,与下图保持一致:
转载于:https://blog.51cto.com/286722/2174072