Lab: CKA Mock Exam 5 (Q4)

Solve this question on: ssh cluster2-controlplane

In the cka-multi-containers namespace, proceed to create a pod named cka-sidecar-pod that adheres to the following specifications:

  1. The first container, labeled main-container, is required to run the nginx:1.27, which writes the current date along with a greeting message Hi I am from Sidecar container to /log/app.log.
  2. The second container, identified as sidecar-container, must use the nginx:1.25 image and serve the app.log file as a webpage located at /usr/share/nginx/html.

Note: Do not rename app.log to index.html. The file name should remain app.log and be available at /app.log via the nginx server.

Solutions by lab

apiVersion: v1
kind: Pod
metadata:
name: cka-sidecar-pod
namespace: cka-multi-containers
spec:
containers:
- name: main-container
image: nginx:1.27
command: [“/bin/sh”]
args:
- -c
- |
while true; do
echo “$(date) Hi I am from Sidecar container” >> /log/app.log;
sleep 5;
done

volumeMounts:
- name: shared-logs
mountPath: /log
- name: sidecar-container
image: nginx:1.25
volumeMounts:
- name: shared-logs
mountPath: /usr/share/nginx/html
volumes:
- name: shared-logs
emptyDir: {}

I am not able to understand where its instructed that it continusesly writing date and message . for me instuction is asking to write only one time

( which writes the current date along with a greeting message Hi I am from Sidecar container to /log/app.log.)

Please use a

code block

for your code, since your code is garbled. Thanks!

@sudhakar042

What happened to your pod if you output the message once only? I reckon it would crashloop, and a crashlooping pod will be failed by the grader.

You should recall from the lectures that a pod must have continuous work or it will exit and be restarted - which registers as CrashLoopBackOff

Therefore for any kind of sidecar (or co-located) logging question like this, you have to put the message in a never ending loop like the solution is saying in order to keep the pod from crashlooping.

If you don’t recognize the - | syntax, it allows you to put a multi-line string as a YAML list value.
This would also have worked

- while true; do echo "$(date) Hi I am from Sidecar container" >> /log/app.log; sleep 5; done