Kubernetes concepts
1. Kubernetes concepts
To understand how Kubernetes works, it's important to understand two related concepts. The first concept is the Kubernetes object model. Each item Kubernetes manages is represented by an object, and you can view and change these objects attributes and state. The second concept is the principle of declarative management. Kubernetes needs to be told how objects should be managed, and it will work to achieve and maintain that desired state. This is accomplished through a "watch loop." A Kubernetes object is defined as a persistent entity that represents the state of something running in a cluster: its desired state and its current state. Various kinds of objects represent containerized applications, the resources available to them, and the policies that affect their behavior. Kubernetes objects have two important elements. The first is an object spec for each object being created. It's here that the desired state of the object is defined by you. The second is the object status, which represents the current state of the object provided by the Kubernetes control plane. By the way, "Kubernetes control plane" is a term to refer to the various system processes that collaborate to make a Kubernetes cluster work. You'll learn about these processes later. Each object represents a certain type, or "kind," as it's referred to in Kubernetes. Pods are the foundational building block of the standard Kubernetes model, and they're the smallest deployable Kubernetes object. Every running container in a Kubernetes system is in a Pod. A Pod creates the environment where the containers live, and that environment can accommodate one or more containers. If there is more than one container in a Pod, they are tightly coupled and share resources, like networking and storage. Kubernetes assigns each Pod a unique IP address, and every container within a Pod shares the network namespace, including IP address and network ports. Containers within the same Pod can communicate through localhost, 127.0.0.1. A Pod can also specify a set of storage volumes that will be shared among its containers. Let's explore an example where you want three instances of an nginx Web server, each in its own container, to be always kept running. How can this be achieved in Kubernetes? You'll recall that Kubernetes operates off of the principle of declarative management, which means that you'll need to declare some objects to represent those nginx containers, and in this case, those objects should be Pods. From there, it's Kubernetes's job to launch those Pods and keep them in existence. Alright, so you've given Kubernetes a desired state that consists of three nginx Pods, to be always kept running. We did this by telling Kubernetes to create and maintain one or more objects that represent them. Now Kubernetes will compare the desired state to the current state. For this example, let's say our declaration of three nginx containers is completely new, meaning the current state does not match the desired state. So Kubernetes, specifically its control plane, will remedy the situation. Because the number of desired Pods running for the object you declared is 3, and 0 are presently running, 3 will be launched. And the Kubernetes control plane will continuously monitor the state of the cluster, endlessly comparing reality to what has been declared, and remedying the state as needed.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.