Step-by-Step Guide to Setting Up a Highly Available Kubernetes Cluster on Hong Kong Cloud Servers for Multi-Node Deployment!
Kubernetes, as a leading container orchestration platform, is widely used for managing containerized applications, automating deployments, and scaling. Many companies opt to use Kubernetes to manage their microservices architecture in order to ensure high availability and flexibility. In this article, we will share how to set up a highly available Kubernetes cluster on Hong Kong cloud servers and deploy multi-node configurations.
Introduction
With the continuous development of cloud computing technology, more developers are choosing to deploy Kubernetes in cloud environments, especially on Hong Kong cloud servers. Due to its geographic advantages, low latency, and excellent network connectivity, Hong Kong has become a popular choice for both domestic and international companies. By deploying a Kubernetes cluster on a Hong Kong cloud server, companies can enjoy stable network performance while supporting cross-regional containerized applications.
This article will guide you through a real-life example of setting up a multi-node Kubernetes cluster on Hong Kong cloud servers, managing the cluster, and optimizing it to ensure its high availability and stability.
1. Preparation
1.1 Choosing the Right Hong Kong Cloud Server
First, you need to choose a suitable Hong Kong cloud server provider. Common providers include Tencent Cloud, Alibaba Cloud, AWS, Google Cloud, etc. These providers offer cloud hosts in the Hong Kong region with reliable performance, making them ideal for Kubernetes cluster deployments.
- Recommended server configuration:
- Master Node: At least 2vCPU, 4GB RAM, 50GB disk.
- Worker Node: Can scale starting from 2vCPU, 4GB RAM.
- Network: Ensure inter-node communication is available with high-speed networking.
1.2 Preparing the Operating System
Kubernetes clusters are typically deployed using Linux operating systems. Commonly used OS for Kubernetes deployments include:
- Ubuntu 20.04 LTS
- CentOS 8
- Debian 10
In this tutorial, we will use Ubuntu 20.04 LTS, and ensure that all cloud server nodes are installed with this OS.
1.3 Open Necessary Ports
Ensure that communication between the nodes in the Kubernetes cluster is smooth. In the cloud server's security group settings, make sure the following ports are open:
- 6443 (Kubernetes API server)
- 2379-2380 (etcd)
- 10250 (Kubelet)
- 10251 (Kube-scheduler)
- 10252 (Kube-controller-manager)
- 30000-32767 (NodePort services)
2. Kubernetes Cluster Installation
2.1 Install Docker
Docker is required on every node to run containers. Therefore, you must first install Docker on all nodes.
# Update package manager sudo apt-get update # Install Docker sudo apt-get install -y docker.io # Start Docker service sudo systemctl start docker sudo systemctl enable docker # Check Docker installation docker --version
2.2 Configure Kubernetes Repository
Kubernetes packages can be installed via the official Kubernetes repository. First, we need to configure this repository.
# Update apt package manager sudo apt-get update && sudo apt-get install -y apt-transport-https # Add Kubernetes official GPG key curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - # Add Kubernetes apt repository echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list # Update apt package manager sudo apt-get update
2.3 Install Kubernetes Components
Install the core Kubernetes components—kubelet, kubeadm, and kubectl—on each node.
# Install Kubernetes components sudo apt-get install -y kubelet kubeadm kubectl # Disable swap (Kubernetes requires swap to be off) sudo swapoff -a # Prevent swap from being enabled again sudo sed -i '/ swap / s/^/#/' /etc/fstab # Check versions kubeadm version kubectl version
3. Initialize Kubernetes Master Node
On the master node, initialize the Kubernetes cluster using kubeadm. During the initialization process, a command will be generated that allows you to join worker nodes to the cluster.
# Initialize the cluster with kubeadm sudo kubeadm init --pod-network-cidr=10.244.0.0/16 # Set kubectl configuration mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config # Deploy a network plugin (using Flannel as an example) kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
3.1 Get the Join Command
After kubeadm init completes, the terminal will output a command like this:
kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
This command needs to be run on the worker nodes to join them to the cluster.
4. Join Worker Nodes
Run the kubeadm join command generated earlier on each worker node to add them to the master node's Kubernetes cluster.
sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
4.1 Confirm Node Joining
On the master node, run the following command to check the status of all nodes in the cluster:
kubectl get nodes
If the output includes all worker nodes and shows the status as Ready, the cluster setup was successful.
5. Verification and Testing
5.1 Deploy a Simple Application
To verify that the Kubernetes cluster is working correctly, you can deploy a simple application, such as Nginx.
kubectl run nginx --image=nginx --replicas=3 --port=80 kubectl expose pod nginx --port=80 --target-port=80 --type=NodePort
Use kubectl get pods and kubectl get svc to check if the application has been successfully deployed.
5.2 Check Cluster Status
Use commands like kubectl get nodes and kubectl get pods --all-namespaces to check the status of the nodes and applications.
6. Conclusion
Through the above steps, we have successfully set up a multi-node Kubernetes cluster on Hong Kong cloud servers. With Kubernetes, we can easily manage multiple containerized applications while improving their scalability and availability.
Setting up a Kubernetes cluster involves multiple steps, but each step has a clear goal and method. If you are planning to deploy Kubernetes in a cloud environment, this tutorial serves as a great reference.
Hope this tutorial helps you! If you have any questions, feel free to leave a comment for discussion.