Installing a 3-Master Node Kubernetes Cluster Behind a Load Balancer
Introduction
Kubernetes has become the go-to solution for container orchestration, offering robust features for managing containerized applications. In production environments, high availability is crucial. Setting up a Kubernetes cluster with multiple master nodes behind a load balancer ensures that the control plane remains available, even if one or more master nodes fail. This article will guide you through the generic process of setting up a 3-master node Kubernetes cluster behind a load balancer.
Prerequisites
Before proceeding, ensure you have the following:
- Three servers for the master nodes, each with a unique hostname, static IP, and sufficient resources (CPU, memory, and disk space).
- One or more additional servers for worker nodes (optional, depending on your deployment needs).
- A load balancer (hardware or software) to distribute traffic to the master nodes.
- SSH access to all servers.
- Basic familiarity with Kubernetes, Docker, and Linux system administration.
Step 1: Setting Up the Load Balancer
- Configure your load balancer to distribute incoming Kubernetes API requests to the three master nodes.
- Set up a health check for the Kubernetes API server port (default 6443) to ensure traffic is only sent to healthy nodes.
- Record the load balancer IP or DNS name, as it will be used to access the Kubernetes API.
Step 2: Installing Kubernetes Components
Perform these steps on each master node.
- Install Docker as the container runtime:
sudo apt-get update sudo apt-get install docker.io
- Install kubeadm, kubelet, and kubectl:
sudo apt-get update sudo apt-get install -y apt-transport-https curl curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
- Disable Swap:
sudo swapoff -a
Step 3: Initializing the First Master Node
Choose one master node as the initial control plane node.
- Initialize the Kubernetes Cluster using
kubeadm:
sudo kubeadm init --control-plane-endpoint "LOAD_BALANCER_IP:6443" --upload-certs
- Set up kubectl access:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Save the join command output by
kubeadm init. You’ll need it to join other master and worker nodes to the cluster.
Step 4: Joining Additional Master Nodes
On the other two master nodes, use the join command you saved earlier. It should look like this:sudo kubeadm join LOAD_BALANCER_IP:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash> --control-plane --certificate-key <certificate-key>
Step 5: Joining Worker Nodes (Optional)
If you have worker nodes, join them to the cluster using the join command without the --control-plane flag.
If you only wanted to use these 3 nodes as worker, remove the default control plane taints on each nodes.
Step 6: Deploying a Pod Network
Choose a network solution like Calico, Flannel, or Weave, and apply it using kubectl. For example, with Calico:kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Conclusion
Your high-availability Kubernetes cluster with 3 master nodes is now set up behind a load balancer. This configuration ensures that your Kubernetes control plane remains accessible and resilient to individual node failures. Remember to regularly update and maintain your cluster to keep it secure and efficient.



Post Comment