Step 1: defining the architecture

In short
  • Fundamentals of the Kubernetes architecture chosen for Cookbook V1 (legacy).
  • Why a naming convention for servers and objects.
  • Architecture diagram and principles: control plane, workers, modularity.
  • An overview of concepts, detailed in the following steps.

Legacy version of the Kubernetes cookbook

This article is part of the first version of the cookbook (VMware and PhotonOS). A new version, on XCP-ng and Rocky Linux, is being published: the equivalent step is Step 00 - Architecture and components. The article remains online for reference.

Introduction

The following article aims to present the fundamentals chosen for the Kubernetes architecture (or K8S/KUB), which serves as a tutorial and hosting solution for my personal needs. Several concepts specific to K8S will be presented, but not necessarily detailed here. It is therefore possible that some principles may seem confusing if you are not already familiar with the Kubernetes ecosystem. This is not necessarily a problem at this stage.

What is important to know is that Kubernetes is based on a principle of modularity. A Kubernetes cluster consists of several servers, virtual and/or physical, on which functional components run, each responsible for a specific role.

Some of these components can be redundant, and are more or less critical for the proper functioning of the cluster. They can also be customized or enhanced according to needs.

Components of a K8S cluster

Click the image to enlarge.

Interacting with a Kubernetes cluster primarily involves interacting with an API. This API has different branches that contain the definition of various objects.

Each object has a specific purpose and a number of properties, which are mandatory and/or optional.

It is the combination of all these objects, which can be manipulated through the API, that will allow you to run your applications.

You can thus describe the state in which you want your assets to be, and Kubernetes will always strive to ensure that the execution state corresponds to your requirements.

The need for a naming convention

Kubernetes is an ecosystem that can quickly become complex. Running an application under K8S involves a whole set of objects described in an API. These objects all have a specific role (managing deployment, providing storage, exposing a service, etc.) and may be dependent on each other to function.

I will detail the role and usage of these objects in dedicated articles, but keep in mind that their manipulation is mainly (but not exclusively) done through YAML files, which contain a set of properties describing the characteristics of the targeted object.

Example of K8S objects

Click the image to enlarge.

Thinking about a naming convention for these files at the beginning of a project is a good practice. This helps to understand the architecture once it is deployed and simplifies automation operations in order to implement industrialization.

There are no "good" or "bad" naming conventions; there is only the convention that makes sense to you and your team. The essential thing is that it is shared by all stakeholders on the cluster and strictly adhered to.

As for me, I have chosen the following standard:

env-shortname_object-role-net

  • env is a trigram used to represent the environment in which the object operates: prd for production, int for integration, and dev for development.
  • shortname is the abbreviated version of the object's name as defined in the Kubernetes API. For example, a persistentvolume will be referenced as pv, and a deployment is named deploy. These names can be found by running the command kubectl api-ressource on an active cluster.
  • ShortName of K8S objects

    Click the image to enlarge.

  • role helps to further describe what the object will be used for. If the description is unnecessary or unsuitable, I use the term "default".
  • net represents the network zone associated with the object. In my case, it is either lan for an internal application, dmz for an application exposed on the web, or na for not applicable.

Once again, everyone is free to choose their preferred naming convention; the important thing is to adopt one and stick to it.

Similarly, the naming of cluster nodes is important and must correspond to a predefined convention. In my case:

envk8srol5YX

  • env is a trigram representing my environment: prd for production, int for integration, and dev for development.
  • k8s indicates that this VM is part of a Kubernetes cluster.
  • rol is a trigram associated with the role of the server in the cluster, either ctp for a control plane or nod for a standard execution node. This will be explained further in the article.
  • 5 is associated with a virtual environment
  • Y takes the value 0 if it is a VM on the LAN, and 1 if it is a VM in the DMZ
  • X is simply the server number

K8S architecture diagram and principles

Before diving into installing the cluster, it's good to define on paper what you want to deploy.

A diagram is worth more than a long explanation, so here is a quick overview of my cluster.

