Kubernetes Commands

Debugging

https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-output-verbosity-and-debugging

  • --v=9 is good for seeing values, put into JSON formatter

Get logs for pod

$ kubectl logs <pod_name>

Get logs for ingress controller

$ kubectl logs -n kube-system $(kubectl get po -n kube-system | egrep -o 'alb-ingress[a-zA-Z0-9-]+')

Spinning up the instances

$ kubectl run --replicas=1000 web-server # deploys an application on the cluster 1000 times

Scaling the instances

$ kubectl run --replicas=1000 web-server
$ kubectl scale --replaces=2000 web-server # scales up the current webserver to 2000 instances

Updating the instances

# Updates all instances to the given image
$ kubectl rolling-update web-server --image=web-server:2

Rollback

# If something goes wrong in the updates, we can always roll back all the instances
$ kubectl rolling-update web-server --rollback

View Information on the Cluster

$ kubectl cluster-info

See nodes in cluster

$ kubectl get nodes

List pods

$ kubectl get pods

Describe pods (Troubleshooting)

$ kubectl describe pod <pod_name>

Exec into bash

$ kubectl exec -it <pod_name> -c <container_name> -- /bin/bash

Delete pods by pattern

kubectl get pods -n default --no-headers=true | awk '/<word>/{print $1}'| xargs  kubectl delete -n default pod

Last updated