2024/2025
Command to start a pod - ANSWERSkubectl run nginx --image=nginx --restart=Never
Command to change image of a pod - ANSWERSkubectl set image pod/nginx nginx=nginx:1.7.1
Sequence to ping a pod from busybox - ANSWERSkubectl run busybox --image=busybox --restart=Never
--rm -it -- sh
# / wget -O- <pod_ip>:80
#/ exit
Output nice yaml from a resource - ANSWERSkubectl get pod nginx -o yaml --export
Get logs of a previous version of a pod - ANSWERSkubectl logs nginx -p
Attach a process to a running pod - ANSWERSkubectl exec -it nginx -- /bin/sh
Set an environment variable from command line - ANSWERSkubectl run nginx --image=nginx --
env=var1=val1
Multi-container pod - ANSWERSkubectl run busybox --image=busybox -o yaml --dry-run -- /bin/sh -c
'echo hello;' > pod.yaml
# vi pod.yaml, Copy + Paste container list and rename the container
kubectl create -f pod.yaml
kubectl exec -it busybox -c busybox2 -- /bin/bash # Connect to second container
Create a pod with labels - ANSWERSkubectl run --image... --restart=Never --labels=app=v1,label2=val2
, Show labels on pods / resource - ANSWERSkubectl get pods --show-labels
Label a running pod - ANSWERSkubectl label po nginx app=v2 --overwrite
Get all pods with a certain label - ANSWERSkubectl get po -lapp
Remove a label from a running pod - ANSWERSkubectl label nginx{1..3} app-
Get documentation for a pod spec - ANSWERSkubectl explain po.spec
Annotate a running pod - ANSWERSkubectl annotate po nginx description='test description'
kubectl annotate po nginx description- # Remove
Create pod with 2 replicas and open port 80 from yaml - ANSWERSkubectl create deploy nginx --
image=... --dry-run -oyaml > deploy.yaml
vi deploy.yaml
# Change replicas: 2
# Under containers list add following
ports:
- containerPort: 80
kubectl create -f deploy.yaml
Check status and history of a deployment - ANSWERSkubectl rollout status deploy nginx
kubectl rollout history deploy nginx
Up replicas of a deployment to 5 - ANSWERSkubectl scale deploy nginx --replicas=5