Infrastructure diagram

Click the image to enlarge.

Handling the storage layer

In the world of containerization, it is common practice to minimize the need for persistent storage. A container should be able to stop and restart without depending on data directly attached to it. However, this mode of operation is not compatible with all use cases. For example, a containerized database will need to find its databases. That's why in K8S, we separate the execution layer from the storage layer. The two are handled through different objects, and it is the combination of the two that allows you to design an application. We will talk about persistentvolumes (pv) to describe the objects responsible for hosting the data.

For my needs, two types of volumes will be set up through what is called storageclasses (sc). These objects allow you to define storage spaces offering certain characteristics (performance, block or file...). The cluster can, depending on the requirements, automatically provision a persistent volume in one of these storage classes. This provisioning will be done through a third object called persistentvolumeclaims (pvc). In principle, a user will describe their storage needs in a pvc, which will be evaluated by the cluster, which will then offer a pv from the sc corresponding to the expected characteristics.

The idea is not to go into detail here, but here is a diagram from weng-albert.medium.com that describes the logic.

Conceptual diagram for storage under K8S

Click the image to enlarge.

An sc will most of the time rely on a CSI, for Container Storage Interface: a kind of driver provided by a third party that complies with the standards set by the Kubernetes project. It allows a cluster to drive a storage provider, such as a cloud solution, a specific storage array or a third-party ecosystem with a storage solution. It is an extremely powerful concept: without having to worry about the final storage solution, the storage class + CSI combination makes it possible to offer, within the cluster and completely transparently, several options for hosting persistent data. On one side, infrastructure teams can choose the provider they want, as long as it offers a CSI driver, and developers can pick the storage class that matches their needs (or that they are allowed to use) without worrying about the rest. If the storage provider were to change, another CSI driver would be declared in the sc without affecting the deployment files.

Here are the two sc offered:

  • A storage class prd-sc-vmfs-default-na: This storage class will rely on the CSI driver from VMware to enable the creation of PVs directly within a VMFS datastore. We can provide high-performance, block-based storage that is accessible for both reading and writing. In my case, I typically use this SC for databases. Since my cluster runs as a VM on a VMware infrastructure, a PV using this SC will appear as a mapped disk to the VM that executes the workload associated with that volume. If, for some reason, the execution context changes nodes, the disk will be automatically unmapped and then remapped to the new VM associated with the selected node.
  • A storage class prd-sc-nfs-default-na: this storage class will rely on a NAS offering NFS space. The pv (persistent volumes) created from this sc can be read and written to by multiple targets simultaneously. In my case, I will use it for the static content of my website or other needs for sharing between different assets.

Handling the network layer

The core components of K8S are focused on container orchestration. For third-party features such as the container runtime engine, their storage, or communication between them, Kubernetes allows you to choose the technologies you prefer. These supplementary components can be provided by third-party solutions, provided they adhere to a certain standard and comply with common norms. Regarding networking, Kubernetes offers the CNI specification for the Container Network Interface. Various solutions or "plugins" are based on CNI to handle the network layer within a K8S cluster. Each user can choose the plugin that best suits their needs, depending on the features it offers: supported routing protocol, ability to use access policies, etc.

Trends change, and since I started working with Kubernetes, I have already switched CNI solutions 3 times. At the time of writing, I have chosen Cilium, which seems to be the market favorite... in fact, the company behind this open source project was acquired by Cisco at the end of 2023... Cilium's success seems largely due to its implementation of eBPF (Extended Berkeley Packet Filter), a technology introduced in the 4.x branch of the Linux kernel. I am far from understanding exactly what lies behind it, but in Cilium's case, it gives it very advanced observability capabilities on the network flows circulating within a Kubernetes cluster.

Another debate that can be found within the K8S community is whether to use nodes in a DMZ or dedicate an entire cluster to exposed network zones.

For me, there are no right or wrong answers. As always, it all depends on the constraints you may have, especially regarding cybersecurity.

