Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to set up a Kubernetes environment on Plenit

Keep reading if you want to discover how to set up a Kubernetes environment in Plenit and get the most out of it.

Since Google released the Kubernetes project almost 10 years ago (2014), this technology has been gaining more and more prominence until it has become an essential element in microservices management.

Kubernetes is an extensible, portable and flexible platform based on open software (open source) that allows us to manage workloads of different sizes and that includes variable sizing, allowing all kinds of services to be deployed, facilitating, among other things, automation and response to workload spikes and other types of changing workloads.

The way Kubernetes operates makes it an ideal platform for PaaS (Platform as a Service) or IaaS (Infrastructure as a Service)-based management.

How to set up a Kubernetes environment in Plenit?

Prerequisites and recommendations:

To successfully complete this tutorial and be able to set up a Kubernetes environment in Plenit the following will be necessary:

  • On the one hand, be registered on the Plenit Platform with an organization and be registered in it after doing Log-in.

  • Have three servers Ubuntu 22.04 deployed within the subscription.

kubernetes-nacho-1 = Master.
kubernetes-nacho-2 = Worker 1.
kubernetes-nacho-3 = Worker 2.
  • A user with administrator privileges either through "root" or using the "sudo" command.

  • According to Kubernetes specifications, the provisioned virtual machines must have at least 2GB of RAM, 2 CPUs, and at least 20GB of hard disk space to work, although depending on the use they are going to be put to, it may be necessary to increase these requirements.

Step 1. Preparing the machine before deploying Kubernetes

The first thing to do before starting the deployment of Kubernetes is update the packages and the distribution to make sure we have the most up-to-date packages and the latest updated sources.

To do this, you must run the following commands.

Let's remember that the "sudo" command is used in Ubuntu distributions to run commands with elevated privileges. It would be something like a "Super User Do" (Do as Super User), the equivalent of a "RunAs" in Microsoft environments.

Step 1. We launch the update of the packages and the distribution

One of the points that we must control when working with Kubernetes is the use of swap memory. Sometimes problems have occurred during scaling of the PODS, since the system does not manage them correctly if the system SWAP is active.

To avoid erratic behavior, the best option is to disable this option using the "swapoff" command.

To check whether it has been disabled, several methods can be used.

So that it is not activated on reboot and cannot be used in any way it must be removed from the file systems table, that is, from "/etc/fstab" so it must be edited and the lines where the word "swap" appears commented out.

Once that is done, you can run the query with a "cat" (if you are a cat lover you can use any other viewing command) to see if it was saved correctly.

This cleanup process of the "/etc/fstab" file could also be done with the following command:

This command based on "sed" searches for the string "swap", without applying typing, and places a hash "#", which is the symbol used to comment out text.

Step 1. We disable SWAP so there are no problems with Kubernetes PODS

It is possible that you may want to change the machine name to identify it within our network or for any other purpose. This process can be carried out before the entire Kubernetes setup process, which is why we mention it before starting the actual procedure.

It is the name is queried current through the command "hostname", although it should actually be visible as part of the Bash prompt.

Next, to change the machine name the "sudo hostnamectl set-hostname" command is run followed by the new name and the "exec bash" command is run so that the changes take effect.

An example of all this could be:

Where:

  • <New_Name>: Will be the name received by the machine from that moment on.

An example could be:

Where:

  • "kubernetes-nacho-1" will be the name received by the machine from that moment on.

Step 1. We change the machine name to identify it on the network as a Kubernetes server

The next step is configure the kernel (system core) with some additional parameters so that Kubernetes can work correctly.

To do this, you must edit the file "/etc/sysctl.conf" by running the following commands:

And the following sequence:

Step 1. We configure Kernel parameters for use with Kubernetes

The next step will be to run the “sysctl –system” command so that reloads the configuration of the kernel with the changes we have made.

We will need to review the architecture we want to set up and the IPs and names of the servers involved, which in this case would be something like this:

Server
Name in Plenit
Internal IP

kubernetes-nacho-1

Ubuntu22Nacho1

10.0.0.96

kubernetes-nacho-2

Ubuntu22Nacho2

10.0.0.33

kubernetes-nacho-3

Ubuntu22Nacho3

10.0.0.92

With that we generate the data that the “/etc/hosts” file should contain, which should be:

Step 2. Installing Kubernetes on our Ubuntu system

At this point we are going to start with the configuration of Kubernetes itself, so we must download and install the packages securely. To do this, the "apt" command is used again, adding the use of certificates.

Step 2. We ensure the download and installation of the packages securely

For the correct operation of Kubernetes, you must create a directory in which the authenticity of the Kubernetes packages will be verified.

