Hi Team,
Please help me with an explanation to this task. I may be misunderstanding part of the problem-statement:
Solve this question on: ssh cluster2-controlplane
In the cka-multi-containers namespace, proceed
to create a pod named cka-sidecar-pod that adheres
to the following specifications:
The first container, labeled main-container, is required
to run the nginx:1.27, which writes the current date along
with a greeting message Hi I am from Sidecar container
to /log/app.log.
The second container, identified as sidecar-container, must
use the nginx:1.25 image and serve the app.log file as a
webpage located at /usr/share/nginx/html.
Note: Do not rename app.log to index.html. The file name should remain app.log and be available at /app.log via the Nginx server.
The proposed solution by the examiner:
apiVersion: v1
kind: Pod
metadata:
name: cka-sidecar-pod
namespace: cka-multi-containers
spec:
containers:
- name: main-container
image: nginx:1.27
command: ["/bin/sh"]
args:
- -c
- |
while true; do
echo "$(date) Hi I am from Sidecar container" >> /log/app.log;
sleep 5;
done
volumeMounts:
- name: shared-logs
mountPath: /log
- name: sidecar-container
image: nginx:1.25
volumeMounts:
- name: shared-logs
mountPath: /usr/share/nginx/html
volumes:
- name: shared-logs
emptyDir: {}
versus what I attempted (AKA - my attempt):
apiVersion: v1
kind: Pod
metadata:
labels:
run: cka-sidecar-pod
name: cka-sidecar-pod
namespace: cka-multi-containers
spec:
containers:
- image: nginx:1.27
name: main-container
command: ['sh', '-c', 'while true; do echo $(date) " Hi, I am from Sidecar container" > /log/app.log; sleep 5; done']
volumeMounts:
- name: redis-storage
mountPath: /log
- image: nginx:1.25
name: sidecar-container
resources: {}
volumeMounts:
- name: redis-storage
mountPath: /usr/share/nginx/html
volumes:
- name: redis-storage
emptyDir: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
cluster2-controlplane ~ âžś k get pod -n cka-multi-containers cka-sidecar-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
cni.projectcalico.org/containerID: 13eff4525f3289429ad58e0d33f0ad4aedd755f759d3bb5f1c4f93bfcb74f340
cni.projectcalico.org/podIP: 172.17.1.3/32
cni.projectcalico.org/podIPs: 172.17.1.3/32
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"run":"cka-sidecar-pod"},"name":"cka-sidecar-pod","namespace":"cka-multi-containers"},"spec":{"containers":[{"command":["sh","-c","while true; do echo $(date) \" Hi, I am from Sidecar container\" \u003e /log/app.log; sleep 5; done"],"image":"nginx:1.27","name":"main-container","volumeMounts":[{"mountPath":"/log","name":"redis-storage"}]},{"image":"nginx:1.25","name":"sidecar-container","resources":{},"volumeMounts":[{"mountPath":"/usr/share/nginx/html","name":"redis-storage"}]}],"dnsPolicy":"ClusterFirst","restartPolicy":"Always","volumes":[{"emptyDir":{},"name":"redis-storage"}]},"status":{}}
creationTimestamp: "2025-05-08T20:32:41Z"
labels:
run: cka-sidecar-pod
name: cka-sidecar-pod
namespace: cka-multi-containers
resourceVersion: "5519"
uid: ac7923f7-7aec-455c-90c1-98a2a7b7a1a9
spec:
containers:
- command:
- sh
- -c
- while true; do echo $(date) " Hi, I am from Sidecar container" > /log/app.log;
sleep 5; done
image: nginx:1.27
imagePullPolicy: IfNotPresent
name: main-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /log
name: redis-storage
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-rrhqm
readOnly: true
- image: nginx:1.25
imagePullPolicy: IfNotPresent
name: sidecar-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/nginx/html
name: redis-storage
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-rrhqm
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: cluster2-node01
preemptionPolicy: PreemptLowerPriority
priority: 500
priorityClassName: default-tier
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- emptyDir: {}
name: redis-storage
- name: kube-api-access-rrhqm
projected:
defaultMode: 420
sources:
- serviceAccountToken:
expirationSeconds: 3607
path: token
- configMap:
items:
- key: ca.crt
path: ca.crt
name: kube-root-ca.crt
- downwardAPI:
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
path: namespace
The substantial difference that I noticed is that instead of appending the date, I used the over-write option “>”; but ultimately I was marked wrong for the task of:
Is the main-container writing logs to /log/app.log?
Is the sidecar-container exposing the app.log as a webpage?
can anyone please help me figure out what I have potentially done wrong?
Also, about the appending versus overwriting thing, may I suggest an update to the question to specifically ask for an append (and potentially also state for how many seconds intervals…lol. Luckily, the examiner and myself both used 5 seconds).