By default, Kubernetes operates on an "all-pass" logic, but many mechanisms exist to isolate resources from each other and segment your cluster into specific, isolated zones.

In my case, I don't have the luxury of creating more clusters, so I will rely on these protection mechanisms to ensure that an asset in the DMZ cannot freely communicate with an asset on the LAN by taking advantage of the internal network within the cluster.

Handling the compute layer

Currently, this is a VMware cluster with several ESXi servers that will be used to host my cluster. The details of my installation are available here

Over time, I may switch to a different solution due to issues that have arisen following the acquisition of VMware by Broadcom.

Regardless, I would certainly continue using PhotonOS, regardless of whether it runs on VMware nodes, Proxmox, or other systems. You are, of course, free to choose the operating system of your choice. Ultimately, it won't matter much, because in my case, I have decided to use a so-called "vanilla" installation using the Kubeadm tool.

It is important to know that Kubernetes remains a modular solution where each component is available individually. It is up to you to assemble them and potentially modify them to build your cluster. This can be tedious work, which is why there are Kubernetes "distributions" that will take care of deploying everything necessary on your virtual or physical nodes. These "suites" are offered with many associated tools, such as GUIs and assisted update methods. Examples include OpenShift from RedHat, or Tanzu from VMware. Even though there are free versions of these solutions, they are generally expensive products aimed at businesses. A so-called "vanilla" installation is a deployment that does not rely on a distribution but directly uses the basic components. Fortunately, this type of installation has evolved significantly over time and is becoming increasingly easier, especially thanks to Kubeadm.

Kubeadm is the official installer associated with the K8S project. It will greatly simplify deployment by preconfiguring all the necessary components based on configuration elements that you provide as arguments. Note that other methods exist, such as kubespray, which relies on Ansible.

In my case, I will also use Ansible, but simply to make it easier to create the cluster configuration files. Finally, be aware that one of the most commonly used solutions for installing a Kubernetes cluster is the managed offering from cloud providers. Azure, AWS, or GCP, among others, offer managed clusters that can be deployed with just a few clicks.

This allows you to focus on your applications and not on the administration of the cluster.

Deployment solution for Kubernetes

Click the image to enlarge.

As for me, I prefer to maintain complete control over my cluster, even if it means taking on all the maintenance responsibilities. This is also, in my opinion, the best way to gain experience and truly understand how Kubernetes works.

It's important to carefully consider all available options, and while I often hear criticism of using a vanilla installation in an enterprise environment, I believe it remains a completely viable solution as long as you have the necessary skills internally (or are willing to develop them).

More broadly, in professional environments, it's not uncommon to see mixed deployments. You might find one or more on-premises clusters deployed using Kubeadm or based on a dedicated distribution, along with other clusters in the cloud for different needs and workloads. This is where one of Kubernetes' greatest strengths lies. Regardless of the platform, as long as it adheres to K8S standards, it becomes possible to design a truly hybrid infrastructure where you can choose at any time to run your applications on a specific platform based on your performance, availability, security, and cost constraints.

Staying with the modular approach, the container runtime is also a choice for the user. This is particularly true with a vanilla installation.

The world of containerization has evolved significantly, and while Docker was once ubiquitous, used to refer to everything and anything, that's no longer the case today. The industry has agreed on a standard through the Open Container Initiative (OCI). Now, running a container is done via runtimes that adhere to this standard. The most well-known and, in fact, the original of the standard is runc, the component historically used by Docker, which was "given" to the OCI.

runc is truly the lowest-level component. On top of that, you often find containerd, which adds a management environment that can be controlled, most often through a CLI like Docker's.

But it doesn't end there. Kubernetes also offers its own standard: the Container Runtime Interface (CRI). This is intended to define how Kubernetes controls a runtime...

In summary, we often have a runtime executing a container according to the OCI standard, combined with an additional environment that can be managed by Kubernetes because it is compatible with CRI. For my part, I will stick with the classic containerd/runc.

The diagram below summarizes these principles, as well as those previously explained regarding networking and storage.

