Skip to content

Latest commit

 

History

History
153 lines (95 loc) · 1.95 KB

File metadata and controls

153 lines (95 loc) · 1.95 KB

Kubectl Commands

A cheat sheet to stop doing history | grep



Namespace

View Namespaces

kubectl get namespace

Change Namespace

kubectl config set-context --namespace=[namespace name]

Create Namespace

kubectl create namespace [namespace name]

Execute pod

kubectl exec -it [pod name] -- [path]

ex)

k exec -it prism-69b8c846c-gc9zj -- /bin/sh
  • kubectl command is aliased to k
  • Note that some cases use /bin/bash instead of /bin/sh

Execute specific container

k exec -it [pod name] -c [container name] -- [path]

Delete

Delete pod

kubectl delete pod [pod name]

Force delete pod

kubectl delete pod [pod name] -grace-period=0 --force
  • Setting the -grace-period option to 0 deletes the pod immediately
  • The --force option enables forced deletion

Fully shut down the Deployment

kubectl delete all --selector app=[APP_IDENTIFIER]

Delete Service Account

kubectl delete serviceaccount [service account name]

Delete Deployment

kubectl delete deploymnet [deployment name]

Log

View Pod logs

kubectl logs -f [pod name]

View logs for a specific container

If multiple containers are running in a single pod, use the -c option to specify the container

kubectl logs -f [pod name] -c [container name]

Events

View Events

kubectl get events

View Events sorted by timestamp

kubectl get events --sort-by=.meta.creationTimestamp

Get commands w/ basic output

List all services

kubectl get services

List all pods in all namespaces

kubectl get pods --all-namespaces

List all pods in the current namespace w/ more detail

kubectl get pods -o wide

List all deployment in all namespaces

kubeclt