Skip to content

On-Premises Multi Master Kubernetes Cluster Deployment with HAProxy via Ansible and kubeadm

Notifications You must be signed in to change notification settings

kayvansol/Kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alt text

This repository is for deploying kubernetes on-permises cluster (bare-metal servers).

The kubernetes folder contains the files for preparing server to install kubernetes cluster or join to the cluster.

Please run the following script on all servers :

 sudo ansible servers -m ping -i inventory.ini -u root
 
 sudo ansible-playbook -i inventory.ini Kubernetes/ServerPrepare.yml -u root

Kubernetes Cluster :

The control-plane nodes addresses are :

192.168.56.120
192.168.56.121
192.168.56.122

The worker nodes addresses are :

192.168.56.123
192.168.56.124

The vms hosted on virtualbox are like the below schema :

alt text

HAProxy server (Load Balancer for kube apiserver) address is :

192.168.56.118 

haproxy.cfg :

stats enable
(frontend bind to 192.168.56.118:6443)
(backend  bind to 192.168.56.120:6443  192.168.56.121:6443  192.168.56.122:6443)

For starting a Kubernetes cluster, follow the below lines :

Run below scripts only on 192.168.56.120 :

sudo kubeadm init  --control-plane-endpoint="192.168.56.118:6443"   
      --upload-certs  --apiserver-advertise-address=192.168.56.120
      --pod-network-cidr=192.168.0.0/16  
      --cri-socket=unix:///var/run/cri-dockerd.sock  
      --ignore-preflight-errors=all 

And below code for all nodes :

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

Install Calico network policy for on-premises deployments, 50 nodes or less :

curl https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/calico.yaml -O

kubectl apply -f calico.yaml

and run the below on other servers to join to the cluster :

On control-plane (e.g. 192.168.56.122) :

kubeadm join 192.168.56.118:6443 --token c4c6wt.2rzubblajmxx7wf1 \
     --discovery-token-ca-cert-hash sha256:91877d933445148c650e5fa11acca05d455fe1e9e53cd33f8497ad06a2126142 \
     --control-plane --certificate-key 2e8c3d0a1f2d4aec3e4ccb09a0dd6f43756344269c0b414cdd83c0ef02c0293d \
     --apiserver-advertise-address=192.168.56.122 
     --cri-socket=unix:///var/run/cri-dockerd.sock 
     --ignore-preflight-errors=all

On worker nodes :

kubeadm join 192.168.56.118:6443 --token  c4c6wt.2rzubblajmxx7wf1 \
     --discovery-token-ca-cert-hash sha256:91877d933445148c650e5fa11acca05d455fe1e9e53cd33f8497ad06a2126142 \
     --cri-socket=unix:///var/run/cri-dockerd.sock 
     --ignore-preflight-errors=all

and at final step enjoy from your cluster :

kubectl get nodes -o wide

kubectl get pod -A

alt text

alt text

HAProxy Stats :

alt text

haproxy.cfg :

alt text

About

On-Premises Multi Master Kubernetes Cluster Deployment with HAProxy via Ansible and kubeadm

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published