Three Nodes Kubernetes Installation on Centos 7
- Disable swap in all nodes
swapoff -a
Remove swap entry from /etc/fstab.
- Min: 2GB memory, 2 CPUs per node.
- Install docker on all nodes.
yum -y install docker
systemctl enable docker
systemctl start docker
- All hosts file should be same and include all nodes hostnames.
192.168.1.60 kubemaster01
192.168.1.61 kubeworker01
192.168.1.62 kubeworker02
- Set these kernel parameters on 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
Configure Repository
Do this on 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
Install Kubernetes Packages
Install packages on all nodes.
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet
systemctl start kubelet
Initialize Kubernetes Master
This command is for weave overlay network. There should be — pod-network-cidr parameter for other networks.
kubeadm init
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
Run these commands in the terminal 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
Check pods in cluster.
kubectl get pods --all-namespaces
There should be core-dns pods in pending state. A pod network should be installed to make them ready.
export kubever=$(kubectl version | base64 | tr -d '\n')
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever
Check pods again and all pods should be ready.
Adding 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.
kubectl get nodes
If you forget to write down join command, you can get it again with this;
kubeadm token create — print-join-command