exam questions

Exam CKA All Questions

View all questions & answers for the CKA exam

Exam CKA topic 1 question 13 discussion

Actual exam question from CNCF's CKA
Question #: 13
Topic #: 1
[All CKA Questions]

SIMULATION -


Context -
An existing Pod needs to be integrated into the Kubernetes built-in logging architecture (e.g. kubectl logs). Adding a streaming sidecar container is a good and common way to accomplish this requirement.

Task -
Add a sidecar container named sidecar, using the busybox image, to the existing Pod big-corp-app. The new sidecar container has to run the following command:

Use a Volume, mounted at /var/log, to make the log file big-corp-app.log available to the sidecar container.

Show Suggested Answer Hide Answer
Suggested Answer:






Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Samm1
Highly Voted 1 year, 5 months ago
This is an example that will work for this question for me: vi sd1.yaml apiVersion: v1 kind: Pod metadata: name: big-corp-app spec: containers: - name: count image: busybox:1.28 args: - /bin/sh - -c - > i=0; while true; do echo "$i: $(date)" >> /var/log/big-corp-app.log; i=$((i+1)); sleep 1; done volumeMounts: - name: varlog mountPath: /var/log - name: sidecar image: busybox args: [/bin/sh, -c, 'tail -n+1 -F /var/log/big-corp-app.log'] volumeMounts: - name: varlog mountPath: /var/log volumes: - name: varlog emptyDir: {} --- kubectl apply -f sd1.yaml kubectl logs big-corp-app -c sidecar
upvoted 9 times
137eceb
3 months, 1 week ago
when the task says you should use a specific command, then you have to use that command.
upvoted 2 times
...
LavaPup
1 year, 2 months ago
Trying to understand why would you use volumeMounts: twice? In line#20 and #26
upvoted 2 times
adahiya
12 months ago
one for each container
upvoted 2 times
...
...
...
[Removed]
Highly Voted 10 months ago
solution : https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent
upvoted 7 times
...
noahsark
Most Recent 2 months, 3 weeks ago
killer_sh_lab practice only part 2: k apply -f big-corp-app.yml k logs big-corp-app -c sidecar k exec -it big-corp-app -c=count -- cat /var/log/big-corp-app.log k exec -it big-corp-app -c=sidecar -- cat /var/log/big-corp-app.log # admin/logging/two-files-counter-pod-agent-sidecar.yaml # Remove the extra volumeMounts / volume
upvoted 1 times
VegaAbhi
3 weeks, 1 day ago
apiVersion: v1 kind: Pod metadata: labels: run: nginx name: big-corp-app namespace: default spec: volumes: - name: vol emptyDir: {} containers: - name: sidecar image: busybox args: - /bin/sh - -c - tail -n+1 -f /var/log/big-corp-app.log volumeMounts: - name: vol mountPath: /var/log/ - image: nginx imagePullPolicy: Always name: nginx args: - /bin/sh - -c - while true; do echo big-corp-app event $(date) >> /var/log/big-corp-app.log; sleep 6; done; volumeMounts: - name: vol mountPath: /var/log/
upvoted 1 times
...
...
noahsark
2 months, 3 weeks ago
killer_sh_lab practice only part 1: vi big-corp-app.yml apiVersion: v1 kind: Pod metadata: name: big-corp-app spec: containers: - name: count image: busybox:1.28 args: - /bin/sh - -c - > i=0; while true; do echo "$i: $(date)" >> /var/log/1.log; echo "$(date) INFO $i" >> /var/log/big-corp-app.log; i=$((i+1)); sleep 1; done volumeMounts: - name: varlog mountPath: /var/log - name: sidecar image: busybox:1.28 args: [/bin/sh, -c, 'tail -n+1 -F /var/log/big-corp-app.log'] volumeMounts: - name: varlog mountPath: /var/log volumes: - name: varlog emptyDir: {}
upvoted 2 times
...
c35c269
4 months, 2 weeks ago
apiVersion: v1 kind: Pod metadata: name: counter spec: containers: - name: count image: busybox:1.28 args: - [/bin/sh, -c, 'tail -n+1 -f /var/log/bit-corp-app.log'] volumeMounts: - name: varlog mountPath: /var/log volumes: - name: varlog emptyDir: {}
upvoted 2 times
...
extrascenario
7 months, 2 weeks ago
This is an exam question or not answers are not accuarte
upvoted 4 times
...
Anderson23
8 months ago
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: nginx name: nginx spec: containers: - image: nginx name: nginx - image: busybox name: sidecar command: ["/bin/sh"] args: [ "-c", "tail -n+1 -f /var/log/big-corp-app.log" ] volumeMounts: - name: log mountPath: /var/log volumes: - name: log hostPath: path: /var/log type: Directory
upvoted 1 times
...
fc146fc
11 months, 2 weeks ago
create a bigcorp.yaml apiVersion: v1 kind: Pod metadata: name: big-corp-app spec: containers: - name: count image: busybox args: - /bin/sh - -c - > i=0; while true; do echo "$i: $(date)" >> /var/log/ big-corp-app.log i=$((i+1)); sleep 1; done volumeMounts: - name: varlog mountPath: /var/log - name: sidecar image: busybox args: [/bin/sh, -c, 'tail -n+1 -f /var/log/big-corp-app.log'] volumeMounts: - name: varlog mountPath: /var/log kubectl create -f bigcorp.yaml
upvoted 2 times
...
blackcloudgeeks
11 months, 3 weeks ago
i had this question but there was an issue with it not finding the file from the script in the first container
upvoted 1 times
...
judaspriest1
1 year, 1 month ago
vi sidecar.yaml apiVersion: v1 kind: Pod metadata: name: big-corp-app spec: containers: - name: count image: busybox:1.28 args: - /bin/sh - -c - > i=0; while true; do echo "$i: $(date)" >> /var/log/1.log; echo "$(date) INFO $i" >> /var/log/2.log; i=$((i+1)); sleep 1; done volumeMounts: - name: varlog mountPath: /var/log - name: sidecar image: busybox:1.28 args: [/bin/sh, -c, 'tail -n+1 -F /var/log/big-corp-app.log'] volumeMounts: - name: varlog mountPath: /var/log volumes: - name: varlog emptyDir: {} k create -f sidecar.yaml k get pod NAME READY STATUS RESTARTS AGE big-corp-app 2/2 Running 0 9s
upvoted 1 times
...
abbabe
1 year, 3 months ago
apiVersion: v1 kind: Pod metadata: name: big spec: containers: - name: big image: nginx volumeMounts: - name: varlog mountPath: /var/log/nginx/ - name: sidecar image: busybox:1.28 args: [/bin/sh, -c, 'tail -n+1 -F /var/log/nginx/access.log'] volumeMounts: - name: varlog mountPath: /var/log/nginx/ volumes: - name: varlog emptyDir: {} https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent
upvoted 2 times
...
[Removed]
1 year, 4 months ago
Are we to describe and write the existing configuration of the deployment to a file, delete the deployment, then recreate it?
upvoted 1 times
[Removed]
1 year, 4 months ago
kubectl get deployment big-corp-app -o yaml > 13.yaml
upvoted 2 times
...
...
iiiaz
1 year, 6 months ago
Who started the " include env in sidecar container" thing? What are the reasons to use ENV from main container in the sidecar container? ENV variable from container 1 is not visible in container 2?
upvoted 3 times
...
iiiaz
1 year, 6 months ago
I failed this question in my exam but I cannot tell the reason. The sidecar container was not running and pod was in Crashloopback. I used "args" when defining the sidecar container like: args: - /bin/sh - -c - tail n+1 .... and I thought "command" should have been used. But in the busybox image there is CMD ["sh"] so in my case "args" would work. Tested also like this and the pod is running. I cannot tell at this moment what I did wrong. Any ideas? controlplane ~ ➜ k get pods mypod -o yaml apiVersion: v1 kind: Pod metadata: creationTimestamp: "2023-07-13T12:04:25Z" labels: run: mypod name: mypod namespace: default resourceVersion: "1029" uid: c135577f-fad5-4127-a3a2-1ae0cb074e83 spec: containers: - args: - /bin/sh - -c - echo "this is a test"; sleep 3600 image: busybox
upvoted 1 times
bobbykumar
1 year, 5 months ago
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: kucc8 name: kucc8 spec: containers: - image: nginx name: nginx volumeMounts: - mountPath: /var/log/nginx name: logs - image: busybox name: sidecar command: ["/bin/sh", "-c", "tail -n+1 -f /var/log/nginx/access.log"] volumeMounts: - mountPath: /var/log/nginx name: logs volumes: - name: logs emptyDir: {}
upvoted 3 times
...
...
real111
1 year, 6 months ago
Is it correct, if exiting yaml file has -env defined, I don't add a container under env and also do not include env in sidecar container, just adding sidecar container under spec like this? Spec : name: sidecar image: busybox command: ["/bin/sh", "-c", "kkkkkkmm"] volumeMounts: - name: log-volume mountPath: /var/log volumes: - name: log-volume emptyDir: {}
upvoted 2 times
iiiaz
1 year, 6 months ago
There is no relation between "env" in a pod and additional containers. Additional containers should be added under "spec", https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/ .
upvoted 1 times
...
...
rahulkum7
1 year, 8 months ago
Why its required to have env variable?
upvoted 3 times
...
Hamiltonian
2 years, 2 months ago
don't forget to also define outside the container context: volumes: - name: varlog emptyDir: {}
upvoted 3 times
3bd0
2 years ago
I think it has been already defined as: volumes: - name: logs emptyDir: {}
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago