Commands that I use frequently but can never seem to remember.
Set k8s context:
kubectl config set-context --current --namespace=NAMESPACE
Copy from a container:
kubectl cp NAMESPACE/POD_NAME:/path_to_file/SRC_FILE -c CONTAINER_NAME dest_file
the SRC_FILE can be a single file or a directory.
Copy to a container:
kubectl SRC_FILE NAMESPACE/POD_NAME:/path_to_file/dest_file -c CONTAINER_NAME
Get secret:
kubectl get secret secret_name -o jsonpath={.data.secret_path} | base64 -d
Example:
kubectl get secret db-info -o jsonpath={.data.db-username} | base64 -d
List every k8s component in a given namespace:
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -nl -n NAMESPACE
List containers in a given pod:
kubectl get pods PODNAME -o jsonpath='{.spec.containers[*].name}'
Change context:
kubectl config set-context --current --namespace=NAMESPACE
Scale up a deployment:
kubectl scale deploy DEPLOYMENT_NAME --replicas=2