Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Last active May 4, 2022 19:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save mjhea0/b08ed217144ad307085a05450f3ac6be to your computer and use it in GitHub Desktop.
Save mjhea0/b08ed217144ad307085a05450f3ac6be to your computer and use it in GitHub Desktop.

Install a 3-Node Kubernetes Cluster on Centos 7

This setup uses 3 machines:

  1. Centos7
  2. 100GB HDD
  3. 32 GB RAM
  4. 8 CPU

All Machines

The following commands need to be run on all machines.

Configure /etc/hosts

Update /etc/hosts so that each machine can ping one other using the hostname:

192.168.16.179 kubemaster
192.168.16.168 kube2
192.168.16.182 kube3

Be sure to update the IP addresses!

Disable SELinux

This allows the Kubernetes cluster to communicate.

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

Disable Swap

kubernetes/kubernetes#53533

$ swapoff -a

Install Docker

$ 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

Install Kubernetes

Add the repository info for yum in /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

Install Kubernetes:

$ yum install -y kubelet kubeadm kubectl

Add Kubernetes to the cgroupfs group:

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

Restart systemd daemon and kubelet:

$ systemctl daemon-reload
$ systemctl restart kubelet
$ systemctl enable kubelet.service
$ systemctl start docker.service

Master Setup

The following commands need to be run on the master.

Init Kubernetes

Initialize the Kubernetes cluster, making sure to update apiserver-advertise-address:

$ kubeadm init --apiserver-advertise-address=192.168.16.179 --pod-network-cidr=192.168.1.0/16

This could take a few minutes to complete. Once done, take note of the token and discovery-token.

Set up the Kubernetes Config:

$ 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 network to the cluster:

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

Worker(s) Setup

The following commands need to be run on the worker machines.

Init Kubernetes

Join the worker to the cluster, making sure to replace TOKEN and DISCOVERY_TOKEN:

$ kubeadm join 192.168.1.99:6443 --token TOKEN --discovery-token-ca-cert-hash DISCOVERY_TOKEN

Set up the Kubernetes Config:

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

Master

Back on the master, let's verify the Kubernetes install.

Sanity Check

Are the nodes reachable?

$ kubectl get nodes

NAME                                   STATUS    ROLES     AGE       VERSION
server-f2-base-node-2a0h8a.novalocal   Ready     <none>    5m        v1.11.1
server-f2-base-node-jqbii9.novalocal   Ready     <none>    5m        v1.11.1
server-f2-base-node-jr3695.novalocal   Ready     master    19m       v1.11.1

Configure the dashboard:

$ kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
$ kubectl describe services kubernetes-dashboard --namespace=kube-system
$ kubectl proxy --address 0.0.0.0 --port 8001 --accept-hosts='^*$'

Test at http://192.168.16.179:8001/healthz/ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment