K8s Useful Commands

Contents

Useful k8s commands 💡 💕

How to create pods

1
2
kubectl run podname --image imagename

This command will create a nginx pods

1
kubectl run nginx-pod --image nginx

This command will list all the objects under the currect namespace

1
kubectl get all

To simplify the output we are using --no-headers attributes alone with the commands

1
kubectl get namespace --no-headers | wc -l

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

1
k delete pod <pod-name> --force --grace-period 0

One of the easyway to copy the syntax without referring web documentation

First search the command in the command line documentation

1
kubectl explain pods --recursive | less
1
kubectl explain pods --recursive | grep -i envFrom -A 10 -B10

This will list the envFrom syntax spec , before and after 10 lines

1
kubectl get pods --show-labels