How to mount local volume hostPath with AKS?

2/13/2020

I am trying to create a Kubernetes pod and mounting a volume from local hostpath. I am using Azure Kubernetes cluster. Following is my yaml for creating pod

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - name: nginx
    image: nginx:1.7.9
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: /opt/myfolder
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /Users/kkadam/minikube/myfolder
      # this field is optional

I have few files under myfolder which I want to use inside container. Files are present in local volume but not inside container.

What could be an issue?

-- Komal Kadam
kubernetes

2 Answers

2/13/2020

You can not add local path to container running on AKS. You have to add the file on specific node where POD is scheduled.

If both are on same node POD and files then you can mount the files as the volume to the container and use it.

However if your POD is schedule to another node then you will not be able to access the files inside the container.

If due to any reason your node restarted or deleted during auto-scaling you might lose the data.

-- Harsh Manvar
Source: StackOverflow

2/13/2020

Judging by what you said in your comment and your config, especially the path /Users/kkadam/minikube/myfolder which is typically a Mac OS path, it seems that you're trying to mount your local volume (probably your mac) in a pod deployed on AKS.
That's the problem.

In order to make it work, you need to put the files you're trying to mount on the node running your pod (which is in AKS).

-- Marc ABOUCHACRA
Source: StackOverflow