stewchicken
stewchicken

Reputation: 531

k8s initContainer mountPath does not exist after kubectl pod deployment

Below is deployment yaml, after deployment, I could access the pod and I can see the mountPath "/usr/share/nginx/html", but I could not find "/work-dir" which should be created by initContainer. Could someone explain me the reason? Thanks and Rgds

apiVersion: v1
kind: Pod
metadata:
 name: init-demo
spec:
 containers:
 - name: nginx
   image: nginx
   ports:
   - containerPort: 80
   volumeMounts:
   - name: workdir
     mountPath: /usr/share/nginx/html
 # These containers are run during pod initialization
 initContainers:
 - name: install
   image: busybox
   command:
   - wget
   - "-O"
   - "/work-dir/index.html"
   - http://kubernetes.io
   volumeMounts:
   - name: workdir
     mountPath: "/work-dir"
 dnsPolicy: Default
 volumes:
 - name: workdir
   emptyDir: {}

Upvotes: 1

Views: 4140

Answers (1)

apisim
apisim

Reputation: 4586

The volume at "/work-dir" is mounted by the init container and the "/work-dir" location only exists in the init container. When the init container completes, its file system is gone so the "/work-dir" directory in that init container is "gone". The application (nginx) container mounts the same volume, too, (albeit at a different location) providing mechanism for the two containers to share its content.

Per the docs:

Init containers can run with a different view of the filesystem than app containers in the same Pod.

Upvotes: 3

Related Questions