Init Containers
Tips and Tricks
For simulated Practice problems visit KillerCoda.
-
Solution
k create ns demeter
-
In
demeter
namespace create a pod namedstew
with an init container namedsetup
withbusybox
image. Run another container namedserve
withnginx
image.Solution
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: stew name: stew namespace: demeter spec: initContainers: - image: busybox name: setup containers: - image: nginx name: serve dnsPolicy: ClusterFirst restartPolicy: Always status: {}
-
Take
stew
pod created fromdemeter
namespace, there exist a yaml filepod.yaml
for reference & use. create a volume namedstorage
in thestew
pod of typeemptyDir
. Mountstorage
volume on initContainer at path/set
and run a command in init containerecho "this is nginx index page" > /set/index.html
. Mount same volume in nginx container at path/usr/share/nginx/html
. Do these updates inpod.yaml
. Delete & create the pod againSolution
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: stew name: stew namespace: demeter spec: initContainers: - image: busybox name: setup command: ["sh","-c","echo 'this is nginx index page' > /set/index.html"] volumeMounts: - name: storage mountPath: /set containers: - image: nginx name: serve volumeMounts: - name: storage mountPath: /usr/share/nginx/html dnsPolicy: ClusterFirst restartPolicy: Always volumes: - name: storage emptyDir: {} status: {}
-
Solution
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: stew name: stew namespace: demeter spec: initContainers: - image: busybox name: setup command: ["sh","-c","echo 'this is nginx index page' > /set/index.html"] volumeMounts: - name: storage mountPath: /set containers: - image: nginx name: serve volumeMounts: - name: storage mountPath: /usr/share/nginx/html ports: - containerPort: 80 dnsPolicy: ClusterFirst restartPolicy: Always volumes: - name: storage emptyDir: {} status: {}
-
Solution
# check ip of the stew pod k get po stew -o wide # make request on port 80 wget -qO- <IP>