Need help identify the error in the below YAML for 2 containers pod creation

Hello,
The below is from Ultimate CKA Mock exam series , Exam 5- Question 4.
The YAML file I created is the same as the YAML in the Exam solution.
I have checked multiple times and I cannot find any difference between the two.
kubectl apply -f filename.yaml is successful but it eventually fails to create the main container.
Please help identify what is missing in the below YAML file.

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: {}

============================
The warning message and the log are:
Warning BackOff 45s (x47 over 10m) kubelet Back-off restarting failed container main-container in pod cka-sidecar-pod_cka-multi-containers(e34259a2-4cee-4ac9-9b15-f47c813d4b5e)
cluster2-controlplane ~ ➜ kubectl get pod -n cka-multi-containers
NAME READY STATUS RESTARTS AGE
cka-sidecar-pod 1/2 CrashLoopBackOff 7 (39s ago) 11m

cluster2-controlplane ~ ➜ kubectl -n cka-multi-containers logs cka-sidecar-pod
Defaulted container “main-container” out of: main-container, sidecar-container

cluster2-controlplane ~ ➜

A bit hard to tell; just pasting your YAML into the edit window garbles it, so I can’t really test it w/o putting in about 15 minutes of reformatting :-(. Please read this article that tells how to format stuff in this forum, and paste it in again in a

code window

I’ll take a look at the problem, and will see if I can figure out what you meant to write, in the meantime.

Hello,

Thank you for the reply.
Please see the file named Q4 in the below mentioned github link:

Error in your YAML:

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

should be

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

There’s also a validation issue with the solution itself, which I’ve reported to the lab team.

1 Like

Our lab engineers have already fixed the validation issue. The lab, properly done, should validate for you now as well.

1 Like

Thanks a lot for identifying the additional not required hyphen which I was using and also for getting the lab fix it in the solution!