How to install Kubernetes (K8S)

How to install Kubernetes (K8S)
Written by Erik LianApril 18, 2020
3 min read
DevOps
18 VIEWS 3 LIKES 0 DISLIKES SHARE
3 LIKES 0 DISLIKES 18 VIEWS SHARE
Erik Lian

Cloud Security Engineer

This lesson covers how to install Kubernetes on a CentOS 7 server. **Note Commands 1-10 need to be run on all

The first thing that we are going to do is use SSH to log in to all machines. Once we have logged in, we need to elevate privileges using sudo.

  sudo su 

Disable SELinux

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

Enable the br_netfilter module for cluster communication.

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

Disable swap to prevent memory allocation issues.

swapoff -a
vim /etc/fstab.orig -> Comment out the swap line

Install the Docker prerequisites.

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

Add the Docker repo and install Docker.

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

Configure the Docker Cgroup Driver to systemd, enable and start Docker

sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service 
systemctl daemon-reload
systemctl enable docker --now 
systemctl status docker
docker info | grep -i cgroup

Add the Kubernetes repo.

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=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
     https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

Install Kubernetes.

yum install -y kubelet kubeadm kubectl

Enable Kubernetes. The kubelet service will not start until you run kubeadm init.

systemctl enable kubelet

*Note: Complete the following section on the MASTER ONLY!

Initialize the cluster using the IP range for Flannel.

kubeadm init --pod-network-cidr=10.244.0.0/16

Copy the kubeadmin join command.

Exit sudo and run the following:

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

Deploy Flannel.

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

Check the cluster state.

kubectl get pods --all-namespaces

*Note: Complete the following steps on the NODES ONLY!

Run the join command that you copied earlier (this command needs to be run as sudo), then check your nodes from the master.

kubectl get nodes


blogpostThanks!

k8s
kubernetes
centos
18 VIEWS 3 LIKES 0 DISLIKES SHARE
3 LIKES 0 DISLIKES 18 VIEWS SHARE
Was this blog helpful?
You must be Logged in to comment
Code Block
Erik Lian
Cloud Security Engineer
+1 more
2 Blog Posts
3 Discussion Threads
Trending Technologies
15
Software39
DevOps45
Frontend Development24
Backend Development20
Server Administration17
Linux Administration24
Data Center24
Sentry24
Terraform21
Ansible46
Docker28
Penetration Testing14
Kubernetes17
NGINX19
JenkinsX17
Techiio

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

facebooklinkdeintwitter

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Copyright techiio.com @2020 Kolkata, India
made with by Abhishek & Priyanka Jalan
Copyright techiio.com @2020
made with by Abhishek & Priyanka Jalan