kubectl api-resources

No shorthand

List API Resources

kubectl api-versions

No shorthand

List API Versions

kubectl apply --filename [file].yaml

kubectl apply -f [file].yaml

Apply Configuration File

kubectl auth can-i [verb] [resource]

No shorthand

Check Can I Do Something

kubectl cluster-info

No shorthand

View Cluster Info

kubectl config current-context

No shorthand

Show Current Context

kubectl config get-contexts

No shorthand

List all Contexts

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

No shorthand

Set Default Namespace

kubectl config use-context [context-name]

No shorthand

Switch Context

kubectl config view

No shorthand

View Kubeconfig

kubectl config view --output=jsonpath='{.users[*].name}'

kubectl config view -o jsonpath='{.users[*].name}'

View Current User Tokens

kubectl cordon [node-name]

No shorthand

Cordon a Node

kubectl cp [local-path] [pod-name]:[path-in-pod]

No shorthand

Copy File to Pod

kubectl cp [pod-name]:[path-in-pod] [local-path]

No shorthand

Copy File from Pod

kubectl create configmap [name] --from-file=[path]

kubectl create cm [name] --from-file=[path]

Create a ConfigMap from File

kubectl create configmap [name] --from-literal=key=value

kubectl create cm [name] --from-literal=key=value

Create a ConfigMap from Literal

kubectl create deployment [name] --image=[image]

kubectl create deploy [name] --image=[image]

Create a Deployment

kubectl create namespace [name]

kubectl create ns [name]

Create a Namespace

kubectl create secret generic [name] --from-literal=key=value

No shorthand

Create a Secret from Literal

kubectl delete deployment [deployment-name]

kubectl delete deploy [deployment-name]

Delete a Deployment

kubectl delete namespace [name]

kubectl delete ns [name]

Delete a Namespace

kubectl delete pod [pod-name]

kubectl delete po [pod-name]

Delete a Pod

kubectl delete pod [pod-name] --force --grace-period=0

kubectl delete po [pod-name] --force --grace-period=0

Force Delete a Pod

kubectl delete service [service-name]

kubectl delete svc [service-name]

Delete a Service

kubectl describe configmap [name]

kubectl describe cm [name]

Describe a ConfigMap

kubectl describe deployment [name]

kubectl describe deploy [name]

Describe a Deployment

kubectl describe ingress [name]

kubectl describe ing [name]

Describe an Ingress

kubectl describe node [node-name]

kubectl describe no [node-name]

Describe a Node

kubectl describe persistentvolumeclaim [name]

kubectl describe pvc [name]

Describe Persistent Volume Claim

kubectl describe persistentvolume [name]

kubectl describe pv [name]

Describe Persistent Volume

kubectl describe pod [pod-name]

kubectl describe po [pod-name]

Describe a Pod

kubectl describe secret [name]

No shorthand

Describe a Secret

kubectl describe service [service-name]

kubectl describe svc [service-name]

Describe a Service

kubectl drain [node-name] --ignore-daemonsets --delete-emptydir-data

No shorthand

Drain a Node

kubectl edit pod [name]

kubectl edit po [name]

Edit a Resource

kubectl exec --stdin --tty [pod-name] -- /bin/bash

kubectl exec -it [pod-name] -- /bin/bash

Execute Interactive Shell

kubectl explain pod

kubectl explain po

Explain a Resource

kubectl expose deployment [name] --port=80 --target-port=8080

kubectl expose deploy [name] --port=80 --target-port=8080

Expose a Deployment as a Service

kubectl get configmaps

kubectl get cm

List ConfigMaps

kubectl get cronjobs

kubectl get cj

List all CronJobs

kubectl get daemonsets

kubectl get ds

List all DaemonSets

kubectl get deployments

kubectl get deploy

List all Deployments

kubectl get events --sort-by='.metadata.creationTimestamp'

kubectl get ev --sort-by='.metadata.creationTimestamp'

List Cluster Events

kubectl get ingress

kubectl get ing

List all Ingresses

kubectl get jobs

No shorthand

List all Jobs

kubectl get namespaces

kubectl get ns

List all Namespaces

kubectl get nodes

kubectl get no

List all Nodes

kubectl get persistentvolumeclaims

kubectl get pvc

List Persistent Volume Claims

kubectl get persistentvolumes

kubectl get pv

List Persistent Volumes

kubectl get pods

kubectl get po

List all Pods

kubectl get pods --all-namespaces

kubectl get po -A

List Pods in all Namespaces

kubectl get pods --output wide

kubectl get po -o wide

List Pods with Wide Output

kubectl get pods --selector [key]=[value]

kubectl get po -l [key]=[value]

Filter Pods by Label

kubectl get replicasets

kubectl get rs

List all ReplicaSets

kubectl get secret [name] -o jsonpath='{.data.key}' | base64 --decode

kubectl get secret [name] -o jsonpath='{.data.key}' | base64 -d

Get Secret Value (Base64 Decoded)

kubectl get secrets

No shorthand

List Secrets

kubectl get services

kubectl get svc

List all Services

kubectl get statefulsets

kubectl get sts

List all StatefulSets

kubectl get storageclasses

kubectl get sc

List Storage Classes

kubectl label pod [pod-name] [key]-

kubectl label po [pod-name] [key]-

Remove Label from Pod

kubectl label pod [pod-name] [key]=[value]

kubectl label po [pod-name] [key]=[value]

Add Label to Pod

kubectl logs --follow [pod-name]

kubectl logs -f [pod-name]

Stream Pod Logs

kubectl logs [pod-name]

No shorthand

View Container Logs

kubectl logs [pod-name] --previous

kubectl logs [pod-name] -p

Logs from Previous Container Instance

kubectl port-forward pod/[pod-name] 8080:80

kubectl port-forward po/[pod-name] 8080:80

Forward Port to Local

kubectl rollout history deployment [name]

kubectl rollout history deploy [name]

View Rollout History

kubectl rollout restart deployment [name]

kubectl rollout restart deploy [name]

Restart a Deployment

kubectl rollout status deployment/[name]

kubectl rollout status deploy/[name]

Rollout Status

kubectl rollout undo deployment/[name]

kubectl rollout undo deploy/[name]

Rollout Undo (Rollback)

kubectl run [name] --image=[image] --restart=Never

No shorthand

Run a Temporary Pod

kubectl scale deployment [name] --replicas=5

kubectl scale deploy [name] --replicas=5

Scale a Deployment

kubectl top nodes

kubectl top no

Check Resource Usage (Top Nodes)

kubectl top pods

kubectl top po

Check Resource Usage (Top Pods)

kubectl uncordon [node-name]

No shorthand

Uncordon a Node