To understand basic Kubernetes commands



kubectl version

Cluster Info

kubectl cluster --info

Get All info about Pods, Deployments Services etc

kubectl get all

kubectl get services

kubectl get pods

$ kubectl get deployments --show-labels

Create a deployment

kubectl run {pod-name} --image={image-name}

Port Forward

kubectl port-forward {pod-name} {external-port:internal-port}

Port Expose

kubectl expose

Create Resource

kubectl create

kubectl apply


kubectl delete pod {pod-name}

kubectl delete deployment {deployment-name}

kubectl delete -f {yaml-file}

Describe Pod

kubectl describe pod {pod-name}

kubectl describe deployment{pod-name}

Running from Yaml file

Dry run:

$ kubectl create -f nginxserv.pod.yml --dry-run --validate=true


$ kubectl create -f nginxserv.pod.yml

(if you want to update future, add --save-config)

$ kubectl create -f nginxserv.pod.yml --save-config

Apply (for create/overwrite)

$ kubectl apply -f nginxserv.pod.yml

$ kubectl apply -f nginxserv.deployment.yml

Edit Pod

$ kubectl edit -f nginxserv.pod.yml

Login to shell

$ kubectl exec {pod-name} -it sh


$ kubectl scale -f nginxserv.deployment.yml --replicas=3

$ kubectl get all
NAME                              READY   STATUS    RESTARTS   AGE
pod/nginx-serv-6c7d88fb47-jtk54   1/1     Running   0          8s
pod/nginx-serv-6c7d88fb47-v5msb   1/1     Running   0          8s
pod/nginx-serv-6c7d88fb47-xggwj   1/1     Running   0          4m40s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP    <none>        443/TCP   6d2h

NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-serv   3/3     3            3           4m40s

NAME                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-serv-6c7d88fb47   3         3         3       4m40s