Abhinandan Bharamgunde
Abhinandan Bharamgunde

Reputation: 207

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

I am kind of new to AKS deployment with volume mount. I want to create a pod in AKS with image; 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).

Below is the docker command that is working on local machine.

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

I want to achieve same thing in AKS. When I tried to deploy same using Azure File Mount (with PersistentVolumeClaim) volume is getting attached. The question now is how to pass config.yaml file to that pod. I tried uploading config.yaml file to Azure File Share Volume that is attached in POD deployment without any success.

Below is the pod deployment file that I used

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.

Thanks in advance.

Upvotes: 0

Views: 1705

Answers (1)

hariK
hariK

Reputation: 3059

Create a kubernetes secret using config.yaml file.

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

Mount it as a volume in the 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.

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

Upvotes: 2

Related Questions