K8S-Course 02: Installing the kubernetes Lab – part 2

Tram Ho


Today I will continue to guide you through the complete installation of a kubernetes cluster using kubespray! image.png

I re-introduce the k8s model that I will guide you to install: image.png

The parameters of the VMs used for the installation are as follows:

Virtual machineRoleIPRAMCPUHDDNote
master1master192.168.10.11 (NAT)3GB2 cores30GBWill install more haproxy
worker1worker192.168.10.12 (NAT)4GB2 cores30GBWill install more rancher
worker2worker192.168.10.13 (NAT)4GB2 cores30GB + 30GBWill install more nfs-server
kubesprayinstallation server192.168.10 (NAT)2GB2 cores30GB

Review the work done

In part 1 , I guided you to install VMware Workstation and created 4 VMs according to the above planning.

In this article, I continue to guide the remaining work to complete the installation, including:

  • Configure the kubespray virtual machine to prepare for the installation of k8s
  • Parameter configuration for k8s installation + installation using kubespray
  • Install & configure kubectl (to communicate and manage the k8s cluster)
  • Install rancher (to VM worker1)

Now get your hands on it!

Detailed instructions

Configuration settings for VM kubespray

Install docker

Do a docker install with the following command:

Then configure so that your user (non-root) can run docker commands without sudo, then restart the session connecting to the server so that the user is updated:

You can logout/re-login the session to update the above permissions before continuing the operation.

As a result install docker and run docker command without sudo privileges:

Configuring the hosts file

Add the following lines to the /etc/hosts file:

Create kubespray installation directory

Create the directory containing the installation files:

Install kubernetes using kubespray

Download kubespray installer

Go to the installation directory and download Kubespray, note that you need to download the correct version you need. Here I want to install kubernetes version v1.20.7, I will need to download kuberpay release-2.16 version:

Now kubespray will be downloaded to your device at /home/sysadmin/kubernetes_installation/kubespray.

Update configuration file of kubespray

You need to create your own new inventory named viettq-cluster from kubespray’s template set:

Next comes the most important step – configure the hosts.yaml file in your inventory folder. This file is the file that defines how many nodes you will install k8s cluster, what is the name and IP of the nodes…

You need to edit the content of this file according to the hostname/IP of the nodes where you will install Kubernetes. According to the above planning, I have 1 master and 2 workers, according to which we need the following configuration file:

Next, if you want to change CNI (network plugin of K8S), edit the following config file:

Edit parameter:

Or you can use the command to update the network plugin configuration as follows (instead of manually editing as above):

So the preparation steps are ready, let’s proceed with the installation!

Install kubernetes cluster

We will perform the installation from within a kubespray docker container with the following command:

Please note that the prompt will now be “root@…” since we are inside the container.

Finally the command to install:

You will enter the password of the sysadmin user twice and wait for ansible to run the installation tasks on the nodes for you.

The finished result will be as follows:

Install and configure kubectl

Configure kubectl on master1

When installing the k8s cluster, the master node already has kubectl installed on the master node by default, so we just need to configure it without having to reinstall it.

Configure kubectl on master node as follows:

Then check the cluster’s node information:

That’s it, the installation is complete.

Install and configure kubectl on kubespray

Since the version of Kubernetes installed in this LAB series is v1.20.7 , I will also install kubectl with the same version:

Configure kubectl to connect to my K8S cluster :

Edit the config file, parameter “server: ” to “server: ” and save. Note “” is the IP of node master1, 6443 is the default port of kube-api-server.

Now check the connection with the command “kubect get nodes” to see if the connection is ok or not :

So we have installed and configured kubectl on kubespray node successfully .

Install rancher

According to planning we will install rancher on worker1 node. Connect SSH to woker1 and install rancher.

First we need to configure the sysadmin user to have permission to run docker commands without sudo :

Next, we install the rancher with the following command:

Now that the rancher container has finished running, we go to its web address at https://[ ip ]:[ https-port ] specifically .

Now you choose to change the new password to enter the new password and press OK to go to the main Rancher interface as follows.

Next, select Add Cluster -> Other Cluster -> Enter Cluster Name -> Select Create.

Next copy the bottom command line to run on K8S Master Node to install rancher-agent on K8S.

Wait a few minutes for the agent to be installed, then on the rancher you click on the newly created cluster name will display as follows:


Additional: When the Rancher interface says Controller Manager unhealthy, please perform the following steps on the Master nodes!

So here you have completed the installation of the kubernetes cluster lab system.

In the following lessons, we will both learn and practice about the concepts and resources of k8s such as nodes, pods.. on this lab system. Hope to receive everyone’s support by upvote and bookmark this article. Thank you!!

Share the news now

Source : Viblo