logo

kubectl

Last Updated: 2023-02-16

Clusters

Get a list of clusters:

$ kubectl config get-clusters
NAME
kind-kind

Get Cluster Info

$ kubectl cluster-info
$ kubectl cluster-info dump

Specify output columns

$ kubectl get services -A -o=custom-columns=NAME:.metadata.name,Namespace:.metadata.namespace

API Resources

To see which Kubernetes resources are and aren't in a namespace:

# In a namespace
$ kubectl api-resources --namespaced=true

# Not in a namespace
$ kubectl api-resources --namespaced=false

Get a list of Services:

$ kubectl get services

Get a list of controllers: check the service accounts:

$ kubectl -n kube-system get sa

Check resource consumption

$ kubectl top node
$ kubectl top pod -A

Pods

Get pods on a specific node.

$ kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>

Plugins

Add the tree plugin to visualize

$ kubectl krew install tree

How to force restart a pod

kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f -

Check status

kubectl get --raw='/readyz?verbose'