Task 54 unable to complete

Hello Team,

I am working on task DevOps task 54. Task says to create side container to store the logs. and in the steps, it says to create the side container as a initcontainer. If I create the side-container as a normal container, and when I submit, I get error messages saying the sidecar-container does not exist, if I create sidecar-container as initcontainer with the given command, it creates a loop and does not create the nginx-container. Below are the logs, kindly help complete the task.

Events:
Type Reason Age From Message


Normal Scheduled 2m50s default-scheduler Successfully assigned default/webserver to jump-host
Normal Pulling 2m50s kubelet Pulling image “ubuntu:latest”
Normal Pulled 2m50s kubelet Successfully pulled image “ubuntu:latest” in 352ms (352ms including waiting). Image size: 41582068 bytes.
Normal Created 2m50s kubelet Created container: sidecar-container
Normal Started 2m50s kubelet Started container sidecar-container
Normal Pulling 2m50s kubelet Pulling image “nginx:latest”
Normal Pulled 2m49s kubelet Successfully pulled image “nginx:latest” in 468ms (468ms including waiting). Image size: 66343926 bytes.
Normal Created 2m49s kubelet Created container: nginx-container
Normal Started 2m49s kubelet Started container nginx-container


thor@jump-host ~$ k get pods
NAME READY STATUS RESTARTS AGE
webserver 2/2 Running 0 33s
thor@jump-host ~$ k exec webserver -c sidecar-container – ls -la /var/log/nginx
total 12
drwxrwxrwx 2 root root 4096 Sep 3 13:34 .
drwxr-xr-x 1 root root 4096 Sep 3 13:34 …
-rw-r–r-- 1 root root 0 Sep 3 13:34 access.log
-rw-r–r-- 1 root root 1308 Sep 3 13:34 error.log
thor@jump-host ~$ k exec webserver -c nginx-container – ls -la /var/log/nginx
total 16
drwxrwxrwx 2 root root 4096 Sep 3 13:34 .
drwxr-xr-x 1 root root 4096 Sep 2 21:04 …
-rw-r–r-- 1 root root 0 Sep 3 13:34 access.log
-rw-r–r-- 1 root root 1308 Sep 3 13:34 error.log
thor@jump-host ~$ thor@jump-host ~$ k describe pod
Name: webserver
Namespace: default
Priority: 0
Service Account: default
Node: jump-host/10.244.73.189
Start Time: Thu, 03 Sep 2026 13:34:17 +0000
Labels: run=webserver
Annotations:
Status: Running
IP: 10.22.0.12
IPs:
IP: 10.22.0.12
Containers:
sidecar-container:
Container ID: containerd://a48dd5a9031d7c3935b7fdb7f159e9dd9d47fd0c66138e39082655e14adf9e8f
Image: ubuntu:latest
Image ID: Docker Hub Container Image Library | App Containerization
Port:
Host Port:
Command:
sh
-c
while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done
State: Running
Started: Thu, 03 Sep 2026 13:34:18 +0000
Ready: True
Restart Count: 0
Environment:
Mounts:
/var/log/nginx from shared-logs (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-n4nlq (ro)
nginx-container:
Container ID: containerd://1ce358427b989adf0b14136b975e73848cee3f13b3ed6ffc6d60578d86be58a3
Image: nginx:latest
Image ID: Docker Hub Container Image Library | App Containerization
Port:
Host Port:
State: Running
Started: Thu, 03 Sep 2026 13:34:19 +0000
Ready: True
Restart Count: 0
Environment:
Mounts:
/var/log/nginx from shared-logs (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-n4nlq (ro)
Conditions:
Type Status
PodReadyToStartContainers True
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
shared-logs:
Type: EmptyDir (a temporary directory that shares a pod’s lifetime)
Medium:
SizeLimit:
kube-api-access-n4nlq:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
Optional: false
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message


Normal Scheduled 2m50s default-scheduler Successfully assigned default/webserver to jump-host
Normal Pulling 2m50s kubelet Pulling image “ubuntu:latest”
Normal Pulled 2m50s kubelet Successfully pulled image “ubuntu:latest” in 352ms (352ms including waiting). Image size: 41582068 bytes.
Normal Created 2m50s kubelet Created container: sidecar-container
Normal Started 2m50s kubelet Started container sidecar-container
Normal Pulling 2m50s kubelet Pulling image “nginx:latest”
Normal Pulled 2m49s kubelet Successfully pulled image “nginx:latest” in 468ms (468ms including waiting). Image size: 66343926 bytes.
Normal Created 2m49s kubelet Created container: nginx-container
Normal Started 2m49s kubelet Started container nginx-container

It’s really hard to read the content you’ve posted, as it mangles the required YAML indentation.
It helps if you share such content in </> code block, using the tool in the editor ribbon.

I suppose this deals with sidecar-container. If that is the case, one thing to note that is the sidecar-container need to be in Pods initContainers block, and not in regular containers block.

containers:
- name: nginx-container
  image: nginx:latest
  volumeMounts:
  - name: shared-logs
    mountPath: /var/log/nginx
initContainers:
- name: sidecar-container   # <-- This makes it a sidecar
  image: ubuntu:latest
  restartPolicy: Always  # <-- This is a required field for sidecar-containers.

You can refer to the official docs for more information.

Hi Santosh,

Yes. the task specifically requires sidecar-container to be an init container, put it under initContainers before the regular containers section…

Because the sidecar container includes an infinite while true loop, an init container setup will prevent the main nginx-container from starting since init containers must run to completion first.

Submitting the task without nginx-container, it throws message:

image

So, I am stuck here.

no matter where the init-container block is (before or after container block), nginx-container is not created. Below is the error in the logs:

Defaulted container “nginx-container” out of: nginx-container, sidecar-container (init)
Error from server (BadRequest): container “nginx-container” in pod “webserver” is waiting to start: PodInitializing

That’s because you missed the key hint that Santosh gave you – you must specify restartPolicy: Always, or the initContainer will not allow the regular container to start. Your loop is due to that problem. The effect of that setting is to run the initContainer in parallel to the regular container, rather than wait until it completes, as would happen if you omit that setting.

You are right Rob, I missed the hint that Santosh gave.
Thanks to both of you, I was able to complete the task.