K8S cheat sheet for developer, daily used k8s cheat sheet!!
Table of contents
Basic Commands
kubectl get
: list resourceskubectl describe
: show details of a resourcekubectl create
: create a resource from a file or stdinkubectl apply
: apply a configuration file to create or update resourceskubectl delete
: delete a resourcekubectl edit
: edit a resource live
Pods
kubectl run
: create a new deployment with one or more replicaskubectl logs
: show the logs of a podkubectl exec
: run a command in a running container in a pod
Deployments
kubectl create deployment <deployment name> --image=<image name>
: Create a new deployment with a specified image.kubectl get deployments
: List all deployments in the current namespace.kubectl describe deployment <deployment name>
: Get detailed information about a deployment.kubectl rollout status deployment/<deployment name>
: Check the status of a deployment rollout.kubectl rollout history deployment/<deployment name>
: View the revision history of a deployment.kubectl rollout undo deployment/<deployment name>
: Roll back a deployment to the previous revision.kubectl scale deployment <deployment name> --replicas=<number>
: Scale the number of replicas in a deployment.kubectl set image deployment/<deployment name> <container name>=<new image>
: Update the image of a container in a deployment.kubectl delete deployment <deployment name>
: Delete a deployment.
Services
kubectl get services
: View a list of all services in the current namespace.kubectl describe service <service-name>
: Get detailed information about a specific service.kubectl create service <service-type> <service-name> [--tcp=<port>] [--dry-run]
: Create a new service.<service-type>
can beClusterIP
,NodePort
, orLoadBalancer
.kubectl expose <resource-type> <resource-name> [--port=<port>] [--target-port=<target-port>] [--type=<service-type>] [--name=<service-name>]
: Expose a port for a resource (e.g. a deployment or pod) as a new service.<service-type>
can beClusterIP
,NodePort
, orLoadBalancer
.kubectl edit service <service-name>
: Edit the configuration of an existing service.kubectl delete service <service-name>
: Delete a service.
Note that some of these commands require additional parameters, such as the port number or target port. Also, the
expose
command is deprecated in recent versions of Kubernetes, so it's recommended to usecreate service
instead.
Configurations
kubectl config view
: View the current kubeconfig file configuration.kubectl config use-context <context-name>
: Set the active context in the kubeconfig file.kubectl config set-context <context-name> --namespace=<namespace>
: Set a namespace for a specific context.kubectl config set-cluster <cluster-name> --server=<server-url>
: Set the server URL for a cluster in the kubeconfig file.kubectl config set-credentials <user-name> --token=<token>
: Set the credentials for a user in the kubeconfig file.kubectl config delete-context <context-name>
: Delete a context from the kubeconfig file.kubectl config unset <property>
: Unset a specific property in the current context.kubectl config use-context <context-name> --kubeconfig=<file-path>
: Set the active context in a specific kubeconfig file.kubectl config view --minify
: View the current kubeconfig file configuration in a compact format.kubectl config current-context
: Display the name of the current context in the kubeconfig file.
There are many more commands but in general if you are a developer these commands are more than enough.
I hope this helps, you!!
More such articles:
https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA
\==========================**=========================
If this article adds any value to you then please clap and comment.
Let’s connect on Stackoverflow, LinkedIn, & Twitter.