-We have now set up the nodes required to set up a Kubernetes cluster.
We have set up a master node and two worker nodes,
node 01 and node 02.
Let us now proceed to the kubeadm documentation page
to install a Kubernetes cluster.
We will start with the prerequisites.
We must have a supported operating system
like for example, Ubuntu 16.04 or higher, which we already do.
That's what we did in the previous demo.
We have some hardware requirements
to have at least 2 GB of RAM, two CPUs, and network connectivity between the VMs
which we have already taken care of in the previous video.
Another thing is to make sure that our firewall
and network security settings are in place,
otherwise, the nodes will run into connectivity issues.
For this, we must let iptables see bridged traffic.
We must first make sure the br_netfilter module is loaded before the step.
We can do that by running the command lsmod grep br_netfilter.
We see that it's not loaded as there is no result
so we run the modprobe command to load the kernel module.
We now execute that on all the nodes.
[pause]
Once that is done,
we run this set of commands to create the new kernel parameters.
We then do that on all the nodes.
[pause]
The next step is to install container runtime on the nodes.
We will be using Docker in this example.
For this, we use the documentation link and click on Docker.
We will use these commands to install the latest stable version of Docker.
These need root privileges.
I will switch to sudo to make the next steps easier
by running the sudo -i command.
I will now paste the command that I copied to set up the software repositories.
We will then proceed to execute the same on all the three machines.
[pause]
Okay, that's done, the next step is to install Docker's official GPG keys.
We will do that also on all the machines.
[pause]
The next step is to add the Docker apt repository.
We will then do the same on all the systems.
[pause]
The next step is to install the Docker runtime.
We run the commands
to install the latest stable version of Docker as of this recording.
If the version of Docker that's shown here has changed as you're watching this,
then feel free to follow the latest version of documentation,
to install the latest version of Docker.
Run that on all the nodes.
This may take a few minutes so wait for that to finish.
[silence]
The next step is to set up the Docker daemon.
For this we create a daemon.json file
and then create a directory for the Docker service.
[pause]
We then run the systemctl daemon reload and restart Docker command
to load and start the Docker service.
[silence]
To verify Docker is installed,
run the systemctl status docker.service command and verify that it is running.
Confirm that that's the case on all the three nodes.
We now go back to the documentation page
to proceed with the installation of Kubernetes components using kubeadm.
The next step is to install the Kubernetes related packages
such as the kubeadm, kubelet, and kubectl on all the nodes.
The kubeadm tool is used to bootstrap the cluster.
The kubelet is the process that's responsible
to manage pods and containers on the nodes
and the kubectl utility is the Kubernetes Command Line Tool.
For this,
run the commands to update repository and install the required packages.
[silence]
Run these on all the nodes and wait for it to finish.
[pause]
The next section about configuring c group driver
is not applicable when using Docker,
as kubeadm will automatically detect the group driver for the kubelet.
If you're not using Docker,
then we must follow this step to specify the c group driver.
We can skip this for now.
The next step is to configure the kubeadm cluster by clicking on this link.
This takes us to the cluster creation process using kubeadm.
The first phase is to initialize control-plane node.
The first step in that is only applicable
if we are deploying a highly available cluster.
In this demo, we are not.
We just have a single master node so we will skip that for now.
The next step is to choose a pod network addon.
When we do that,
decide what network IP address range we are going to use for the pod.
There are multiple network options available for networking
between pods in a Kubernetes cluster.
If you click on this link,
which takes you down in that page to the pod networks section,
you will see different options for configuring a network
such as Calico, Cilium, Contiv, Kube-router, Weave, et cetera.
In this case, we will make use of Weave
and we can choose a network range
that does not conflict with the network of the nodes.
Remember that we configured the nodes to be in the 192.168.56 network,
we will use a network cidr that's different from that range.
For pods we will use 10.244.0.0/16 network.
The third step can be ignored as well,
since we are using Docker as our container runtime,
but in case you're using a different one, you may use this option to specify that.
The fourth step is what we will configure.
We must specify the Kubernetes API servers IP address
as the API server advertise address.
This is so that the API server
listens on the correct static IP address we have set on the master node.
Which will make the API server accessible to the worker nodes
on any other clients on that IP address.
Once we have decided the values for the options,
we can proceed with initializing the cluster
using the kubeadm init command.
We will run this on the master node.
Remember this step must only be run on the master node
because that's where all the cluster components
have to be installed and initialized.
We copy and paste the kubeadm init command on the master node,
we will then pass in all the required parameters
such as the pod network cidr, which will be 10.244.0.0/16.
The API server advertise address
is going to be the static IP address of the master node,
which will be 192.168.56.2
which is the IP address of the master.
Now if you're not sure about the IP address of the master node,
we can double-check that.
I will for now command this command
so that it is not executed
and that I can later access it after I confirm the IP address.
I will then run the ifconfig command to confirm the IP address of the node.
I can confirm that it is the correct IP address.
I will now run the kubeadm init command.
It runs a set of preflight-test to make sure all prerequisitesare in place.
Let's give it some time to run.
The checks are complete and everything looks good.
It proceeds with the creation of security certificates
and installation of the various components.
We give it some more time for the installation to finish.
Now, the installation is complete.
We will now perform the post-installation tasks.
As the output states,
to start the cluster, you need to run the following as a regular user.
We've been running things as the root user.
We will run the logout command to log out and become the regular user.
Once we are a regular user,
we must create a directory under the user's home directory
and copy the admin.con file.
The admin.con file has the necessary information credentials
required to access the Kubernetes cluster using the kubectl command line utility.
It must be placed in the user's home directory under the .kube directory.
We run this command to create the .kube directory
and copy the admin.con file into it and also set the right ownership on it.
The next step is to deploy a pod network to the cluster.
Earlier, we decided that we will use Weave as our pod network solution.
We need to do that.
After the pod network solution is set up,
we will have the worker nodes join the cluster using the command given here.
Keep a node of the command
that will be used to join the worker node to the cluster.
I'm just going to copy and echo the command to my screen terminal
so that it is available in the terminal history and I can retrieve it later,
or you may just copy it to an external text editor.
Let's run the kubectl get nodes command to check the status of the cluster now.
We see that the cluster consists of the Kubemaster node only
and the status is not ready as of now.
The version is 1.18.3.
The reason it's not ready is because we do not have a pod network solution.
For this, we go back to the documentation side and go to the pod network section.
Select Weave and copy the command to install Weave.
Place it on the master node and execute it.
We see that the port network solution is been installed
and all the required components are created.
It creates a service account, roles, role bindings, daemonsets, et cetera.
We discussed a lot about each of these
in the certified Kubernetes administrator course.
We have a section just for networking
where we go from the absolute basics of network
all the way to how a Weave solution works.
Check that out if you have time.
For now, let's proceed with adding the worker nodes to the cluster.
For this, we will use the command we saved earlier.
We will copy it and run it on both the worker nodes.
[pause]
We see that the node has successfully joined the cluster.
Now, we run the kubectl get nodes command on the master node
and we will check the status.
It may take a few minutes for the worker node to be in a ready state.
Let's monitor that.
[silence]
We now see that they are in a ready state.
Our Kubernetes cluster is now ready.
We can now test by creating some objects.
Let's create a pod using the kubectl, run NGINX command
and specify the NGINX image.
[silence]
You see it's created a pod by running the kubectl get pods command.
The pods are still being created so we wait for a few minutes.
We will see that it's now in a running state.
We will now delete it using the kubectl deleting pod command.
That's it for this demo.
Thank you for watching.