How to install a Kubernetes cluster on CentOS 7 Print

  • home lab Kubernetes on linux, kubernetes cluster on mac book os, kubernetes on virtualbox
  • 2

Introduction:

This document will guide you that how you can install kubernetes cluster on centos 7. You can use physical server or virtual machines.

 

Three virtual machines with the latest Centos 7.X has been installed so far which are able to access Internet and must be able to ping each other.

 

Virtual machines names and IP:

 

192.168.2.222  centosmaster

192.168.2.221  centosworkerone

192.168.2.220  centosworkertwo

 

1.Pre-Install consideration.   [ Perform it on all 3 servers]    

Can you access it as root?

Are these vms can resolve & ping each other IPs. ( No DNS server no problem edit your               /etc/host file)

Yum works?

Firewall off?

Do you have unique hostname, MAC address, and product_uuid for every node? See here for more details.

Certain ports are open on your machines. See here for more details.

Is swap off (disabled) on all your three servers? [Follow step 3]

 Make sure you have a “Yes” answer to all shown above questions.

 

 2. Dealing with SELINUX by disabling it. [Perform it on all 3 servers]

setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

 

3. Disable swap by commenting the swap partition line in /etc/fstab. [Perform it on all 3 servers]

 

You can comment your swap entry like this in /etc/fstab. By doing this you will make sure that it will not enable by itself during next boot.

#/dev/mapper/centos-swap swap                    swap defaults 0 0

 

4.  Enable br_netfilter  [Perform it on all 3 servers]

modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

 

5. Now you need to install Docker-ce  [ Perform it on all 3 servers]    

Install the Docker-ce repo and dependencies with the following commands.

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum install -y docker-ce

 

5. Install  Kubernetes  [ Perform it on all 3 servers]    

Create a repository entry for yum.

copy/past shown below text into your terminal.

 

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

[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

exclude=kube*

EOF

 

yum install -y kubelet kubeadm kubectl

After the installation reboot all three servers.

 

6. Cgroup changes [ Perform it on all 3 servers]  

Make sure  that both Docker-ce and Kubernetes belong to the same control group (cgroup). By default, Docker should already belong to cgroupfs (you can check this with the command docker info | grep -i cgroup). To add Kubernetes to this, issue the command:

sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

Restart the systemd daemon and the kubelet service with the commands:

systemctl daemon-reload
systemctl restart kubelet

 

7. Initialize the Kubernetes cluster [Only Master Node]

kubeadm init --ignore-preflight-errors=SystemVerification --apiserver-advertise-address=192.168.2.222 --pod-network-cidr=192.168.2.0/24

This can take upto 5 minutes.

 

8. Setup nodes By running show below command: [Run on centosworkerone and cetosworkertwo]

In the output from command in step 7 on master node you will get token and ca cert hash.

kubeadm join 192.168.2.222:6443 --token ts7bsz.XXXXXXXXXXXXX --discovery-token-ca-cert-hash sha256:XXXXXXXX

 

9. Configuration of Kubernetes [  Perform it on all cetosmaster]

Issue the following three commands (to create a new .kube configuration directory, copy the necessary configuration file, and give the file the proper ownership):

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

 

10. Deploy flannel network

Now we must deploy the flannel network to the cluster with the command:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

 

Checking your nodes

kubectl get nodes

 

Troubleshooting:

(i) to ignore all system errors you can initialise the cluster like this.

kubeadm init --ignore-preflight-errors=SystemVerification--apiserver-advertise-address=192.168.2.222 --pod-network-cidr=192.168.2.0/24

 

 

(ii) Very helpful command to check the logs related with the service:  - 'journalctl -xeu kubelet'

 

 

 

 

 

 


Was this answer helpful?

« Back