secce 发表于 2019-2-21 06:33:12

通过Kubernetes在Docker容器挂载Azure文件存储

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.jpga
root@nginx:/mnt/azure# df-Th
Filesystem                                          Type   SizeUsed Avail Use% Mounted on
overlay                                             overlay   30G4.1G   25G15% /
tmpfs                                                 tmpfs    966M   0966M   0% /dev
tmpfs                                                 tmpfs    966M   0966M   0% /sys/fs/cgroup
//imagesdisks845.file.core.chinacloudapi.cn/azurefile cifs   5.0T128K5.0T   1% /mnt/azure
/dev/sda1                                             ext4      30G4.1G   25G15% /etc/hosts
shm                                                   tmpfs   64M   0   64M   0% /dev/shm
tmpfs                                                 tmpfs    966M   12K966M   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs                                                 tmpfs    966M   0966M   0% /sys/firmware
root@nginx:/mnt/azure# touch k8stest
root@nginx:/mnt/azure# ls
2.2.jpgak8stest
root@nginx:/mnt/azure#

管理门户中验证,确认将正确的文件共享名写入azure.yaml中,与下图保持一致:
http://s1.运维网.com/images/20180912/1536716678135746.png



页: [1]
查看完整版本: 通过Kubernetes在Docker容器挂载Azure文件存储