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

Full cluster list

$ kubectl config get-contexts

List all resources in all namespaces

$ kubectl get all --all-namespaces

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)'

Tailing latest 5 logs

$ kubectl logs -f --tail 5 deployment.apps/pacman

Live watch pod status changes

$ watch 'kubectl get pods'

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