Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

List below contains mostly used Kubernetes commands. You can see wide range of commands here and here.

List all resources

$ kubectl api-resources --verbs=list -o name

Delete all x resource (e.g. pods)

$ kubectl delete pods --all

K8S node info (cpu, mem etc)

$ kubectl describe node

List all x resources (e.g. pods)

$ kubectl get all pods

List all containers in a pod

$ kubectl get pods some-pod-name -o json

Show x resource information (e.g. pod)

$ kubectl describe pod some-pod-name

Get into a pod's container

$ kubectl exec -it some-pod-name -c some-container-name sh

Forward K8S port to local port

$ kubectl port-forward some-pod-name some-local-port:some-k8s-port

Dump pod logs

$ kubectl logs some-pod-name

Tail pod container logs

$ kubectl logs -f some-pod-name some-container-name

Exclude some logs while tailing pod logs

$ kubectl logs -f some-pod-name some-container-name | grep -ev '(health|metrics)'

Restart a pod

$ kubectl rollout restart deployment/some-deployment-name
$ kubectl rollout restart deploy some-deployment-name

Delete and restart a pod

$ kubectl delete pod some-pod-name

Delete namespace

If you delete a namespace, all the resources within will be deleted.

$ kubectl delete namespace some-namespace

Switch to a different namespace

$ kubectl config set-context --current --namespace=some-namespace

List events occurred in cluster

$ kubectl get events

Update deployment with a new env var

$ kubectl set env deployment/some-deployment-name some-env-var=some-value

Update container image of deployment

$ kubectl set image deployment/some-deployment-name some-container-name=some-image-name:version