July 26, 2023 ・ Kubernetes
Kubernetes 101: Understanding the Basics. Key Concepts and Features of Container Orchestration
Kubernetes has become the de facto standard for container orchestration and management, enabling developers to deploy and scale containerized applications quickly and efficiently. In this article, we will introduce the key concepts and features of Kubernetes, its architecture, and how it can be used to manage containerized applications at scale.
If you're familiar with Docker, then Kubernetes is something that will help you take your infrastructure to new levels of robustness and scalability.
What is Kubernetes?
Kubernetes is an open-source container orchestration system that automates the deployment, scaling, and management of containerized applications. It was originally developed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes provides a platform-agnostic way of managing containerized applications, making it possible to deploy and manage applications across different cloud providers, data centers, and on-premises infrastructure.
Containers are a lightweight way of packaging software applications with all their dependencies into a single unit. They are similar to virtual machines (VMs) but are much lighter and more efficient. Containers use the host operating system's kernel, which allows them to share resources and run on any platform that supports the container runtime. Containers are an important tool for developers because they allow them to package and ship applications more quickly and consistently across different environments.
Different kinds of Kubernetes
There are several Kubernetes implementations and tools available, each with its own strengths and weaknesses. Broadly, there's two groups of them: non-managed (that you can host on baremetal servers) and managed (cloud-based).
- Vanilla Kubernetes
Vanilla Kubernetes is the official Kubernetes distribution, which can be downloaded and installed on any infrastructure. It provides a base Kubernetes cluster with no additional features or integrations, but it allows you to customize your cluster and add additional components as needed. It's a reference implementation and usually should not be your first choice.
Kubeadm is a tool for bootstrapping a Kubernetes cluster on any infrastructure, including on-premises, cloud, or hybrid environments. It provides a simple command-line interface for creating and managing Kubernetes clusters, and it also supports automatic upgrades and scaling.
- Rancher Kubernetes Engine (RKE)
Rancher is a Kubernetes distribution that includes additional features such as built-in DevOps tools, integrated container registry, and support for multiple Kubernetes clusters. It allows you to manage your own Kubernetes clusters on any infrastructure, including on-premises, cloud, or hybrid environments.
Minikube is a lightweight, open-source tool that enables developers to run a single-node Kubernetes cluster on their local machine. It is designed to make it easy for developers to experiment with Kubernetes without the need for a full-scale production environment.
MicroK8s is a lightweight, single-node Kubernetes distribution that is designed to run on resource-constrained environments such as edge and IoT devices, as well as on developer workstations. It is an open-source project that is maintained by Canonical, the company behind Ubuntu Linux.
Kubespray is a tool for deploying and managing Kubernetes clusters on any infrastructure, including on-premises, cloud, or hybrid environments. It provides a simple command-line interface for deploying and managing Kubernetes clusters, and it also supports automatic upgrades and scaling.
- Google Kubernetes Engine (GKE)
GKE is a managed Kubernetes service provided by Google Cloud Platform. It offers automatic scaling, load balancing, and integrated logging and monitoring. GKE also integrates well with other Google Cloud services such as Cloud Storage, Cloud SQL, and BigQuery.
- Amazon Elastic Kubernetes Service (EKS)
EKS is a managed Kubernetes service provided by Amazon Web Services. It offers automatic scaling, load balancing, and integrates well with other AWS services such as Amazon S3, RDS, and DynamoDB. EKS also allows you to run your Kubernetes control plane on your own AWS account or use Amazon's managed control plane.
- Microsoft Azure Kubernetes Service (AKS)
AKS is a managed Kubernetes service provided by Microsoft Azure. It offers automatic scaling, load balancing, and integrates well with other Azure services such as Azure Container Registry, Azure DevOps, and Azure Active Directory. AKS also provides built-in security features such as network policies and private clusters.
Declarative vs. Imperative management
Kubernetes provides two ways to manage your cluster: declarative and imperative. Each approach has its own advantages and trade-offs, and it's important to understand them to choose the right approach for your use case. In general, you should design your architecture from a declarative point of view, and defer to imperative actions only during troubleshooting, testing and research.
Declarative management is the preferred way of managing your Kubernetes cluster. It involves defining the desired state of your cluster using configuration files, and letting Kubernetes figure out how to achieve that state.
Declarative management involves creating objects that define the desired state of your applications and services. For example, you might define a deployment object that specifies the number of replicas of your application that should be running, the container image to use, and other configuration options.
When you apply this configuration file to your cluster, Kubernetes will compare the current state of your cluster with the desired state described in the configuration file. If there are any differences, Kubernetes will make the necessary changes to bring the current state of the cluster in line with the desired state.
Declarative management has several advantages. First, it makes it easy to manage your cluster at scale. You can use tools like GitOps to manage your Kubernetes configurations and automate the deployment of changes to your cluster. This makes it easy to manage complex applications and services with many dependencies.
Another advantage of declarative management is that it makes it easy to roll back changes to your cluster. If a change causes problems or introduces bugs, you can simply roll back to a previous version of your configuration file and let Kubernetes revert the cluster to the previous state.
Imperative management involves directly manipulating the current state of your cluster. For example, you might use the kubectl command-line tool to create a new deployment object, update the number of replicas of an existing deployment, or delete a pod.
While imperative management can be useful for some tasks, such as debugging or ad-hoc changes, it has several disadvantages. First, it can be error-prone, especially when managing complex applications with many dependencies. It can be easy to make mistakes or overlook important details when making changes manually.
Another disadvantage of imperative management is that it can be difficult to reproduce changes. If you make changes manually, it can be hard to track exactly what was done and when. This can make it difficult to debug problems or roll back changes if something goes wrong.
Kubernetes has a highly modular and extensible architecture that enables it to be customized and extended to meet specific needs. The core components of Kubernetes are the master nodes and worker nodes.
The master nodes are responsible for managing the overall state of the cluster. They contain several components, including:
API server: This component provides a RESTful API that can be used to interact with the Kubernetes cluster.
etcd: This is a distributed key-value store that stores the configuration data for the cluster.
Controller manager: This component is responsible for maintaining the desired state of the cluster, including managing deployments, services, and other objects.
Scheduler: This component is responsible for scheduling pods onto worker nodes based on resource availability and other factors.
The worker nodes run the actual containers. They contain several components, including:
Kubelet: This component runs on each worker node and is responsible for starting and stopping containers.
kube-proxy: This component runs on each worker node and is responsible for routing traffic to the appropriate container.
Container runtime: This is the software that actually runs the containers, such as Docker or rkt.
In Kubernetes, everything is an object. An object is a persistent entity that represents the state of your cluster. There are several types of objects in Kubernetes, including:
Pod: The smallest deployable unit in Kubernetes. A pod is a single instance of a container.
Deployment: A higher-level object that manages the deployment and scaling of multiple pods.
Service: A way of exposing a set of pods to the network.
Ingress: A way of routing incoming traffic to different services in the cluster.
ConfigMap: A way of storing configuration data that can be accessed by pods.
Secret: A way of storing sensitive data, such as passwords or API keys, that can be accessed by pods.
Custom: A way of extending the Kubernetes API, providing new functionality for the cluster.
Kubernetes objects are described using YAML or JSON files. You can use these files to define the desired state of your applications and services. Kubernetes will then ensure that the current state of your cluster matches the desired state.
Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications across a cluster of nodes. It provides a range of features for managing complex containerized applications, including automated scaling, high availability, self-healing, and easy portability across different environments.
Kubernetes is designed to work with a variety of container runtimes, such as Docker, and can be deployed on any infrastructure, including on-premises, cloud, or hybrid environments. Its ability to manage complex containerized applications has made it an essential tool for modern application development and deployment.
It's relatively simple in design, but is freely extendable and has flexibility to be useful in a lot of situations where containerization is acceptable — which is, nowadays, almost every situation you will encounter.