Question
Write a command into /opt/course/15/cluster_event.sh which shows the latest events in the whole cluster, ordered by time. Use kubectl for it.
Now kill the kube-proxy Pod running on node cluster2-worker1 and write the events this caused into /opt/course/15/pod_kill.log
Finally kill the containerd container of the kube-proxy Pod on node cluster2-worker1 and write the events into /opt/course/15/container_kill.log
Answer
For the first command you can grab the answer from Kubernetes documentation if you search for kubectl cheatsheet:
# List Events sorted by timestamp
kubectl get events -A --sort-by=.metadata.creationTimestamp
Create the shell file:
echo "kubectl get events -A --sort-by=.metadata.creationTimestamp" > /opt/course/15/cluster_event.sh
Test:
bash /opt/course/15/cluster_event.sh
Get pods running on kube-system namespace with extended details:
kubectl get po -n kube-system -o wide
Find the pod running on cluster2-worker1 and delete it and write the events:
kubectl -n kube-system delete po kube-proxy-wk5jt
kubectl -n kube-system get events > /opt/course/15/pod_kill.log
Next - login to cluster2-worker1 and kill the container:
ssh cluster2-worker1
creictl ps
crictl stop xxxxxxxx # id of the kube-proxy pod
Go back to the master and write events:
kubectl -n kube-system get events > /opt/course/15/container_kill.log
Analyze the logs:
cat /opt/course/15/pod_kill.log
cat /opt/course/15/container_kill.log