Skip to content

Instantly share code, notes, and snippets.

@azureru
Last active March 17, 2018 19:40
Show Gist options
  • Save azureru/4bf6e490d2869ca5ec39ff5e8d535f28 to your computer and use it in GitHub Desktop.
Save azureru/4bf6e490d2869ca5ec39ff5e8d535f28 to your computer and use it in GitHub Desktop.
Kubernetes Cheatsheet

Starting Up

If you manage it everyday - add this to your .basrc or .bash_profile or cloud-console. If not then all k in this cheatsheet means kubectl

alias k="kubectl"
To gain access to a pod
k exec -it pod-name sh
To gain access to a pod with multiple containers
k exec -it pod-name --container container-name sh

To port forward connection from a pod to local port

# k port-forward pod-name local-port:remote-port
k port-forward pod-name 6379:6379

# k port forward port
k port-forward pod-name 8000

To delete pods

# Delete a pod using the type and name specified in pod.json.
k delete -f ./pod.json

# Delete pods and services with same names "baz" and "foo"
k delete pod,service baz foo

# Delete pods and services with label name=myLabel.
k delete pods,services -l name=myLabel

# Delete a pod with UID 1234-56-7890-234234-456456.
k delete pod 1234-56-7890-234234-456456

# Delete all pods
k delete pods --all

Copy File To A Pod

k cp file pod-name:~/

View Logs

# view log snapshot from a pod 
k logs pod-name

# Begin streaming the logs 
kubectl logs -f pod-name

# tail N number
k logs --tail=20 pod-name

# tail since N time 
k logs --since=1h pod-name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment