Kubernetes Cheat Sheet: Essential Concepts and Commands
Kubernetes, the popular container orchestration platform, is known for its complexity as well as its power. Understanding its core concepts and mastering its command line interface can greatly improve efficiency and productivity when managing containerized applications. This article provides a quick overview of key Kubernetes concepts followed by a comprehensive cheat sheet of commands.
Key Kubernetes Concepts
Pods: The smallest deployable units created and managed by Kubernetes, a Pod is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers.
Services: An abstract way to expose an application running on a set of Pods as a network service. With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism.
Deployments: Manage the deployment and scaling of a set of Pods, and provide declarative updates to Pods along with a lot of other useful features.
Nodes: Worker machines in Kubernetes, which host the Pods that are the components of the application workload.
Cluster: A set of Nodes that run containerized applications managed by Kubernetes.
Namespaces: Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.
Volumes: A directory, possibly with some data in it, which is accessible to the containers in a pod.
ConfigMaps and Secrets: Kubernetes objects that allow you to store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys.
Kubernetes Command Line Interface (kubectl)
kubectl
is the command line tool for Kubernetes. It allows you to run commands against Kubernetes clusters for managing resources, viewing logs, and other maintenance tasks. Here’s a cheat sheet of essential kubectl
commands:
Command | Description | Example Usage |
---|---|---|
kubectl get | List resources | kubectl get pods |
kubectl describe | Show detailed information about a resource | kubectl describe nodes my-node |
kubectl create | Create a resource from a file or stdin | kubectl create -f my-resource.yaml |
kubectl apply | Apply a configuration to a resource by filename or stdin | kubectl apply -f ./ |
kubectl delete | Delete resources by filenames, stdin, resources and names, or by resources and label selector | kubectl delete -f ./my-resource.yaml |
kubectl logs | Print the logs for a container in a pod | kubectl logs my-pod |
kubectl exec | Execute a command in a container | kubectl exec -ti my-pod -- bash |
kubectl run | Run a particular image on the cluster | kubectl run my-pod --image=myimage |
kubectl expose | Expose a resource as a new Kubernetes service | kubectl expose deployment my-dep --port=8080 |
kubectl scale | Scale a resource | kubectl scale --replicas=3 deployment/my-dep |
kubectl autoscale | Autoscale a deployment, replica set, or replication controller | kubectl autoscale deployment my-dep --min=10 --max=15 --cpu-percent=80 |
kubectl rollout | Manage the rollout of a resource | kubectl rollout status deployment/my-dep |
kubectl set | Set specific features on objects | kubectl set image deployment/my-dep my-container=myimage:latest |
kubectl config | Modify kubeconfig files | kubectl config view |
kubectl top | Display Resource (CPU/Memory/Storage) usage. | kubectl top pod |
kubectl cluster-info | Display cluster info | kubectl cluster-info |
kubectl plugin | Provides utilities for interacting with plugins. | kubectl plugin list |
kubectl attach | Attach to a running container. | kubectl attach my-pod -i |
kubectl patch | Update field(s) of a resource using strategic merge patch. | kubectl patch node my-node -p '{"spec":{"unschedulable":true}}' |
kubectl label | Update the labels on a resource. | kubectl label pods my-pod new-label=my-label |
kubectl annotate | Update the annotations on a resource. | kubectl annotate pod my-pod icon-url=http://my-icon.com |
kubectl port-forward | Forward one or more local ports to a pod. |
Comments
Post a Comment