Getting error in Day 55: Kubernetes sidecar containers

Hi Team,
I’m at Day 55 in 100 days of Devops. Even though 2 pods are in running state and logs are getting, after submitting the task getting 2 errors.: 1.‘sidecar-container’ doesn’t exist and 2. Image used is not ‘ubuntu:latest’ for ‘sidecar-container’
Pls provide me solution asap.

It would have helped if you had shared the manifest you used for this task.

This requires placing the sidecar-container in the initContainers with restartPolicy set to Always.

Refer to the official docs for more on sidecar containers.

I have used below manifest:
apiVersion: v1
kind: Pod
metadata:
name: webserver
spec:
volumes:
- name: shared-logs
emptyDir: {}

initContainers:
- name: sidecar-container
image: ubuntu:latest
command:
- “sh”
- “-c”
- “while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done”
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx

containers:
- name: nginx-container
image: nginx:latest
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx

and by following your reply I have tried below manifest also but got same error
apiVersion: v1
kind: Pod
metadata:
name: webserver
spec:
restartPolicy: Always
volumes:
- name: shared-logs
emptyDir: {}
containers:
- name: nginx-container
image: nginx:latest
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx
initContainers:
- name: sidecar-container
image: ubuntu:latest
command: [“sh”, “-c”, “while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done”]
volumeMounts:
- name: shared-logs
mountPath: /var/log/nginx

hi refer to this soution if it helps and if this helps make sure to stara my repo .

Your both manifests are missing restartPolicy: Always in initContainers.

It helps readability if you wrap your YAML in a code block using the </> button in the editor ribbon.

initContainers:
- name: sidecar-container
  image: ubuntu:latest
  command: [“sh”, “-c”, “while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done”]
  restartPolicy: Always
  volumeMounts:
  - name: shared-logs
    mountPath: /var/log/nginx