Adding Master Nodes To Achieve HA: One of the Best Practices for Using KubeKey
In this post, I will continue to demonstrate how to scale out your cluster, this time by adding master nodes to achieve high availability.
Join the DZone community and get the full member experience.Join For Free
As demonstrated in my last article, you can use KubeKey to easily scale in and out your cluster. Because I only had one master node in the example, the cluster did not feature high availability. In this post, I will continue to demonstrate how to scale out your cluster, this time by adding master nodes to achieve high availability.
The steps are listed as follows:
- Download KubeKey
- Use KubeKey to retrieve cluster information with a configuration file created automatically
- Add your node and load balancer information in the file and apply the configuration
Here is my node information for the existing Kubernetes cluster:
|Host IP||Host Name||Role||System|
|172.16.0.2||master1||master, etcd||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
|172.16.0.3||worker1||worker||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
|172.16.0.4||worker2||worker||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
Here are the nodes that will be added to the cluster to achieve high availability. Note that the number of your etcd nodes in total must be odd.
|Host IP||Host Name||Role||System|
|172.16.0.5||master2||master, etcd||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
|172.16.0.6||master3||master, etcd||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
|172.16.0.7||worker3||worker||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
For more information about requirements for nodes, networks, and dependencies, see this article.
Prepare Load Balancers
You can use any cloud load balancers or hardware load balancers (e.g. F5). In addition, Keepalived and HAproxy, or Nginx, are alternatives for creating high-availability clusters. In this example, I have an internal load balancer with a listener that listens on port
api-server) and an external load balancer with a listener that listens on the port of the Kubernetes dashboard.
Download KubeKey from its GitHub Release Page or use the following command to download KubeKey version 1.0.1. You only need to download KubeKey to one of your machines that serves as the taskbox for scaling.
- The above command downloads KubeKey and unzips the file. Your folder now contains a file called
kk. Make it executable:
Add Master Nodes
- Create a configuration file using KubeKey. If your cluster is installed through KubeKey, you may still have that configuration file on your machine. In this case, you can edit it directly. Otherwise, execute the following command to retrieve your cluster information.
- The above command creates a configuration file, which is
sample.yamlby default. Open the file and you can see some fields are pre-populated with values. Add the information of new nodes and your load balancer to the file.
This is my configuration for your reference:
Note: You are not allowed to modify the host name of existing nodes (e.g.
master1) when adding new nodes. For more information about different parameters in the configuration file, see this article.
- Pay attention to the
controlPlaneEndpointfield in the above example.
- The domain name of the load balancer is
lb.kubesphere.localby default for internal access. You can change it based on your needs.
- In most cases, you need to provide the private IP address of the load balancer for the field
address. However, different cloud providers may have different configurations for load balancers. For example, if you configure a Server Load Balancer (SLB) on Alibaba Cloud, the platform assigns a public IP address to the SLB, which means you need to specify the public IP address for the field
portindicates the port of
- Save the file and execute the following command to apply the configuration:
- You can see the output as below when scaling finishes.
- Execute the following command to check the status of namespaces.
- Execute the following command to check your nodes.
As you can see above, all of the nodes are up and running.
The steps of adding more master nodes so that your cluster is highly available are basically the same as demonstrated in my last post. The major difference is that you must configure your load balancer correctly.
Published at DZone with permission of Sherlock Xu. See the original article here.
Opinions expressed by DZone contributors are their own.