Skip to content

Instantly share code, notes, and snippets.

@jakerella
Created November 24, 2021 20:38
Show Gist options
  • Save jakerella/0a775d92481f05e0aa68a6a60afc4092 to your computer and use it in GitHub Desktop.
Save jakerella/0a775d92481f05e0aa68a6a60afc4092 to your computer and use it in GitHub Desktop.
A cheat sheet for common kubectl CLI actions
# list all contexts in your kube config
kubectl config get-contexts
# switch to a specific context
kubectl config use-context [context-name]
# add a new context to your kube config
(login to aws on the cli first)
aws eks --region [cluster-region (us-east-1)] update-kubeconfig --name [cluster] --role-arn arn:aws:iam::[ACCOUNT]:role/[ROLE_NAME]
(note, role may be named differently in different accounts)
# get list of all pods in a cluster
kubectl get pods --all-namespaces
# get list of pods in a namespace
Kubectl get pods -n [namespace]
# get info on a single pod
kubectl describe pod [pod-id] -n [namespace]
# check logs for a particular pod
kubectl logs [pod-id] -c [container-name] -n [namespace]
# exec into DSE instance
kubectl -n dse-xl exec -it dse-0 -- /bin/bash
# to exec into any pod
kubectl -n [namespace] exec -it [pod-id] -- /bin/bash
# to copy a file from local machine to a pod
kubectl cp [/path/to/local/file] [pod-id]:[/remote/file/path] -c [container]
# to port forward a pod
kubectl -n [namespace] port-forward [pods/pod] [localhost_port]:[remote port]
# Delete a pod (should redeploy)
kubectl delete -n [namespace] pod [pod-id]
# See K8s events from a namespace
kubectl get events -n [namespace]
# See what node (EC2) the pods in a namespace are using with "-o wide"
kubectl get pods -n [namespace] -o wide
# See all the details of a single node, including what services/other stuff is running on it
kubectl describe node [node-id]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment