1
votes

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?

2
is you pod scheduled on same node as where you have the hostPath !!DT.
No. I was doing this from my local system.Komal Kadam
Can you explain your setup more !!DT.
@HarshManvar I meant from my local system, not from the nodes. But I guess I will have to make sure that folder which I mapping for hostPath should exist on nodeKomal Kadam
You should create host path on aks-agentpool-29453832-vmss000000 and copy your data to that hostPath on aks node .. in short host path on your local laptop will not be mounted on AKS .. also note every time your pod is rebuild it can choose a different node and hostPath is node specific .. so if you are looking for persistent data across restarts of container you need to use nfs kind of solution ..DT.

2 Answers

2
votes

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.

1
votes

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).