Kubernetes

Kubernetes Cheatsheet #

Kubernetes, also known as K8s, is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Originally developed by Google, Kubernetes is now maintained by the Cloud Native Computing Foundation (CNCF) and is widely used to manage complex microservices architectures.

Kubernetes Basics #

Command/OptionExampleDescription
kubectl versionkubectl versionShow the kubectl version
kubectl cluster-infokubectl cluster-infoDisplay cluster information
kubectl get nodeskubectl get nodesList all nodes in the cluster

Working with Pods #

Command/OptionExampleDescription
kubectl get podskubectl get podsList all pods in the current namespace
kubectl describe podkubectl describe pod <pod_name>Show details of a specific pod
kubectl logskubectl logs <pod_name>Print the logs from a container in a pod
kubectl execkubectl exec -it <pod_name> -- /bin/bashExecute a command in a container in a pod

Working with Deployments #

Command/OptionExampleDescription
kubectl get deploymentskubectl get deploymentsList all deployments in the current namespace
kubectl describe deploymentkubectl describe deployment <deployment_name>Show details of a specific deployment
kubectl create deploymentkubectl create deployment nginx --image=nginxCreate a new deployment
kubectl scale deploymentkubectl scale deployment <deployment_name> --replicas=3Scale a deployment to a specified number of replicas
kubectl delete deploymentkubectl delete deployment <deployment_name>Delete a deployment

Working with Services #

Command/OptionExampleDescription
kubectl get serviceskubectl get servicesList all services in the current namespace
kubectl describe servicekubectl describe service <service_name>Show details of a specific service
kubectl expose deploymentkubectl expose deployment <deployment_name> --type=NodePort --port=8080Expose a deployment as a service
kubectl delete servicekubectl delete service <service_name>Delete a service

ConfigMaps and Secrets #

Command/OptionExampleDescription
kubectl create configmapkubectl create configmap my-config --from-literal=key1=value1Create a ConfigMap from a literal value
kubectl get configmapskubectl get configmapsList all ConfigMaps in the current namespace
kubectl describe configmapkubectl describe configmap <configmap_name>Show details of a specific ConfigMap
kubectl delete configmapkubectl delete configmap <configmap_name>Delete a ConfigMap
kubectl create secretkubectl create secret generic my-secret --from-literal=password=my-passwordCreate a Secret from a literal value
kubectl get secretskubectl get secretsList all Secrets in the current namespace
kubectl describe secretkubectl describe secret <secret_name>Show details of a specific Secret
kubectl delete secretkubectl delete secret <secret_name>Delete a Secret

Persistent Volumes and Claims #

Command/OptionExampleDescription
kubectl get pvkubectl get pvList all PersistentVolumes in the cluster
kubectl get pvckubectl get pvcList all PersistentVolumeClaims in the current namespace
kubectl describe pvkubectl describe pv <pv_name>Show details of a specific PersistentVolume
kubectl describe pvckubectl describe pvc <pvc_name>Show details of a specific PersistentVolumeClaim
kubectl delete pvkubectl delete pv <pv_name>Delete a PersistentVolume
kubectl delete pvckubectl delete pvc <pvc_name>Delete a PersistentVolumeClaim

Namespaces #

Command/OptionExampleDescription
kubectl get namespaceskubectl get namespacesList all namespaces in the cluster
kubectl describe namespacekubectl describe namespace <namespace_name>Show details of a specific namespace
kubectl create namespacekubectl create namespace <namespace_name>Create a new namespace
kubectl delete namespacekubectl delete namespace <namespace_name>Delete a namespace

Additional Commands #

Command/OptionExampleDescription
kubectl applykubectl apply -f <file.yaml>Apply a configuration to a resource by file or stdin
kubectl deletekubectl delete -f <file.yaml>Delete resources by file or stdin
kubectl config viewkubectl config viewDisplay merged kubeconfig settings
kubectl config use-contextkubectl config use-context <context_name>Set the current context in your kubeconfig
kubectl top nodeskubectl top nodesDisplay resource (CPU/memory) usage of nodes
kubectl top podskubectl top podsDisplay resource (CPU/memory) usage of pods

This cheatsheet covers the most commonly used Kubernetes commands and options, helping you to manage clusters, pods, deployments, services, ConfigMaps, Secrets, and more.

Kubernetes

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.