Kubernetes is a free and open source container management system that provides a platform for automating the deployment, scaling, and operations of application containers across groups of host computers.
With Kubernetes, they can freely leverage on-premises, public, and hybrid cloud infrastructure to run their organization's deployment tasks.
Kubernetes installation on Ubuntu and derivatives
For a practical installation, we are going to use a two node cluster that we will form in this article will consist of a master node and a slave node.
Both nodes need to have Kubernetes installed on them. The first thing we are going to do is install docker on both of them, for this we just need to execute the following command on them:
sudo apt install docker.io
To verify that docker is installed, you can run the following command on both nodes:
docker --version
Now let's proceed to enable docker on both nodes:
sudo systemctl enable docker
Now the next step is to add the Kubernetes key to both nodes, we do this with the following command:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
The next step is to add the following repository to both systems:
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
The last step in the installation process is to install Kubeadm on both nodes via the following command:
sudo apt install kubeadm
They can check the Kubeadm version number and also verify the installation via the following command:
kubeadm version
Kubernetes deployment
Now to implement the Kubernetes deployment in the system we must disable swap memory (if it is running) in both nodes
They should disable swap memory on both nodesas Kubernetes does not work properly on a system that uses swap memory.
To do this, just run:
sudo swapoff -a
Now the next step is run the following command on the master node to give it a unique hostname:
sudo hostnamectl set-hostname master-node
While for the slave node we must type:
sudo hostnamectl set-hostname slave-node
Done this now vLet's proceed to initialize the master node with the following command:
sudo kubeadm init --pod-network-cidr = 10.244.0.0/16
The process may take a minute or more depending on your Internet connection. The output of this command is very important so you should write down the information in the output, as it contains the ip, token and others.
To start using your cluster, they need to run the following as a regular user:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Now they can join any number of machines by running the following on each node as root users:
kubeadm join tuip --token tutoken --discovery-token-ca-cert-hash sha256:tuhash
Where they will replace the information of tutoken, tuip and your hash with the information that was said a few moments ago that they will write down.
Getting the list of nodes
You will see that the status of the master node is not ready yet. This is because no pod has yet been deployed on the master node and therefore the Container Network Interface is empty.
To see the list we only have to execute:
kubectl get nodes
Deploying a pod network through the master node
A pod network is a means of communication between the nodes of a network. In this tutorial, we are implementing a Flannel pod network in our cluster via the following command:
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
To know the status of the network, just type:
kubectl get pods --all-namespaces sudo kubectl get nodes
Once this is done, now it is time to add the slave node to the network to form a cluster, in the same way they must complement the information as in the master node.
sudo kubeadm join tuip --token tutoken --discovery-token-ca-cert-hash sha256:tuhash
Now when you run the following command on the master node, it will confirm that two nodes, the master node and the server nodes are running on your system.
sudo kubectl get nodes
This shows that the two-node cluster is now up and running through the Kubernetes container management system.