Contents

K8s Useful Commands

Useful k8s commands 💡 💕

Table of contents

How to create pods

How to create pods

kubectl run podname --image imagename

This command will create a nginx pods

kubectl run nginx-pod --image nginx

How to view all objects in k8s

This command will list all the objects under the currect namespace

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

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

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

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

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

kubectl get pods --show-labels