Problem:
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.
Solution
pod.yaml
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: {}
This is the exact solution provided in solution category
However,the pods are keep on getting βCrashBackLoopβ error and not in βrunningβ status.
cluster2-controlplane ~ β k get pod cka-sidecar-pod
NAME READY STATUS RESTARTS AGE
cka-sidecar-pod 1/2 CrashLoopBackOff 22 (96s ago) 89m
cluster2-controlplane ~ β k logs cka-sidecar-pod -c main-container
sleep 2; done: 1: Syntax error: end of file unexpected (expecting "done")
Please let me know, whats wrong in the pod definition file.