Skip to content

Latest commit

 

History

History
98 lines (78 loc) · 2.01 KB

Kubectl.md

File metadata and controls

98 lines (78 loc) · 2.01 KB

Kubectl

Run commands against a particular namespace

kubectl -n namespace <command>

View all pods|services|ingresses

kubectl get pods|services|ingresses

View all autoscalers (hpa, Horizontal Pod Autoscaler)

kubectl get hpa

Delete a given pod|service|ingress|hpa

kubectl delete pod|service|ingress|hpa <pod|service|ingress|hpa_name>

Completely redeploy a deployment

kubectl rollout restart deployment <deployment_name>

View all deployments

kubectl get deployments

Scale a deployment to 0

kubectl scale deployment deployment_name --replicas 0

View all contexts

kubectl config get-contexts

Switch context

kubectl config use-context <context-name>

Copy file from a pod to local filesystem

kubectl cp pod_name:/path/filename /path/filename

Copy file with retries (useful for very large files)

If you are copying a large file and see this (incomplete download):

Dropping out copy after 0 retries
error: unexpected EOFDropping out copy after 0 retries
error: unexpected EOF

Add --retries 10 to circumvent
kubectl cp pod_name:/path/filename /path/filename --retries 10

View all events in order

kubectl -n <namespace> get events --sort-by=.metadata.creationTimestamp

View configmap

kubectl -n <namespace> describe cm <configmap-name> -o yaml

Edit configmap (vi[m] editor)

kubectl -n <namespace> edit configmap <configmap-name>

List all secrets

kubectl -n <namespace> get secrets

View a secret

kubectl -n <namespace> get secret <secret_name> -o yaml

Create a secret in one-line

kubectl -n <namespace> create secret generic <secret_name> --from-literal=password="password123"

Copy a secret from one context to another

kubectl -n <namespace> --context <context> get secret <secret_name> -o yaml | kubectl -n <namespace> --context <context> apply  -f -