Useful kubectl commandsΒΆ
The following commands are useful for checking the status of your cluster or of the applications running in it
kubectl get <resource> [instance] [-o json] : Get a list or single instance of a kubernetes resource.
Resources:
deployment
service
configmap
secret
statefulset
pod
<any other kubernetes resource>
kubectl describe <resource> <instance> : Shows details of the resource instance status. Useful for troubleshooting
kubectl logs <pod|controller> <instance> <container> [--all-containers=true] [-f] : Print the logs of the specified
pod or resource. The -f flag can be used to follow logs.
kubectl exec <podname> [-c containername] -- <command> : Execute the command in a container. To interactively run
the command, add the -it flag. This works more or less identically to the docker exec command.
kubectl delete <resource> <instance> : Delete the specified resource instance.
kubectl port-forward <podname> localport:podport : Start a local listener that forwards all traffic on
localhost:localport to the podport in the pod on the cluster. Useful for testing applications where there
is no external network access.
For more useful commands, see the kubectl Cheat Sheet