Skip to content

Latest commit

 

History

History
84 lines (51 loc) · 1.87 KB

Cheatsheet.md

File metadata and controls

84 lines (51 loc) · 1.87 KB

kubectl Cheat Sheet

The official cheat sheet can be found here.

Short Version

A short summary of kubectl commands.

Help

kubectl --help

You can use help on any other sub-command. Examples:

  • kubectl get --help
  • kubectl run --help
  • kubectl create svc clusterip --help

Run a single pod

Run a single pod without anything more.

kubectl run --image nginx demo

Print and follow the logs of a pod

Print the logs to your console that were generated by a container inside the pod.

kubectl logs -f <POD-NAME>

Attach to a running pod

Open a shell or execute a binary.

kubectl exec -it <POD-NAME> -- <BINARY>

Examples:

  • kubectl exec -it demo -- sh
  • kubectl exec -it demo -- whoami

View and find Pods, Deployments etc.

Simple, short table output: kubectl get <RESOURCE-KIND> Descriptive ouptut: kubectl describe <RESOURCE-KIND <RESOURCE-NAME>

Examples:

  • kubectl get pods
  • kubectl get deployments,services
  • kubectl get secret
  • kubectl get po -l demo
  • kubectl describe pod demo

Create Deployments, Services etc.

Create Kubernetes objects.

Imperatively: kubectl create <RESOURCE-KIND> ...

Examples:

  • kubectl create deploy demo --image nginx --replicas=2
  • kubectl create svc clusterip demo --tcp 8000:8000

Declaratively: kubectl apply -f <FILE-NAME>.yaml

Delete Deployments, Services etc.

Delete Kubernetes objects.

kubectl delete <RESOURCE-KIND> <RESOURCE-NAME>

Examples:

  • kubectl delete deployment demo
  • kubectl delete -f <FILE-NAME>.yaml
  • kubectl get po -o yaml | kubectl delete -f -

Port forward from Pods

Access a pod or service on the Kubernetes cluster via localhost.

kubectl port-forward <RESOURCE-KIND> <LOCAL-PORT>:<REMOTE-PORT>

Examples:

  • kubectl port-forward po demo 8080:8000
  • kubectl port-forward svc demo 80:8000