简体   繁体   English

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

[英]AKS - How to mount volume with file for pod/image

I am kind of new to AKS deployment with volume mount.我对使用卷挂载的 AKS 部署有点陌生。 I want to create a pod in AKS with image;我想在 AKS 中创建一个带有图像的 pod; that image needs a volume mount with config.yaml file (that I already have and needs to be passed to that image to run successfully).该映像需要使用 config.yaml 文件进行卷挂载(我已经拥有并且需要将其传递给该映像才能成功运行)。

Below is the docker command that is working on local machine.下面是在本地机器上运行的 docker 命令。

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

I want to achieve same thing in AKS.我想在 AKS 中实现同样的目标。 When I tried to deploy same using Azure File Mount (with PersistentVolumeClaim) volume is getting attached.当我尝试使用 Azure 文件挂载(使用 PersistentVolumeClaim)进行部署时,卷已附加。 The question now is how to pass config.yaml file to that pod.现在的问题是如何将 config.yaml 文件传递给该 pod。 I tried uploading config.yaml file to Azure File Share Volume that is attached in POD deployment without any success.我尝试将 config.yaml 文件上传到 POD 部署中附加的 Azure 文件共享卷,但没有成功。

Below is the pod deployment file that I used下面是我使用的 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

Need help regarding how I can use that local config.yaml file for aks deployment so image can run properly.需要有关如何使用本地 config.yaml 文件进行 aks 部署的帮助,以便映像可以正常运行。

Thanks in advance.提前致谢。

Create a kubernetes secret using config.yaml file.使用config.yaml文件创建 kubernetes 机密。

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

Mount it as a volume in the pod.将其作为卷安装在 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

Exec to the pod and view the file.执行到 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AZURE AKS 上的 HPA 但 pod 将立即终止 state,因为它显示无法找到要安装的默认卷 - HPA on AZURE AKS but pod are immediately going in terminating state because it showing not able to find out default volume to mount 如何在卷中挂载单个文件 - How to mount a single file in a volume 如何将气流工人的体积安装到气流kubernetes吊舱操作员上? - How to mount volume of airflow worker to airflow kubernetes pod operator? 如何在 pod.yaml 中将 wsl 文件夹路径挂载为卷 - How to mount wsl folder path as volume in pod.yaml Apache Flink - 将卷挂载到 Job Pod - Apache Flink - Mount Volume to Job Pod kubernetes:在pod启动后挂载主机路径卷 - kubernetes: Mount hostpath volume after pod start 如何在Azure(容器Web应用程序)上将卷(Azure文件共享)安装到基于Bitnami的Docker映像? - How to mount a volume (Azure File Share) to a bitnami-based docker image on Azure (Web App for Container)? 如何从使用 KubernetesPodOperator 触发它的 Airflow 主机将卷挂载到运行 docker 容器的 Kubernetes Pod - How to mount a volume to a Kubernetes Pod running a docker container from the Airflow host that triggers it using the KubernetesPodOperator 在OSX上将卷装载到Docker镜像 - Mount volume to Docker image on OSX 如何在创建 docker 映像时在卷中挂载 jdk 并在容器中使用它 - how to mount jdk in volume and use it in a container while creating a docker image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM