2 C
Texas
angeloma
Senior Writer and partner

How to install Kubernetes on CentOS 7?

Kubernetes (k8s) is a technology for the orchestration of Docker containers. If you’ve heard of or used Docker, you probably also know about Kubernetes. In this tutorial, I will show you how to install Kubernetes on CentOS 7.

In short, Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. The most important factor that sets Kubernetes apart from other cloud computing solutions is that it was built to work with Docker. That’s why it’s the most used tool to deploy Dockers applications.

Now, I will show you how to install it on CentOS 7.

0. Prerequisites

The installation is not as complicated as it seems, however, you should have a little knowledge about Terminal and commands. Also required is a computer that will serve as a server and another that will serve as a node. The central idea is to add them in a cluster.

- Advertisement -

Both computers run CentOS 7 and it’s on a local network. Let’s start.

1. Install Kubernetes on the server

As I said before the idea is to make a cluster, for it, first we must configure the server where you will run Kubernetes. First, you have to disable SELinux and apply various rules in the Firewall for everything to work well. Note: all commands must be run as root user.

:~# hostnamectl set-hostname osradar
:~# exec bash
:~# setenforce 0
:~# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

1.- Preparing the enviroment
1.- Preparing the environment

Next, set the firewall rules:

:~# firewall-cmd --permanent --add-port=6443/tcp
:~# firewall-cmd --permanent --add-port=2379-2380/tcp
:~# firewall-cmd --permanent --add-port=10250/tcp
:~# firewall-cmd --permanent --add-port=10251/tcp
:~# firewall-cmd --permanent --add-port=10252/tcp
:~# firewall-cmd --permanent --add-port=10255/tcp
:~# firewall-cmd --reload
:~# modprobe br_netfilter
:~# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

2.- Setting Firewall rules
2.- Setting Firewall rules

In case you don’t have a DNS server configured. Edit the file /etc/hosts and add the information of your node and server.

:~# nano /etc/hosts

And add the following:

192.168.1.8 osradar
192.168.1.9 node1

2.- Editing hosts file
3.- Editing hosts file

Of course, replace the configuration with yours depending on the IP addresses and hostname chosen.

2. Install Kubernetes

In order to install Kubernetes on CentOS 7, you must add its repository. With this, the installation will be quick and easy. Run

:~# nano /etc/yum.repos.d/kubernetes.repo

And put the following:

[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

4.- Adding the Kubernetes repository
4.- Adding the Kubernetes repository

Then, you can install it. Also, you have to install docker:

:~# yum install kubeadm docker

5.- Install Kubernetes
5.- Install Kubernetes

Then, start and enable both docker and kubectl services:

:~# systemctl enable docker
:~# systemctl start docker
:~# systemctl enable kubelet
:~# systemctl start kubelet

6.- Enabling the required services
6.- Enabling the required services

3. Initialize Kubernetes in CentOS 7

Now you can start Kubernetes with the next command:

.~# kubeadm init

If you see something like this, everything is OK.

7.- Kubernetes is running!
7.- Kubernetes is running!

As you can see from the image, you must now execute these commands:

:~# mkdir -p $HOME/.kube
:~# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
:~# chown $(id -u):$(id -g) $HOME/.kube/config

8.- Creating the cluster folders
8.- Creating the cluster folders

The next step is to check the status of the clusters and pods

:~# kubectl get nodes
:~# kubectl get pods --all-namespaces

To ensure that there is communication between the nodes of the cluster, you have to run the following:

:~# export kubever=$(kubectl version | base64 | tr -d '\n')
:~# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"

9.- Configuring Kubernetes
9.- Configuring Kubernetes

Now, re-run the command to show all the pods.

:~# kubectl get pods --all-namespaces

10.- All pods running
10.- All pods running

Everything is going OK.

4.- Working on the node or nodes

In this step, you must work on the number of nodes you want to configure. In this case, it will be only one, but remember that they can be more.

At each node, run the following. First, change the hostname and set the firewall rules:

:~# setenforce 0
:~# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
:~# firewall-cmd --permanent --add-port=10250/tcp
:~# firewall-cmd --permanent --add-port=10255/tcp
:~# firewall-cmd --permanent --add-port=30000-32767/tcp
:~# firewall-cmd --permanent --add-port=6783/tcp
:~# firewall-cmd  --reload

11.- Setting Firewall rules on Node1
11.- Setting Firewall rules on Node1

Next, install Kubernetes.

:~# cat <<EOF > /etc/yum.repos.d/kubernetes.repo

And add the following:

> [kubernetes]
> name=Kubernetes
> baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
> enabled=1
> gpgcheck=1
> repo_gpgcheck=1
> gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
>         https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
> EOF

12.- adding the kubernetes repository
12.- adding the kubernetes repository

Next, install it:

:~# yum install kubeadm docker

13.- Installing Docker and kubernetes on Node1
13.- Installing Docker and kubernetes on Node1

Then, enable and start the services:

:~# systemctl enable docker
:~# systemctl start docker
:~# systemctl enable kubelet
:~# systemctl start kubelet

14.- Enabling the required services
14.- Enabling the required services

Finally, join to the master node.

:~# kubeadm join --token xnxlx4.k6qupcvb9g7tq2ti 192.168.1.8

Conclusion

As you can see, the process of installing Kubernetes on CentOS 7 is simple and we are talking about a very powerful tool in the Linux world.

We want to know about you, have you used Kubernetes? do you use Docker?

Please spread this article on your social networks

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article