K8s Useful Commands

Contents
Useful k8s commands 💡 💕
Table of contents
- How to create pods
- How to view all objects in k8s
- How to find or count the number of k8s objects - namespace, pods, service
- How to delete or terminate the pod force
- Print lables of an object or pods
How to create pods
How to create pods
kubectl run podname --image imagenameThis command will create a nginx pods
kubectl run nginx-pod --image nginxHow to view all objects in k8s
This command will list all the objects under the currect namespace
kubectl get allHow to find or count the number of k8s objects - namespace, pods, service
To simplify the output we are using --no-headers attributes alone with the commands
kubectl get namespace --no-headers | wc -lHow to delete or terminate the pod force
Sometime we want to delete to pod without waiting time. The below command is useful to delete the pod without waiting time or delte / terminate the pod immediately
k delete pod <pod-name> --force --grace-period 0Reading the documentation in commandline
One of the easyway to copy the syntax without referring web documentation
First search the command in the command line documentation
kubectl explain pods --recursive | lesskubectl explain pods --recursive | grep -i envFrom -A 10 -B10This will list the envFrom syntax spec , before and after 10 lines
Print lables of an object or pods
kubectl get pods --show-labels