100 days of DevOps - Day 55

Dear KodeKloud,

on day 55 it’s asked to create a sidecar container. A sidecar container is an initContainer with restartPolicy: Always.

While this solution was accepted:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: webserver
  name: webserver
spec:
  volumes:
    - name: shared-logs
      emptyDir: {}
  containers:
  - image: nginx:latest
    name: nginx-container
    volumeMounts:
      - name: shared-logs
        mountPath: /var/log/nginx
  - image: ubuntu:latest
    name: sidecar-container
    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
status: {}

this solution wasn’t:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: webserver
  name: webserver
spec:
  volumes:
    - name: shared-logs
      emptyDir: {}
  containers:
  - image: nginx:latest
    name: nginx-container
    volumeMounts:
      - name: shared-logs
        mountPath: /var/log/nginx
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  initContainers:
  - image: ubuntu:latest
    name: sidecar-container
    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
status: {}

Kind regards

Thanks for highlighting this.
I’ll inform the team to look into this and resolve it.

1 Like

refer to this solution it its helps

Hello I have the same error while trying to complete this lab. The below is my errors:

I followed the same steps here: https://github.com/MiqdadProjects/kodekloud-eng-100-days-devops/blob/main/DAY55/Task-55-WebserverSidecarPod.md

But it doesn’t work Y.Y.

Please help me out. Thank you!

Could you please share 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.

1 Like

Hi Santosh,

I found the solution as your recommendation. My code after fixed below:

apiVersion: v1
kind: Pod
metadata:
  name: webserver
spec:
  # The Sidecar is defined under initContainers with a RestartPolicy
  initContainers:
    - name: sidecar-container
      image: ubuntu:latest
      restartPolicy: Always #This is important , lab will be failed if missing
      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

  volumes:
    - name: shared-logs
      emptyDir: {}

Thanks a lot.

1 Like