Cheatsheets

Kubernetes

kubectl

CommandsDescriptions
kubectl config get-contextsList all the contextsin your kubeconfig file.
kubectl config current-contextDisplay current context.
kubectl config use-context <context name>Sets the current-context to the specified context.
kubectl apply -f <config file/directory>This will apply configuration to a resource. This will create the resource if the resource does not exist yet.
kubectl apply -f <config file/directory>This will delete resources created by the yaml file.
kubectl rollout status deployment <name>Watches the rollout status of a deployment.
Eg., kubectl rollout status deployment my-app-depl
kubectl rollout restart deployment <name>Restarts a resource. This will also pull the latest container images.
Eg., kubectl rollout restart deployment my-app-depl
kubectl get allList all resources
kubectl get <resources>List a specific resource.
Eg., kubectl get pods
kubectl get pods --watchWatches pod status updates.
kubectl explain <resource>List the fields of a resource.
Eg.,
kubectl explain deployment
kubectl describe <resource>Prints a detailed description of the selected resource.
Eg.,
kubectl describe deployment
kubectl describe pods -l name=myLabel
kubectl api-resourcesShow supported API resources (kinds).
kubectl api-versionsShow supported API versions.
kubectl exec -it <pod name> -- <command>Access the pod container.
Eg., kubectl exec -it my-app-depl-65c67ff97c-jtxhs -- bash

Imperative commands

Declarative approach is recommended, but there are some exemptions, such as when you're creating secrets.

CommandsDescriptions
kubectl create secret generic <secret_name> --from-literal <KEY>=<VALUE>Create a secret based on specified literal value.
kubectl create deployment <name> --image <image>Create a deployment.
Eg., kubectl create deployment my-nginx --image nginx
kubectl create deployment <name> --image <image> --dry-run -o yamlPrint out the object ina yaml format. This will not actually send the object.
Eg., kubectl create deployment my-nginx --image nginx --dry-run -o yaml
kubectl expose deployment <name> --port <port>Creates a ClusterIP service for a deployment.
Eg., kubectl expose deployment my-nginx --port 8080
kubectl expose deployment <name> --port <port> --type NodePortCreates a NodePort service for a deployment.
Eg., kubectl expose deployment my-nginx --port 8888 --type NodePort
kubectl expose deployment <name> --port <port> --type LoadBalancerCreates a LoadBalancer service for a deployment.
Eg., kubectl expose deployment my-nginx --port 8080 --type LoadBalancer
ingress-nginxIngress controller for Kubernetes using NGINX as a reverse proxy and load balancer.
cert-managerKubernetes add-on to automate the management and issuance of TLS certificates from various issuing sources.