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.
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
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
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
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
Then, you can install it. Also, you have to install docker:
:~# yum install kubeadm docker
Then, start and enable both docker
and kubectl
services:
:~# systemctl enable docker :~# systemctl start docker :~# systemctl enable kubelet :~# systemctl start kubelet
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.
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
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"
Now, re-run the command to show all the pods.
:~# kubectl get pods --all-namespaces
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
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
Next, install it:
:~# yum install kubeadm docker
Then, enable and start the services:
:~# systemctl enable docker :~# systemctl start docker :~# systemctl enable kubelet :~# systemctl start kubelet
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
Thanks, well explained, Found it useful