Multi-Container Pods
Some of the scenario questions here are based on Kodekloud's CKAD course labs.
CKAD and CKA can have similar scenario questions. It is recommended to go through the CKA practice tests.
Shortcuts
First run the two commands below for shortcuts.
export do="--dry-run=client -o yaml"
export now="--force --grace-period=0"
Questions
-
Create a multi-container pod with 2 containers. Use the spec given below. If the pod goes into the crashloopbackoff then add the command sleep 1000 in the lemon container.
-
Name: yellow
-
Container 1 Name: lemon
-
Container 1 Image: busybox
-
Container 2 Name: gold
-
Container 2 Image: redis
Answer
controlplane ~ ➜ k run yellow --image busybox $do > yellow.ymlcontrolplane ~ ➜ ls -ltotal 8drwxr-xr-x 3 root root 4096 Jan 5 09:40 elastic-search-rw-r--r-- 1 root root 237 Jan 5 09:43 yellow.yml## yellow.ymlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: yellowname: yellowspec:containers:- image: busyboxname: lemon- image: redisname: goldresources: {}dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}controlplane ~ ➜ k apply -f yellow.ymlpod/yellow createdcontrolplane ~ ➜ k get poNAME READY STATUS RESTARTS AGEapp 1/1 Running 0 5m2sblue 2/2 Running 0 3m30sfluent-ui 1/1 Running 0 5m3sred 3/3 Running 0 4m50syellow 0/2 ContainerCreating 0 3s -
-
Update the newly created pod 'simple-webapp-2' with a readinessProbe using the given specs:
-
Pod Name: simple-webapp-2
-
Image Name: kodekloud/webapp-delayed-start
-
Readiness Probe: httpGet
-
Http Probe: /ready
-
Http Port: 8080
controlplane ~ ➜ k get poNAME READY STATUS RESTARTS AGEsimple-webapp-1 1/1 Running 0 2m7ssimple-webapp-2 1/1 Running 0 111sAnswer
controlplane ~ ➜ k get po simple-webapp-2 -o yaml > simple-webapp-2.ymlcontrolplane ~ ➜ k delete po simple-webapp-2 $nowWarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "simple-webapp-2" force deletedcontrolplane ~ ➜ k get poNAME READY STATUS RESTARTS AGEsimple-webapp-1 1/1 Running 0 3m5scontrolplane ~ ➜ ls -ltotal 16-rwxr-xr-x 1 root root 114 Dec 1 06:17 crash-app.sh-rwxr-xr-x 1 root root 216 Dec 1 06:17 curl-test.sh-rwxr-xr-x 1 root root 123 Dec 1 06:17 freeze-app.sh-rw-r--r-- 1 root root 2772 Jan 5 09:56 simple-webapp-2.ymlModify the YAML file.
apiVersion: v1kind: Podmetadata:creationTimestamp: "2024-01-05T14:53:47Z"labels:name: simple-webappname: simple-webapp-2namespace: defaultresourceVersion: "631"uid: 302ac3b8-bb0b-4294-89dd-4eef603bf001spec:containers:- env:- name: APP_START_DELAYvalue: "80"image: kodekloud/webapp-delayed-startimagePullPolicy: Alwaysname: simple-webappreadinessProbe:httpGet:path: /readyport: 8080controlplane ~ ➜ k apply -f simple-webapp-2.ymlpod/simple-webapp-2 createdcontrolplane ~ ➜ k get poNAME READY STATUS RESTARTS AGEsimple-webapp-1 1/1 Running 0 6m37ssimple-webapp-2 0/1 ContainerCreating 0 8s -
-
Update both the pods with a livenessProbe using the given spec
-
Pod Name: simple-webapp-1
-
Image Name: kodekloud/webapp-delayed-start
-
Liveness Probe: httpGet
-
Http Probe: /live
-
Http Port: 8080
-
Period Seconds: 1
-
Initial Delay: 80
-
Pod Name: simple-webapp-2
-
Image Name: kodekloud/webapp-delayed-start
-
Liveness Probe: httpGet
-
Http Probe: /live
-
Http Port: 8080
-
Initial Delay: 80
-
Period Seconds: 1
controlplane ~ ✦ ➜ k get poNAME READY STATUS RESTARTS AGEsimple-webapp-1 1/1 Running 0 9m15ssimple-webapp-2 1/1 Running 0 2m46sAnswer
controlplane ~ ✦ ➜ k get po simple-webapp-1 -o yaml > simple-webapp-1.ymlcontrolplane ~ ✦ ➜ k get po simple-webapp-2 -o yaml > simple-webapp-2.ymlcontrolplane ~ ✦ ➜ k delete po simple-webapp-1 $nowWarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "simple-webapp-1" force deletedcontrolplane ~ ✦ ➜ k delete po simple-webapp-2 $nowWarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "simple-webapp-2" force deletedcontrolplane ~ ✦ ➜ k get poNo resources found in default namespace.Modify the first pod first.
apiVersion: v1kind: Podmetadata:creationTimestamp: "2024-01-05T14:53:31Z"labels:name: simple-webappname: simple-webapp-1namespace: defaultresourceVersion: "605"uid: 5843cf05-165d-4f4c-9293-21f21e9a7905spec:containers:- image: kodekloud/webapp-delayed-startimagePullPolicy: Alwaysname: simple-webapplivenessProbe:initialDelaySeconds: 80periodSeconds: 1httpGet:path: /liveport: 8080ports:- containerPort: 8080protocol: TCPresources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /var/run/secrets/kubernetes.io/serviceaccountname: kube-api-access-zwmnpreadOnly: truecontrolplane ~ ✦ ➜ k apply -f simple-webapp-1.ymlpod/simple-webapp-1 createdcontrolplane ~ ✦ ➜ k get poNAME READY STATUS RESTARTS AGEsimple-webapp-1 1/1 Running 0 51sNext, modify the YAML file for the second pod.
apiVersion: v1kind: Podmetadata:creationTimestamp: "2024-01-05T15:00:00Z"labels:name: simple-webappname: simple-webapp-2namespace: defaultresourceVersion: "1286"uid: cfdd23e3-e7e3-4be7-9dd9-b2abf5f0ad0espec:containers:- env:- name: APP_START_DELAYvalue: "80"image: kodekloud/webapp-delayed-startimagePullPolicy: Alwaysname: simple-webapplivenessProbe:initialDelaySeconds: 80periodSeconds: 1httpGet:path: /liveport: 8080ports:- containerPort: 8080protocol: TCPreadinessProbe:failureThreshold: 3httpGet:path: /readyport: 8080scheme: HTTPperiodSeconds: 10successThreshold: 1timeoutSeconds: 1resources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /var/run/secrets/kubernetes.io/serviceaccountname: kube-api-access-xvbr6readOnly: truecontrolplane ~ ✦ ➜ k apply -f simple-webapp-2.ymlpod/simple-webapp-2 createdcontrolplane ~ ✦ ➜ k get poNAME READY STATUS RESTARTS AGEsimple-webapp-1 1/1 Running 0 118ssimple-webapp-2 0/1 Running 0 6s -