Three Nodes Kubernetes Installation

MKM
thesystemadmin
Published in
2 min readApr 11, 2020

--

This cluster is installed on Centos 7 operating systems. Nodes should be minimum 2GB memory, 2 CPUs. We’ll have one master node, two worker nodes at the end of the installation.

  1. Disable swap in all nodes
swapoff -aRemove swap entry from /etc/fstab to disable after reboots.

2. Install docker on all nodes.

yum -y install docker
systemctl enable docker
systemctl start docker

3. All hosts file should be same and include all nodes hostnames. Configure in all nodes.

192.168.1.60 kubemaster01
192.168.1.61 kubeworker01
192.168.1.62 kubeworker02

4. Set these kernel parameters in all nodes.

cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p

5. Configure repository in all nodes.

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

6. Install packages and enable kubelet agent in all nodes.

yum install -y kubelet kubeadm kubectl — disableexcludes=kubernetes
systemctl enable kubelet
systemctl start kubelet

7. Initialize kubernetes master. This command is for weave overlay network. There should be — pod-network-cidr parameter for other networks. Run at master node.

For weave;kubeadm initFor others(flannel, calico...etc.), cidr example;kubeadm init --pod-network-cidr=10.244.0.0/16

There will an output like that;

......To start using your cluster, you need to run the following as a regular user:

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

kubeadm join 192.168.1.10:6443 --token d1dyaj.31zxywbg93s1ywjy --discovery-token-ca-cert-hash sha256:71a91721595fde66b6382908d801266602a14de8e16bdb7a3cede21509427009

8. Run these commands to manage and work on the cluster as a regular user. “kubeadm join…” command will be used for to add worker nodes. Write it down.

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

9. Check pods in cluster.

kubectl get pods --all-namespaces

There should be core-dns pods in pending state.

10. Install one of overlay network.

Weavekubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"Calicokubectl apply -f https://docs.projectcalico.org/v3.11/manifests/calico.yamlFlannelkubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml...

After one of these commands core-dns pods should pass to ready state.

11. Add worker nodes. Nodes can be added with “kubeadm join…” command which was given in init output.

kubeadm join 192.168.1.10:6443 — token d1dyaj.31zxywbg93s1ywjy — discovery-token-ca-cert-hash sha256:71a91721595fde66b6382908d801266602a14de8e16bdb7a3cede21509427009

Now all nodes should be ready when it is checked from master node. If you forget to write down join command, you can get it again with this;

kubeadm token create — print-join-command

--

--