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

Delete

Delete pod

Force delete pod

  • Setting the -grace-period option to 0 deletes the pod immediately

  • The --force option enables forced deletion

Fully shut down the Deployment

Delete Service Account

Delete Deployment

Log

View Pod logs

View logs for a specific container

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

Events

View Events

View Events sorted by timestamp

Get commands w/ basic output

List all services

List all pods in all namespaces

List all pods in the current namespace w/ more detail

List all deployment in all namespaces

Last updated