Add New Nodes to a Kubernetes Cluster
This tutorial demonstrates how to add new nodes to a single-node cluster. To scale out a multi-node cluster, the steps are basically the same.
You need to have a single-node cluster. For more information, see All-in-One Installation on Linux.
You have .
Retrieve your cluster information using KubeKey. The command below creates a configuration file ().
You can skip this step if you already have the configuration file on your machine. For example, if you want to add nodes to a multi-node cluster which was set up by KubeKey, you might still have the configuration file if you have not deleted it.
In the configuration file, put the information of your new nodes under
hosts
androleGroups
. The example adds two new nodes (i.e.node1
andnode2
). Heremaster1
is the existing node.···
spec:
hosts:
- {name: master1, address: 192.168.0.3, internalAddress: 192.168.0.3, user: root, password: [email protected]}
- {name: node1, address: 192.168.0.4, internalAddress: 192.168.0.4, user: root, password: [email protected]}
- {name: node2, address: 192.168.0.5, internalAddress: 192.168.0.5, user: root, password: [email protected]}
roleGroups:
etcd:
- master1
master:
- master1
worker:
- node1
- node2
···
Note
- For more information about the configuration file, see Edit the configuration file.
- You are not allowed to modify the host name of existing nodes when adding new nodes.
- Replace the host name in the example with your own.
Execute the following command:
-
NAME STATUS ROLES AGE VERSION
master1 Ready master,worker 20d v1.17.9
node1 Ready worker 31h v1.17.9
The steps of adding master nodes are generally the same as adding worker nodes while you need to configure a load balancer for your cluster. You can use any cloud load balancers or hardware load balancers (for example, F5). In addition, Keepalived and , or Nginx is also an alternative for creating highly available clusters.
Create a configuration file using KubeKey.
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. Here is an example for your reference:
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: sample
spec:
hosts:
# You should complete the ssh information of the hosts
- {name: master1, address: 172.16.0.2, internalAddress: 172.16.0.2, user: root, password: Testing123}
- {name: master2, address: 172.16.0.5, internalAddress: 172.16.0.5, user: root, password: Testing123}
- {name: master3, address: 172.16.0.6, internalAddress: 172.16.0.6, user: root, password: Testing123}
- {name: worker1, address: 172.16.0.3, internalAddress: 172.16.0.3, user: root, password: Testing123}
- {name: worker2, address: 172.16.0.4, internalAddress: 172.16.0.4, user: root, password: Testing123}
- {name: worker3, address: 172.16.0.7, internalAddress: 172.16.0.7, user: root, password: Testing123}
roleGroups:
etcd:
- master1
- master2
- master3
master:
- master1
- master2
worker:
- worker1
- worker2
controlPlaneEndpoint:
# If loadbalancer is used, 'address' should be set to loadbalancer's ip.
domain: lb.kubesphere.local
address: 172.16.0.253
port: 6443
kubernetes:
version: v1.17.9
imageRepo: kubesphere
clusterName: cluster.local
proxyMode: ipvs
masqueradeAll: false
maxPods: 110
nodeCidrMaskSize: 24
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
registry:
privateRegistry: ""
Pay attention to the
controlPlaneEndpoint
field.- The domain name of the load balancer is
lb.kubesphere.local
by 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 fieldaddress
. - The field
port
indicates the port ofapi-server
.
- The domain name of the load balancer is