kubectl - Core Concepts Flashcards
List all namespaces
kubectl get ns
List all pods in all
kubectl get po –all-namespaces
List all the pods in the particular namespace
kubectl get po -n
List all the services in the particular namespace
kubectl get svc -n
List all the pods showing name and namespace with a json path expression
kubectl get pods -o=jsonpath=”{.items[*][‘metadata.name’, ‘metadata.namespace’]}”
Create an nginx pod in a default namespace and verify the pod running
- kubectl run nginx –image=nginx –restart=Never
2. kubectl get po
Create the same nginx pod with a yaml file
- kubectl run nginx –image=nginx –restart=Never –dry-run -o yaml > nginx-pod.yaml
- kubectl create -f nginx-pod.yaml
Output the yaml file of nginx pod
kubectl get po nginx -o yaml
Output yaml of nginx pod without cluster-specific information
kubectl get po nginx -o yaml –export
Get the complete details of the nginx pod
kubectl describe pod nginx
Delete the nginx pod
kubectl delete po nginx
Delete the pod created with example-pod.yaml
kubectl delete -f example-pod.yaml
Force delete nginx pod
kubectl delete po nginx –grace-period=0 –force
Create nginx pod version 1.17.4 and expose port 80
kubectl run nginx –image=nginx:1.17.4 –restart=Never –port=80
Change nginx image to 1.15-alpine and verify
- kubectl set image pod/nginx nginx=nginx:1.15-alpine
2. kubectl describe po nginx
Change nginx pod image to 1.15-alpine but you can’t remember the image name
kubectl edit po nginx
output just the image version of the nginx pod
kubectl get po nginx -o jsonpath=’{.spec.containers[].image}{“\n”}’
Create nginx pod and get to the shell
- kubectl run nginx –image=nginx –restart=Never
2. kubectl exec -it nginx /bin/sh
Get the IP address of the nginx pod
kubectl get po nginx -o wide
Create a busybox pod and run command ls while creating it then check the logs
- kubectl run busybox –image=busybox –restart=Never – ls
2. kubectl logs busybox
The busybox pod crashed, check previous logs
kubectl logs busybox -p
Create busybox pod with command sleep 3600
kubectl run busybox –image=busybox –restart=Never – /bin/sh -c “sleep 3600”
Use the busybox pod to check the connection of the busybox pod
IP=$(kubectl get po nginx -o=jsonpath=’{.status.podIPs[].ip}’); kubectl exec -it busybox – wget -o- $IP
Create a busybox pod and echo message ‘How are you’ and delete it manually
- kubectl run busybox –image=nginx –restart=Never -it – echo “How are you”
- kubectl delete po busybox