If you are inspired to become a DevOps (**Devlopment+**Operations)'s Engineer and start your journey as a beginner, or if you're a professional looking to refresh your DevOps knowledge or transition into DevOps, or even if you're a learning geek seeking to expand your knowledge base, then you landed to the right place. Nowadays, Kubernetes (sometimes shortened to K8s with the 8 standing for the number of letters between the “K” and the “s” ) is a trending technology in the field of DevOps, and having a good understanding of it is crucial.
The **Kubernetes Cheat Sheet is a comprehensive guide that serves as a quick reference for learning both the basics and advanced commands of Kubernetes. Whether you are a beginner just starting your journey with Kubernetes or an experienced professional with over 5 years of experience, this guide provides all the necessary commands for managing clusters, nodes, namespaces, and more.
**Pre-requisites: Before moving to the Cheat sheet you should have a basic understanding of What Kubernetes exactly is, what are their uses, and how it helps. and knowledge of EKS, and AKS are additional advantages.
What is Kubernetes?
**Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, and container load balancing (also called a container orchestration tool). It is written in Golang and has a vast community because it was first developed by Google and later donated to CNCF (Cloud Native Computing Foundation). Kubernetes can group ‘n’ number of containers into one logical unit for managing and deploying them easily. It works brilliantly with all cloud vendors i.e. public, hybrid, and on-premises.
**Kubectl (CLI): Kubectl is a command line configuration tool (CLI) for kubernetes used to interact with a master node of Kubernetes. Kubectl has a config file called kubeconfig, this file has the information about the server and authentication information to access the API Server.
Kubernetes (Kubectl) CheatSheet
**Kubernetes CheatSheet servers as a quick reference guide for some commands and operations which are widely used in the kubernetes cluster. In this cheat sheet, Cluster management, node management, namespace management, resource creation, resource viewing and finding, resource deletion, file and directory copying, resource patching, resource scaling, pod management, deployment management, ReplicaSets management, service management, config maps and secrets, networking, storage, stateful sets, monitoring, troubleshooting, and other operations will be covered.
Kubernetes Master Node Components Important Terminologies
**API Server
**Scheduler
**Controller-Manager
**etcd
API Server
Kube API Server interacts with API, its a frontend of the kubernetes control plane. Communication center for developers and other kubernetes components.Receiving queries from multiple clients, including the kubectl command-line tool, the API server serves as the front-end interface for the Kubernetes control plane, coordinating cluster-wide operations.
Scheduler
The scheduler watches the pods and assigns the pods to run on specific hosts. A new pod does not have a specific node assigned when it is formed, whether by a user, a deployment controller, or a replication controller. The scheduler chooses a suitable node for the pod to run on after assessing the resource needs of the pod, such as CPU and memory usage, as well as any restrictions or affinity/anti-affinity rules supplied.
Controller-Manager
The controller manager runs the controllers in the background which run different tasks in the kubernetes cluster. Performs cluster-level functions(Replication, Tracking worker nodes, Handling failures).
etcd
etcd is a simple distributed key-value store. kubernetes uses etcd as its database to store all cluster data. Some of the data stored in etcd is job scheduling information, pods, state information and etc.
Kubernetes Worker Node Components Important Terminologies
Worker nodes are the node where the application actually runs in a kubernetes cluster, it is also known as a minion. These worker nodes are controlled by the master node using Kublet processes.
**kubelet
**kube-Proxy
**Container runtime
Kubelet
The main node agent, known as Kubelet, operates on each node and reads the container manifests to make sure that the containers are active and in good condition. It ensures that pods of containers are operating. Containers that weren't made by Kubernetes are not managed by the kubelet.
Kube-Proxy
By managing network rules on the host and managing connections, kube-proxy supports the kubernetes service abstraction. On nodes, Kube-proxy keeps track of network rules. Network connectivity to your pod is permitted by these network rules from both inside and outside of your cluster. Having a network proxy and load balancer for the service on a single worker node is beneficial to us.
Container Runtime
To process commands from the master server to run containers, each node needs a container runtime, such as Docker, containerd, or another container runtime.
Kubernetes (Kubectl) Commands
**For Cluster Management
Command
Description
kubectl cluster-infokubectl
Get cluster information.
kubectl get nodes
Views all the nodes present in the cluster.
For Node Management
Command
Description
kubectl get nodes
List all nodes in the cluster.
kubectl describe node
Describe a specific node.
kubectl drain
Drain a node for maintenance.
kubectl uncordon
Uncordon a node after maintenance.
kubectl label node <node_name> =
You can label the node by using key-value pair.
kubectl label node <node_name> <label_key>-
You can remove the label which is already attached to the node.
The verbosity of kubernetes can be controlled by using a command which is kubectl verbosity. We can add no **flags according to our requirements.
Command
Command
kubectl get --v=<verbosity-level
By using this command you set the level of verbosity output.
kubectl get --v=0
Used to be visible to a cluster operator.
kubectl get --v=3
You can more information like extended information about changes.
kubectl get --v=7
Displays the HTTPS request headers.
kubectl get --v=8
Display HTTP request contents.
Conclusion
The Kubernetes Cheatsheet will help to have a quick reference of the most commonly used in Kubernetes (kuberctl commands). Kubernetes is one of the powerful container orchestration platforms by which you can manage applications in the form of containers. The commands which are mentioned in the Cheat Sheet provide a quick reference guide for both beginners and experienced before attending any interviews also.