Standards and principles of containerization with K8S

Click the image to enlarge.

Handling the Kubernetes layer

My Kubernetes cluster consists of three control plane nodes, 2 worker nodes on the LAN, and 2 worker nodes in the DMZ.

The control plane nodes are essential for the proper functioning of the cluster. They host the API server, without which it is impossible to interact with the cluster, as well as many other critical roles. They also store the key/value database etcd, in which all of the cluster's configuration is stored. (Note that some prefer to use dedicated etcd instances hosted outside of the control plane).

We often see examples where a single master node is used. This is very good for learning or for handling non-critical environments, but in production environments, we cannot rely on only one master node. If this node were to fail, it would impact interaction with the cluster. While having a master node unavailable does not make applications already running on the cluster inoperable, there is no longer any orchestration, and it becomes impossible to manage the cluster.

It should be noted that two master nodes are not sufficient to provide a high availability (HA) solution, because this is insufficient to achieve consensus on the state of the cluster. A third master node is mandatory to allow all master nodes to agree with each other.

If maintaining a control plane cluster seems daunting, then managed solutions from cloud providers are made for you. In these offerings, you do not have to manage the control plane. You simply interact with the K8S API, but it is up to the cloud provider to ensure the proper functioning of the nodes.

Regarding the hardware configuration of the VMs hosting the various roles, I will start with the minimum recommended for the control plane, which is 2 vCPUs and 2 GB of RAM. 20 GB of disk space is sufficient, but I will end up using 60 GB.

For the worker nodes, we will use 4 vCPUs and 4 GB of RAM, as well as 60 GB of disk space. However, these figures may be adjusted depending on the cluster's load. Please note that the disk volumes are only for the system; as mentioned in the section about storage, reserved spaces for assets are handled differently.

The case of third-party applications

Load balancing logic

Click the image to enlarge.

Exposing the API and entry points

As indicated above, the cluster has three control planes. To ensure high availability of the API they host, it is necessary to expose them through a virtual IP (VIP) via a load balancer.

I chose HAproxy because it is a reputable and widely used open-source solution. Several HAproxy instances will be deployed to cover the API's accessibility needs, as well as external access to applications hosted within the cluster.

Exposing the applications

Once again, it is important to remember that Kubernetes operates on a modular principle. By default, your application is made accessible through dedicated objects called Services (svc). These can be of different types, but are primarily intended for exposing your assets within the cluster.

When it comes to exposing your applications outside the cluster, the basic functionality remains limited. It is recommended to use additional tools to provide more options.

As always with Kubernetes, exposing your applications outside the cluster involves using dedicated objects. In this case, we will talk about ingress (ing), which are themselves linked to the svc. I won't go into detail here, but an ingress can be "controlled" using an ingress controller. This latter will rely on the base object to then process the request and enable processing of requests.

For my part, I chose the Traefik solution. It is a product that I particularly appreciate.

While other solutions like NGINX existed before K8S and were later made compatible with it, Traefik was designed for Kubernetes and more generally for containerization (don't let me say that NGINX isn't good).

It can be deployed in two ways on a cluster. Either by enriching the K8S API. In this case, we talk about CustomResourceDefinition (CRD). This involves adding new objects specific to the deployed solution to the basic Kubernetes objects. This allows you to fully leverage Traefik's capabilities, but it does not guarantee that these new objects will be available on managed Kubernetes solutions or those associated with a distribution. That is why I prefer to stick with the basic Ingress object, where annotations will be added to be processed by Traefik.

It should be noted that as of the time this article was written, there is much talk of a new native Kub object called gateway, which is intended to replace Ingress objects. I will probably use them in the future, but for now, I am not yet very familiar with how they work.

Conclusion

As mentioned at the beginning of this article, it is possible that for someone who has never worked with Kubernetes, some points may still seem unclear. This was a brief overview of some key principles that can be detailed further in later steps. The important thing is to have at least an idea of the components to deploy and the target to achieve.


To continue the cookbook with the next step, click here