Kubernetes is a container-orchestration system we use at my current job.
It’s not my primary focus at work but from time to time I need to use
the kubectl
command line tool. The is a small cheat sheet to refresh
my memory.
Kubernetes
1####
2# VERIFY CONFIGURATION
3####
4kubectl cluster-info # Display cluster info
5kubectl config view # Display merged kubeconfig settings
6
7####
8# LISTING, FINDING RESOURCES
9####
10kubectl api-resources # List supported resources
11kubectl get nodes -n <namespace> # Review status and roles of nodes
12kubectl get nodes -n <namespace> -o wide # Show additional information about nodes in cluster
13kubectl get services -n <namespace> # Show services
14kubectl get pods -n <namespace> # List pods
15kubectl get pods -n <namespace> --show-labels # Show labels for pods
16kubectl get pods -n kube-system # List system pods
17kubectl get all --all-namespaces | more # List all resources in all namespaces
18
19####
20# EXAMINING RESOURCES
21####
22kubectl describe <resource> # Check out Name, Taints, Conditions, Addresses, System Info, Non-Terminated Pods, and Events
23
24####
25# CONNECTION TO RESOURCES
26####
27kubectl exec <pod> -n <namespace> ls # List directory
28kubectl exec -it <pod> -n <namespace> sh # Run interactive shell
29
30####
31# PORT FORWARDING
32####
33kubectl port-forward service/<service> 8080:80 -n <namespace>
34kubectl port-forward <pod> 8080:80 -n <namespace>
35
36####
37# LOGS
38####
39kubectl logs <pod> -n <namespace> # dump pod logs (stdout)
40kubectl logs -l name=myLabel -n <namespace> # dump pod logs with label (stdout)
41kubectl logs -f <pod> -n <namespace> # stream pod logs (stdout)
Helm (v2)
1helm list --all-namespaces # List releases with some basic information
2
3helm delete <release-name> # Delete release from k8s cluster; deletes all k8s objects belonging to release
4helm delete <release-name> --purge # Delete release with all the config data (configmap)
5helm reset # Deleted Tiller's pod, service and deployment; deletes only service side
6
7
8helm install <chart> # Install a Chart
9helm install <chart> --dry-run --debug #
10helm upgrade <release> <chart> # Upgrade a release to a new revision
11helm rollback <release> <version> # Rollback a release to a previous revision
12
13helm history <release> # Lists revision history of the release
14helm status <release> # Display status of the release (installed objects and running statuses)
15helm get <release> # Show details about the release, chart and current values