The beginners kubectl cheatsheet

There’s no denying that Kubernetes is pretty awesome for deploying and managing your web apps, and platforms such as GCP make it really easy to jump in and get started. However, anything you can do in a GUI, you can do faster when you jump into the CLI.

So, without further ado; here’s my beginners cheatsheet for Kubernetes. This should cover all of the most frequently used commands.

1. kubectl apply

kubectl apply is used to create or update resources in a cluster from a configuration file. The configuration file can be in YAML or JSON format.

Example:

kubectl apply -f deployment.yaml

2. kubectl get

kubectl get is used to retrieve information about resources in a cluster. It can be used to get information about pods, services, deployments, and more.

Example:

kubectl get pods

3. kubectl describe

kubectl describe is used to get more detailed information about a resource. It can be used to get information about pods, services, deployments, and more.

Example:

kubectl describe pod my-pod

4. kubectl logs

kubectl logs is used to retrieve logs from a container running in a pod.

Example:

kubectl logs my-pod -c my-container

5. kubectl exec

kubectl exec is used to execute a command in a container running in a pod.

Example:

kubectl exec my-pod -c my-container -- ls /

6. kubectl delete

kubectl delete is used to delete resources from a cluster. It can be used to delete pods, services, deployments, and more.

Example:

kubectl delete pod my-pod

7. kubectl edit

kubectl edit is used to edit a resource in a cluster.

Example:

kubectl edit pod my-pod

8. kubectl port-forward

kubectl port-forward is used to forward a port from a pod to your local machine.

Example:

kubectl port-forward my-pod 8080:80

9. kubectl rollout

kubectl rollout is used to manage rollouts of new versions of a deployment.

Example:

kubectl rollout undo deployment/my-deployment

10. kubectl scale

kubectl scale is used to scale the number of replicas of a deployment.

Example:

kubectl scale deployment/my-deployment --replicas=3

These are just some of my most commonly used kubectl commands. There are many more available, so be sure to consult the official documentation for more information.