At this point you must search for the public key and store it in the folder just created. In this way, Kubernetes packages will be validated to prevent us from being sold a dummy and make sure all packages are legitimate.

The Kubernetes download source is added.

Let's update the "apt" package index to see new items by running the "sudo apt-get update" command again.

Next, you must install the kubelet, kubeadm and kubectl packages by running the "apt install" command with the different Kubernetes versions.

For information purposes, let's explain what each of the kubelet, kubeadm and kubectl packages is for.

  • Kubelet: It is the service that runs on all nodes belonging to the Kubernetes cluster and is responsible for running PODS and containers.

  • Kubeadm: It is used to create the Kubernetes cluster.

  • Kubectl: It is used for the day-to-day operation of the Kubernetes cluster.

The command to run is the following, although there may be variations due to version changes:

NOTE: If it fails, you may need to add the command to include “–allow-downgrades”.

Step 2. We launch the installation of the Kubernetes packages on Ubuntu

The next step is to deploy Docker to serve Kubernetes. Docker will be the platform selected for creating the containers used by Kubernetes, this will allow us to create, distribute and run applications inside containers easily.

The reason containers are used instead of virtual machines is because they offer us a much lighter, portable and elastic environment, thus guaranteeing better performance in their different configurations.

For the installation we use the command “sudo apt install docker.io” which installs the Docker package.

Step 2. We install Docker to serve Kubernetes

The next step is the configuration of “Containerd” on all cluster nodes to ensure compatibility with Kubernetes.

To do this, the first thing to do is create a folder for the configuration file.

Once this is done, you must create a default configuration file for containerd and save it with the name “config.toml”.

After running these commands, you must modify the file "config.toml" to locate the entry that sets «SystemdCgroup = false" and change its value to «SystemdCgroup = true".

To finish this part you must restart the "contenedord" and "kubelet" services so that the configuration is reread and the changes are saved.

The normal thing is to want to start Kubernetes and therefore the Kubelet service every time the machine starts, so you must run the following command:

Step 2. We prepare the system for the use of Containered

The next step is start the Kubernetes cluster on the master node, so that when a Kubernetes control plane is started using kubeadm, different components will be deployed to manage and orchestrate the cluster.

The following command will download the component images (kube-apiserver, kube-controller-manager, kube-scheduler, etcd, kube-proxy).

We initialize the master node by passing "--pod-network-cidr" with the range of IP addresses reserved for the POD network.

Step 2. We start the Kubernetes cluster

At this point we are going to configure kubectl, which is the tool used to manage the Kubernetes cluster. To do this, you must start by creating the .kube directory in HOME and copying the cluster management configuration.

After this you must change the ownership of the file of the configuration that has been copied in order to give the user permission to use the configuration file.

Next we are going to configure both kubectl and Calico, which will be necessary for the operation of our Kubernetes service. To do this, it will be necessary to run the following commands on the master node so that the Calico operator is deployed.

Step 2. We configure Kubectl and Calico on our Ubuntu

The next step to take is to download the custom resource file for Calico, which contains different configurations necessary for using this service.

Step 2. We download the Calico resources and configure the CIDR of our Kubernetes cluster

At this point you must modify the CIDR in the "custom-resources.yaml" configuration file so that the resources match the POD network that will be provisioned in our case.

At this point kubectl is told to read the contents of the "custom-resources.yaml" file and to create the resources defined in that file, for which the following command must be run:

Step 2. We configure the CIDR of our Kubernetes cluster

With this, everything should already be configured within our master, so we move on to configure the workers.

Step 3. Add workers to the Kubernetes cluster

Now that the master node of our Kubernetes cluster is configured, it is time to add the worker nodes to the cluster, which will be the ones doing the actual work, leaving the master the task of coordinating.

When the Kubeadm of the master node is started, a token will be provided that will be used to add those worker nodes, which will be added using the "kubeadm join" command.

Where:

  • <MASTER_NODE_IP>: IP address of the master node of the Kubernetes cluster.

  • <API_SERVER_PORT>: Communication port, usually "6443".

  • <TOKEN>: We pass the validation token.

  • <CERTIFICATE_HASH>: We pass the HASH of the token in order to make the mathematical checks.

With that we would have already added the workers to the Kubernetes structure and can start operating the platform.

NOTE: If you encounter any problem during this procedure, you can consult the Kubernetes installation help

Conclusions:

As you can see, set up a Kubernetes environment in Plenit it is very easy to do by following the steps we have described.

In this case we have seen how to deploy the Kubernetes service on our GNU/Linux servers, Ubuntu 22.04 (the latest version available as of this date) but the same procedure can be used for other versions with slight changes.

Thanks for joining us!

Last updated

Was this helpful?