Contents

K8s Useful Commands

Useful k8s commands 💡 💕

Table of contents

How to create pods

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

How to view all objects in k8s

This command will list all the objects under the currect namespace

1
kubectl get all

How 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

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

How 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

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

Reading 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

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