KUBECTL Commands Cheat Sheet
Here is a cli commands cheat sheet for KUBECTL command, you can use this as a quick reminder for basic commands with a brief description for each of the commands.
What is KUBECTL command?
Add some data here
# To display list of all available commands: kubectl -h # To display an explanation of a specific command: kubectl command_name -h # To display complete list of supported resources: kubectl api-resources # Resouces Examples Pods, nodes, services, deployment, replicasets, statefulsets, volumes ... # To display an explanation of a specific resource: kubectl explain resource_name # To display an explanation of a specific field of resource: kubectl explain resource_name.field_name # To display list of global command-line options: kubectl options # To set up `kubectl` autocomplete in bash (press Tab to use): source <(kubectl completion bash) # create resource(s) in a json or yaml file kubectl create -f ./file.yml # create resources in all .json, .yml, and .yaml files in dir kubectl create -f ./dir # Apply resources in all .json, .yml, and .yaml files in dir kubectl apply -f ./dir # List resources in the namespace kubectl get:services,nodes,pods # Get Verbose output for resource , , ,etc kubectl describe # Apply resource(s) in a json or yaml file kubectl apply -f ./file.yml # To display all resources in all namespaces: kubectl get all -A # To order events by `creationTimestamp`: kubectl get events --sort-by='.metadata.creationTimestamp' # To switch context of a specific cluster: kubectl config use-context CONTEXT_NAME [options] # Add a Label to resource kubectl label pods new-label=awesome # Add an annotation kubectl annotate pods icon-url=http://goo.gl/XXBTWq # Dump pod logs (stdout) kubectl logs # Run pod as interactive shell kubectl run -i --tty busybox --image=busybox -- sh # Attach to Running Container kubectl attach -i # Forward port of Pod to your local machine kubectl port-forward # Forward port to service kubectl port-forward # Run command in existing pod (1 container case) kubectl exec -- ls / # Run command in existing pod (multi-container case) kubectl exec -c -- ls /
Check out the KUBECTL command documentation .
You can also check our MegaSh cheatsheet tool, that has 150+ searchable linux cheat sheets in one page, so you never forget a command as you work again