Adding a New Node to a Kubernetes Cluster Managed by KubeSphere
Introduction
KubeSphere is an elegant, easy-to-use Kubernetes platform that simplifies cluster management and adds enterprise-level features. Adding a new node to an existing Kubernetes cluster managed by KubeSphere is a common operation to expand resources or improve fault tolerance. This guide provides a step-by-step walkthrough for adding a node to your cluster and addresses common issues faced during the process.
Prerequisites
- Existing Kubernetes Cluster:
- A running Kubernetes cluster (e.g., version
1.26.10
) managed by KubeSphere.
- A running Kubernetes cluster (e.g., version
- New Node Preparation:
- A machine (physical or virtual) with a supported OS (e.g., Ubuntu 20.04 or CentOS 7/8).
- Basic software installed:
ssh
,curl
, andiptables
.
- Access to the Control Plane:
- SSH access to the control plane node where KubeKey or the cluster configuration resides.
- Cluster Configuration File:
- The
cluster.yaml
file used to configure the cluster during its setup.
- The
- Permissions:
- You can work as a non-root user with
sudo
privileges, thoughroot
access is preferred for simplicity.
- You can work as a non-root user with
Step 1: Verify Cluster and KubeKey Installation
- Check the Current Cluster Status: Run the following commands on the control plane node:
1 2
kubectl get nodes kubectl get pods -A
This confirms the health of your existing cluster.
- Install KubeKey (if not already installed): Download and install the KubeKey binary:
1
curl -sfL https://get-kk.kubesphere.io | sudo bash
Verify the installation:
1
kk version
Step 2: Retrieve or Recreate cluster.yaml
- Locate the Existing Configuration:
- If the
cluster.yaml
file exists, locate it in the working directory used during the initial cluster setup.
- If the
- Regenerate
cluster.yaml
(if lost): Use thekubectl
tool andkk
to generate a new configuration file based on the current cluster:1
kk create config --from-cluster
Save the file as
cluster.yaml
.
Step 3: Add Node Information to cluster.yaml
Edit the cluster.yaml
file to include the new node. Here’s an example section for adding a worker node:
1
2
hosts:
- {name: "worker-node-2", address: "192.168.1.102", internalAddress: "192.168.1.102", user: "ubuntu", password: "your-password"}
Replace
192.168.1.102
,ubuntu
, andyour-password
with the new node’s IP address, SSH username, and password.
If you’re using SSH keys instead of passwords:
1
- {name: "worker-node-2", address: "192.168.1.102", internalAddress: "192.168.1.102", user: "ubuntu", privateKeyPath: "~/.ssh/id_rsa"}
Step 4: Add the Node to the Cluster
- Run the KubeKey Command: Execute the following command to apply the changes and add the new node:
1
kk add nodes -f cluster.yaml
KubeKey will:
- Install Kubernetes and required components on the new node.
- Configure the node as a part of the cluster.
- Monitor the Progress: The process may take several minutes. Monitor the output for errors or warnings.
Step 5: Verify the New Node
- Check Node Status: Run the following command to ensure the new node is added and ready:
1
kubectl get nodes
You should see the new node listed with a
Ready
status. - Verify Workload Distribution: Check if pods are being scheduled on the new node:
1
kubectl get pods -o wide -A
Step 6: (Optional) Enable KubeSphere Features
If the new node requires specific KubeSphere components or services:
- Log in to the KubeSphere web console.
- Navigate to Cluster Management > Nodes.
- Assign roles or workloads to the new node as needed.
Common Issues and Fixes
Issue 1: SSH Connection Fails
- Cause: Incorrect SSH credentials or configuration.
- Solution:
- Ensure SSH is enabled on the new node.
- Test the connection manually:
1
ssh [email protected]
Issue 2: Node Stuck in NotReady
State
- Cause: Missing dependencies or incorrect configuration.
- Solution:
- Check the node logs:
1 2
kubectl describe node worker-node-2 journalctl -u kubelet
- Verify network and container runtime setup on the new node.
- Check the node logs:
Issue 3: API Server Connection Refused
- Cause: The new node cannot communicate with the control plane.
- Solution:
- Verify that the
apiserver
address is correctly set incluster.yaml
. - Ensure firewall and network policies allow communication.
- Verify that the
Best Practices
Plan Node Names and Roles: Use clear naming conventions for nodes to identify their purpose and roles.
Backup Configuration: Always back up your
cluster.yaml
and KubeSphere configuration before making changes.Monitor Cluster Health: Use tools like
kubectl top
and KubeSphere’s monitoring features to track resource usage and node performance.Test Node Addition in Staging: Test the node addition process in a non-production environment to avoid service disruptions.
Conclusion
Expanding a Kubernetes cluster with KubeSphere is a straightforward process when following the correct steps. By carefully configuring and monitoring the addition of new nodes, you can ensure a smooth scaling operation without impacting the cluster’s stability. KubeSphere’s user-friendly tools further simplify this task, making it accessible for teams of all sizes.