Skip to content

Latest commit

 

History

History
44 lines (40 loc) · 2.39 KB

20220317083558-kubectl.org

File metadata and controls

44 lines (40 loc) · 2.39 KB

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

DescriptionCommand
Get namespaceskubectl get ns
Set namespacekubectl config set-context –current –namespace=foo
Show configkubectl config view
Show current namespaceskubectl config view (then grep namespace)
Show current contextkubectl config current-context
Set current contextkubectl config use-context foo
Remove contextkubectl config unset contexts.foo
Get all podskubectl get pods
Execkubectl exec -it mypod – bash
Get deployment infokubectl get deployments foo -o yaml
Nuke everything in a namespacekubectl delete all –all -n foospace
Pod Resource usagekubectl top pod -n foospace
Cluster Resource usagekubectl top node

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.

Get container ID

Example: get the container ID for the web container

kubectl get po --template '{{range.items}}{{.metadata.name}}{{end}}' -n foospace --selector=component=web

Copy remote file to local

kubectl cp deploymentname/$(kubectl get po --template '{{range.items}}{{.metadata.name}}{{end}}' -n foospace --selector=component=web):/path/to/remote/file /path/to/local