Scale Your Cluster With KubeKey: Best Practices To Make Life Easier for Kubernetes Cluster Operators
KubeKey is a lightweight, powerful installer for Kubernetes and add-ons, and it is also an efficient tool you can use to scale your Kubernetes cluster.
Join the DZone community and get the full member experience.Join For Free
In my last post, I demonstrated how to set up a three-node Kubernetes cluster using KubeKey. As I mentioned in the article, KubeKey is a lightweight, powerful installer that is able to install Kubernetes as well as its related add-ons in a quick and convenient way. In fact, KubeKey can do way more than that as it is also an efficient tool to scale your Kubernetes cluster.
On some cloud platforms, you can directly scale your cluster by increasing or decreasing the number of nodes. Usually, this does not entail complex operations as these platforms will do almost everything for you and you only need to click a few buttons. However, in some on-premises environments, you may need to manually change the number of nodes. In this article, I am going to demonstrate how to scale out and scale in your cluster using KubeKey. The steps are listed as follows:
- Download KubeKey
- Use KubeKey to retrieve cluster information with a configuration file that's created automatically
- Verify cluster information and apply the configuration to scale out the cluster
- Scale in the cluster
Here is my node information of the existing Kubernetes cluster:
|Host IP||Host Name||Role||System|
|192.168.0.2||master||master, etcd||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
|192.168.0.3||worker1||worker||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
|192.168.0.4||worker2||worker||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
Here is the node that will be added to the cluster first and then removed from the cluster:
|Host IP||Host Name||Role||System|
|192.168.0.5||worker3||worker||CentOS 7.5, 8 Core, 8 G Memory, 50 G Disk|
For more information about requirements for nodes, networks, and dependencies, see my last post.
- 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 which serves as the taskbox for scaling, such as the master node.
Note: You can change the version number in the command to download a specific version.
- The above command downloads KubeKey and unzips the file. Your folder now contains a file called
kk. Make it executable:
Scale Out the Cluster
- Now that I have KubeKey ready, I need to create a configuration file that contains the information of all nodes, which is the same as setting up a Kubernetes cluster through 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:
--from-cluster is used to get the exiting cluster’s 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 the new node and verify if other fields are set correctly.
Note: You are not allowed to modify the host name of existing nodes (e.g. master) when adding new nodes. For more information about different parameters in the configuration file, see my last article.
- Save the file and execute the following command to apply the configuration:
- You can see the output 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 the nodes are up and running.
Scale in the Cluster
- To delete a node, you also need to prepare a configuration file in advance. If you jump to this step directly, or you have not downloaded KubeKey, refer to the above content to download KubeKey and retrieve your cluster information. After that, edit the configuration file.
- Check that all the fields are set correctly, make changes if necessary, and save the file.
- Execute the following command to scale in your cluster (
worker3is removed in this example):
<nodeName> with your own node name.
- Execute the following command to verify the result:
You can see that the node
worker3has been successfully removed.
Adding and deleting nodes remains an important part of cluster maintenance. In reality, you need to adjust the number of nodes based on the actual workloads running on your cluster for optimal resource utilization. KubeKey, fortunately, turns out to be one of the most efficient tools in this regard.
Published at DZone with permission of Sherlock Xu. See the original article here.
Opinions expressed by DZone contributors are their own.