spurin / diveintokcna

Dive Into Containers, Kubernetes and the Kubernetes Cloud Native Associate Certification
33 stars 11 forks source link

[Lab Issue]: mypod sidecar args have an extraneous backslash #4

Closed drewheasman closed 7 months ago

drewheasman commented 7 months ago

How is the lab being run?

Docker Compose

Operating System

Linux

Browser

Brave

Lab Details

Kubernetes Pods

Issue Description

The echo date command is given as - while true; do echo "\$(date +'%T') - Hello from the sidecar"; sleep 5; if [ -f /tmp/crash ]; then exit 1; fi; done But it should be - while true; do echo "$(date +'%T') - Hello from the sidecar"; sleep 5; if [ -f /tmp/crash ]; then exit 1; fi; done

The command in the course video is correct, just in the lab tutorial it has the additional backslash

Additional Feedback

No response

spurin commented 7 months ago

Hi @drewheasman

Thanks so much for raising this. I had to add the \ here intentionally for the lab purposes as sadly, when being echo'd first time round it was actually running the date at the time and then, all of the logs showed the same date.

To demonstrate this, here's a snippet -

root@control-plane:~# cat <<EOF > combined.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: mypod
  name: mypod
spec:
  containers:
  - image: nginx
    name: webserver
    resources: {}
  - image: ubuntu
    name: sidecar
    args:
    - /bin/sh
    - -c
    - while true; do echo "\$(date +'%T') - Hello from the sidecar"; sleep 5; if [ -f /tmp/crash ]; then exit 1; fi; done
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
EOF
root@control-plane:~# kubectl apply -f combined.yaml
pod/mypod created
root@control-plane:~# kubectl logs pod/mypod -c sidecar
12:32:10 - Hello from the sidecar
12:32:15 - Hello from the sidecar
12:32:20 - Hello from the sidecar
12:32:25 - Hello from the sidecar
12:32:30 - Hello from the sidecar
12:32:35 - Hello from the sidecar
root@control-plane:~# kubectl delete -f combined.yaml
pod "mypod" deleted
root@control-plane:~# cat <<EOF > combined.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: mypod
  name: mypod
spec:
  containers:
  - image: nginx
    name: webserver
    resources: {}
  - image: ubuntu
    name: sidecar
    args:
    - /bin/sh
    - -c
    - while true; do echo "$(date +'%T') - Hello from the sidecar"; sleep 5; if [ -f /tmp/crash ]; then exit 1; fi; done
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
EOF
root@control-plane:~# kubectl apply -f combined.yaml
pod/mypod created
root@control-plane:~# kubectl logs pod/mypod -c sidecar
12:34:27 - Hello from the sidecar
12:34:27 - Hello from the sidecar
12:34:27 - Hello from the sidecar
12:34:27 - Hello from the sidecar
12:34:27 - Hello from the sidecar

Again, I very much appreciate your due diligence and appreciate you highlighting this.