Kubectl
See also https://kubernetes.io/docs/reference/kubectl/cheatsheet/
For some of these commands, use the -n
flag to specify the namespace if the
namespace wasn’t already set with set-context
Description | Command |
---|---|
Get namespaces | kubectl get ns |
Set namespace | kubectl config set-context –current –namespace=foo |
Show config | kubectl config view |
Show current namespaces | kubectl config view (then grep namespace) |
Show current context | kubectl config current-context |
Set current context | kubectl config use-context foo |
Remove context | kubectl config unset contexts.foo |
Get all pods | kubectl get pods |
Exec | kubectl exec -it mypod – bash |
Get deployment info | kubectl get deployments foo -o yaml |
# Recipes
# forward a port
kubectl port-forward --namespace foospace $(kubectl get pods --namespace foospace --selector "app=mssql" --output=name) 1433:1433
This executes an inner command to get the pod name from a selector.