AKS - 如何使用 pod/image 文件挂载卷

时间:2021-03-04 05:39:48

标签: docker kubernetes azure-aks docker-volume persistent-volumes

我对使用卷挂载的 AKS 部署有点陌生。我想用图像在 AKS 中创建一个 pod;该图像需要使用 config.yaml 文件(我已经拥有并且需要传递给该图像才能成功运行)的卷安装。

以下是在本地机器上运行的 docker 命令。

docker run -v <Absolute_path_of_config.yaml>:/config.yaml image:tag

我想在 AKS 中实现同样的目标。当我尝试使用 Azure File Mount(使用 PersistentVolumeClaim)部署相同的卷时,卷被附加。现在的问题是如何将 config.yaml 文件传递​​给那个 pod。我尝试将 config.yaml 文件上传到 POD 部署中附加的 Azure 文件共享卷,但没有成功。

下面是我使用的pod部署文件

kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: image:tag
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 1Gi
    volumeMounts:
    - mountPath: "/config.yaml"
      name: volume
  volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: my-azurefile-storage

需要关于如何使用本地 config.yaml 文件进行 aks 部署以便图像可以正常运行的帮助。

提前致谢。

1 个答案:

答案 0 :(得分:2)

使用 config.yaml 文件创建 kubernetes secret。

kubectl create secret generic config-yaml --from-file=config.yaml

将其安装为 pod 中的一个卷。

apiVersion: v1
kind: Pod
metadata:
  name: config
spec:
  containers:
  - name: config
    image: alpine
    command:
    - cat
    resources: {}
    tty: true
    volumeMounts:
      - name: config
        mountPath: /config.yaml
        subPath: config.yaml
  volumes:
    - name: config
      secret:
        secretName: config-yaml

执行到 pod 并查看文件。

kubectl exec -it config sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
/ # ls
bin          dev          home         media        opt          root         sbin         sys          usr
config.yaml  etc          lib          mnt          proc         run          srv          tmp          var
/ # cat config.yaml 
---
apiUrl: "https://my.api.com/api/v1"
username: admin
password: password
相关问题