KubeSphere is a powerful open-source Kubernetes platform and cloud-native application management system that has been verified by the CNCF. It offers an enterprise-grade container platform that is tailored for hybrid multi-cloud deployments. With KubeSphere, you can streamline your IT operations and integrate seamlessly with DevOps workflows.
In this article, we will guide you through the process of deploying KubeSphere on Ubuntu 22.04 servers. You will need multiple Ubuntu servers for this deployment, with one server acting as the Kubernetes control-plane and the others as worker nodes. We will be using KubeKey, a command-line tool provided by KubeSphere, to automate the deployment of the Kubernetes cluster and KubeSphere.
Prerequisites
Before we begin, make sure you meet the following requirements:
- Three Linux servers running Ubuntu 22.04, with one server designated as the control-plane and the others as worker nodes.
- A non-root user with sudo/root administrator privileges.
Setting Up Hosts and User
Before installing Kubernetes and KubeSphere, we need to set up the /etc/hosts
file and create a new user with sudo password-less access on all of your servers. Follow these steps on each of your Ubuntu servers:
- Open the
/etc/hosts
file using the following command:
sudo nano /etc/hosts
- Add the IP addresses and hostnames of your servers to the file:
192.168.5.35 master master 192.168.5.121 node1 node1 192.168.5.122 node2 node2
- Save the file and exit the editor.
- Create a new user called ‘ubuntu’ and set up a password for the user:
sudo useradd -m -s /bin/bash ubuntu sudo passwd ubuntu
- Allow the ‘ubuntu’ user to execute ‘sudo’ without a password:
cat <<EOF | sudo tee /etc/sudoers.d/ubuntu Defaults:ubuntu !fqdn Defaults:ubuntu !requiretty ubuntu ALL=(ALL) NOPASSWD: ALL EOF
Now that you have set up the /etc/hosts
file and created the ‘ubuntu’ user, let’s move on to setting up SSH key-based authentication.
Setting Up SSH Key-Based Authentication
In this section, we will set up password-less SSH authentication for the ‘ubuntu’ user. This will allow us to install Kubernetes and KubeSphere from the ‘master’ server to the ‘node1’ and ‘node2’ servers automatically.
On the ‘master’ server, follow these steps:
- Log in as the ‘ubuntu’ user:
su - ubuntu
- Generate a new SSH key pair using the following command:
ssh-keygen -t ed25519
- Copy the SSH public key from the ‘master’ server to all the nodes that will be used for the Kubernetes and KubeSphere installation:
ssh-copy-id ubuntu@master ssh-copy-id ubuntu@node1 ssh-copy-id ubuntu@node2
When prompted, input ‘yes’ to accept the SSH fingerprint for each server, and enter the password for the ‘ubuntu’ user.
Now you can connect to all of your servers via the ‘ubuntu’ user without password authentication. In the next section, we will install the necessary dependencies.
Installing Dependencies
Now that you have uploaded the SSH public key from the ‘master’ server to the ‘node1’ and ‘node2’ servers, let’s make sure you can connect to both servers and install the required dependencies for Kubernetes and KubeSphere.
On the ‘master’ server, follow these steps:
- Update and refresh your Ubuntu package index:
sudo apt update
- Install the necessary package dependencies:
sudo apt install curl socat conntrack ebtables ipset ssh-keyscan
- Add the ‘master’ server to the known hosts file:
ssh-keyscan -H master >> ~/.ssh/known_hosts
- Connect to the ‘node1’ server via SSH and install the dependencies:
ssh ubuntu@node1 sudo apt update sudo apt install curl socat conntrack ebtables ipset
- Connect to the ‘node2’ server via SSH and install the dependencies:
ssh ubuntu@node2 sudo apt update sudo apt install curl socat conntrack ebtables ipset
By now, you have configured your servers for the Kubernetes and KubeSphere installation. In the next section, we will download KubeKey, the tool that will help us initialize the Kubernetes cluster and install KubeSphere.
Downloading KubeKey on the Master Node
In this section, we will download the KubeKey binary file to the ‘master’ server. KubeKey is a single binary file that allows you to deploy the Kubernetes cluster and the KubeSphere administration dashboard. It supports cloud-native add-ons, multi-node deployments, and high availability configurations.
To download KubeKey, follow these steps:
- Download the KubeKey binary file to your current working directory:
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.2 sh-
- Make the ‘kk’ file executable:
chmod +x kk
- Verify the current version of KubeKey and the available parameters:
./kk version ./kk help
The output should display the version of KubeKey and the available command-line options.
Now that you have downloaded KubeKey, we can proceed to the next step: creating the Kubernetes and KubeSphere deployment configuration.
Creating the Kubernetes and KubeSphere Deployment Configuration
KubeKey can be used to deploy Kubernetes-only or Kubernetes with KubeSphere. It supports both single Kubernetes deployments and multi-node deployments.
For a multi-node Kubernetes and KubeSphere deployment, we need to generate a YAML script that defines the server configurations. Follow these steps to generate the YAML script:
- Run the following ‘kk’ command to generate a new YAML configuration:
./kk create config -f deployment-kubesphere.yml --with-kubernetes v1.24.2 --with-kubesphere v3.3.1
- Open the YAML file ‘deployment-kubesphere.yml’ with a text editor:
nano deployment-kubesphere.yml
- Customize the cluster name and specify the details of each server:
apiVersion: kubekey.kubesphere.io/v1alpha2 kind: Cluster metadata: name: testdeployment spec: hosts: - {name: master, address: 192.168.5.35, internalAddress: 192.168.5.35, user: ubuntu, privateKeyPath: "~/.ssh/id_ed25519"} - {name: node1, address: 192.168.5.121, internalAddress: 192.168.5.121, user: ubuntu, privateKeyPath: "~/.ssh/id_ed25519"} - {name: node2, address: 192.168.5.122, internalAddress: 192.168.5.122, user: ubuntu, privateKeyPath: "~/.ssh/id_ed25519"} roleGroups: etcd: - master control-plane: - master worker: - node1 - node2
Replace the IP addresses, usernames, and private key paths with the appropriate values for your servers.
- Save the file and exit the editor.
For this example, we will create a new Kubernetes cluster named ‘mydeployment’ with the ‘master’ server as the control plane and the ‘node1’ and ‘node2’ servers as worker nodes. We will use the ‘ubuntu’ user and the private key ‘~/.ssh/id_ed25519’ for SSH access.
Now that we have generated and configured the YAML file, we can proceed to the deployment of Kubernetes and KubeSphere.
Deploying Kubernetes and KubeSphere
In this section, we will deploy Kubernetes and KubeSphere with a multi-node architecture using KubeKey and the YAML script ‘deployment-kubesphere.yml’.
To deploy Kubernetes and KubeSphere, follow these steps:
- Execute the following ‘kk’ command to start the deployment:
./kk create cluster -f deployment-kubesphere.yml
KubeKey will check the requirements for the Kubernetes installation and prompt you to confirm the deployment. Enter ‘yes’ and press ENTER to proceed.
- Wait for the deployment to complete. This process may take 5-10 minutes. Once finished, you will see an output indicating the successful deployment.
- Open your web browser and visit the IP address of the ‘master’ server followed by port ‘30880’ (e.g.,http://192.168.5.35:30880/).
- On the login page, enter ‘admin’ as the username and ‘P@88w0rd’ as the default password. Click ‘Log In’.
- You will be prompted to change the default password for the ‘admin’ user. Enter your new password and click ‘Submit’.
- You will now have access to the KubeSphere administration dashboard, where you can manage your Kubernetes cluster and deploy applications.
Congratulations! You have successfully deployed Kubernetes and KubeSphere on your Ubuntu servers. In the next section, we will deploy a sample application to verify the success of the installation.
Deploying Pods to Kubernetes and KubeSphere
In this example, we will deploy Nginx pods to the Kubernetes cluster and KubeSphere.
Follow these steps to deploy Nginx pods:
- Run the following command to create a new deployment for the Nginx web server:
kubectl create deployment nginx --image=nginx:alpine --replicas=2
This command will create two replicas of the Nginx deployment based on the ‘nginx:alpine’ image.
- Create a new service of type ‘NodePort’ to expose the Nginx deployment:
kubectl create service nodeport nginx --tcp=80:80
This command will create a Kubernetes service named ‘nginx’ with the type ‘NodePort’ and expose port ’80’ for the Nginx pods.
- Check the list of running pods on your Kubernetes cluster:
kubectlget pods
You should see two Nginx pods running.
- Check the list of available services on Kubernetes:
kubectlget svc
The output should display the ‘nginx’ service with the type ‘NodePort’ and the exposed port ’80’ on the Kubernetes hosts.
- Access your Nginx deployment by running the following curl command:
curl<node-ip>:<node-port>
Replace <node-ip>
with the IP address of one of your worker nodes and <node-port>
with the NodePort value displayed in the previous step.
You have now successfully deployed Nginx pods to your Kubernetes cluster and verified the deployment using KubeSphere. In the next section, we will conclude the article.
Conclusion
In this tutorial, we have walked through the process of deploying Kubernetes and KubeSphere on Ubuntu 22.04 servers. You have learned how to set up the necessary hosts and user configurations, establish SSH key-based authentication, install dependencies, and download KubeKey.
With KubeKey, you were able to create the Kubernetes and KubeSphere deployment configuration and deploy the cluster. You accessed the KubeSphere administration dashboard, deployed Nginx pods to the Kubernetes cluster, and verified the deployment through KubeSphere.
KubeSphere offers a powerful platform for managing your Kubernetes clusters and cloud-native applications. With its intuitive web interface and integrated CI/CD tools, you can streamline your operations and accelerate your development workflows.
To learn more about KubeSphere, visit the official documentation at KubeSphere Documentation. For more information about Kubernetes, refer to the official Kubernetes documentation at Kubernetes Documentation.
As a reliable hosting provider, Shape.host offers a wide range of Cloud VPS solutions to support Fhwyour Kubernetes and KubeSphere deployments. Visit Shape.host to explore our scalable and secure cloud hosting services.
Remember to always stay updated with the latest releases and security patches for your Kubernetes clusters and KubeSphere installations. Happy deploying!