Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

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 (?) , you can switch to a simple comment.
Switch to a voting comment New
Samm1
Highly Voted 7 months, 2 weeks 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 8 times
LavaPup
5 months ago
Trying to understand why would you use volumeMounts: twice? In line#20 and #26
upvoted 2 times
adahiya
2 months ago
one for each container
upvoted 1 times
...
...
...
learndigitalcloud
Most Recent 6 days, 13 hours ago
solution : https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent
upvoted 2 times
...
fc146fc
1 month, 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 1 times
...
blackcloudgeeks
1 month, 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
3 months, 1 week 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
5 months, 2 weeks 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 1 times
...
[Removed]
6 months, 1 week 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]
6 months, 1 week ago
kubectl get deployment big-corp-app -o yaml > 13.yaml
upvoted 2 times
...
...
iiiaz
8 months, 1 week 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 2 times
...
iiiaz
8 months, 2 weeks 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
8 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
8 months, 2 weeks 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
8 months, 1 week 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
11 months ago
Why its required to have env variable?
upvoted 3 times
...
Hamiltonian
1 year, 4 months ago
don't forget to also define outside the container context: volumes: - name: varlog emptyDir: {}
upvoted 3 times
3bd0
1 year, 2 months 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 ...