CKA module test 2 question 2

Create a deployment named logging-deployment in the namespace logging-ns with 1 replica, with the following specifications:

The main container should be named app-container, use the image busybox, and should run the following command to simulate writing logs:

sh -c "while true; do echo 'Log entry' >> /var/log/app/app.log; sleep 5; done"

Add a sidecar container named log-agent that also uses the busybox image and runs the command:

tail -f /var/log/app/app.log

log-agent logs should display the entries logged by the main app-container

with the mntioned solution, i get the below error
logging-ns logging-deployment-7c55fbf8b7-lffzp 0/2 Init:CrashLoopBackOff 1 (14s ago) 16s
apiVersion: apps/v1 kind: Deployment metadata: name: logging-deployment namespace: logging-ns spec: replicas: 1 selector: matchLabels: app: logger template: metadata: labels: app: logger spec: volumes: - name: log-volume emptyDir: {} initContainers: - name: log-agent image: busybox command: - sh - -c - "tail -f /var/log/app/app.log" volumeMounts: - name: log-volume mountPath: /var/log/app restartPolicy: Always containers: - name: app-container image: busybox command: - sh - -c - "while true; do echo 'Log entry' >> /var/log/app/app.log; sleep 5; done" volumeMounts: - name: log-volume mountPath: /var/log/app
can someone please help

Hi @dipti

Is this from Kodekloud engineer tests?
It helps if you share the correct Lab name or URL, and use the </> button at the top of the editor ribbon to render your manifest in a code block.

Coming back to your issue, it appears to be an issue with initContainer. Have you checked the Deployment logs or events by describing the Deployment?
That should give you some hints at what’s causing the Crashloop.

Hi Santosh
Url Udemy Labs - Certified Kubernetes Administrator with Practice Tests Course | KodeKloud
it is stable now but had couple of restarts
`
logging-ns logging-deployment-7c55fbf8b7-7vwcj 2/2 Running 3 (38m ago) 38m

Error from server (BadRequest): container “busybox” in pod “logging-deployment-5d5b759479-2vb5t” is waiting to start: PodInitializing

`
and it has been printing log entry

Can you share the manifest you used to create the Deployment?

Paste the YAML in a code block for readability. You can use the icon showed in the image to paste the yaml.
I guess there could be a bug in this lab. I’ll verify and inform the concerned team about this.

icon

Hello!
I am also experiencing the problem with these questions.
I see that you must use a side and not an initcontainer. The initcontainer will not find the file because the container has not been started yet.

My solution is:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: logging-deployment
  name: logging-deployment
  namespace: logging-ns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: logging-deployment
  strategy: {}
  template:
    metadata:
      labels:
        app: logging-deployment
    spec:
      volumes:
      - name: shared-data
        emptyDir: {}      
      containers:
      - image: busybox
        name: app-container
        command: 
          - sh 
          - -c 
          - "while true; do echo 'Log entry' >> /var/log/app/app.log; sleep 5; done"
        volumeMounts:
        - name: shared-data
          mountPath: /var/log/app
      - image: busybox
        name: log-agent
        command:
          - tail 
          - -f 
          - /var/log/app/app.log
        volumeMounts:
        - name: shared-data
          mountPath: /var/log/app

It is stable and the log is correct but the check tells me that there are still problems. I also tried the yaml in this link but it also goes to error

https://notes.kodekloud.com/docs/CKA-Certification-Course-Certified-Kubernetes-Administrator/Mock-Exams/Mock-Exam-2-Step-by-Step-Solutions

I see the problem; if you do this as an initContainer, the solution as posted never starts the main container. Here’s a work-around for the initContainer, which the grader wants:

      initContainers:
      - command:
        - sh
        - -c
        - tail -f /var/log/app/app.log || echo starting up
        image: busybox
        name: log-agent
        resources: {}
        restartPolicy: Always
        volumeMounts:
        - mountPath: /var/log/app
          name: shared-data

This will not error out, and passes the grader.

I’ve recommended this solution to the lab engineers; hopefully they’ll fix this.

Good morning Rob,

Thank you. I used your code and saw that the check was successful.
Thanks
Best regards

In any event, thanks for reporting this. Our engineers have already updated the question so that the posted solution works better, and the grader likes it as well.

1 Like