Deploying a Kubernetes Cluster¶
Introduction¶
sealos is a simple Go binary that can be installed on most Linux operating systems. It can be flexibly used to deploy Kubernetes clusters.
Prerequisites¶
- Each cluster node must have a different hostname. Hostnames must not contain underscores.
- All nodes must have synchronized time.
- All nodes must be able to SSH into each other as the root user, and all nodes must share the same root password.
- The
sealos runcommand must be executed on the first node of the Kubernetes cluster. Cluster installation is not supported from outside the cluster. - It is recommended to use a clean operating system to create the cluster. Do not install Docker manually.
- Most Linux distributions are supported, for example: Ubuntu, CentOS, Rocky Linux.
- containerd is supported as the container runtime.
- Use private IP addresses on public clouds.
Basic Information and Compatibility¶
| Hostname | IP Address | Role | K8s Configuration |
|---|---|---|---|
| k8s-master | 192.168.100.101 | master | 4 CPU, 16G MEM, 100G DISK |
| K8s-node01 | 192.168.100.102 | node01 | 4 CPU, 16G MEM, 100G DISK |
| K8s-node02 | 192.168.100.103 | node02 | 4 CPU, 16G MEM, 100G DISK |
| Name | Description |
|---|---|
| Offline installation supported | Yes |
| Supported architectures | amd64/arm64 |
Installation Steps¶
1. Set Hostnames¶
Execute the following commands respectively:
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node01
hostnamectl set-hostname k8s-node02
2. Synchronize Time on All Nodes¶
Execute the following command on each node:
# Install ntpdate
yum install ntpdate -y
# Synchronize local time
ntpdate time.windows.com
# Synchronize with a network time source
ntpdate cn.pool.ntp.org
You can also set a crontab:
* */1 * * * /usr/sbin/ntpdate cn.pool.ntp.org
3. Install the sealos Command¶
Execute the following command to install:
Verify that the installation was successful:
$ sealos -h
simplest way install kubernetes tools.
Usage:
sealos [command]
Available Commands:
add add some node
apply apply a kubernetes cluster
build build an cloud image from a Kubefile
completion Generate the autocompletion script for the specified shell
create Create a cluster without running the CMD
delete delete some node
exec exec a shell command or script on all node.
gen Generate a Clusterfile
help Help about any command
images list cloud image
load load cloud image
login login image repository
logout logout image repository
prune prune image
pull pull cloud image
push push cloud image
reset Simplest way to reset your cluster
rmi Remove one or more cloud images
run Simplest way to run your kubernetes HA cluster
save save cloud image to a tar file
scp copy local file to remote on all node.
tag tag a image as a new one
version version
Flags:
--cluster-root string cluster root directory (default "/var/lib/sealos")
--debug enable debug logger
-h, --help help for sealos
Use "sealos [command] --help" for more information about a command.
You only need to install it on one machine.
4. Install the Cluster¶
sealos run pubrepo.guance.com/googleimages/kubernetes:v1.24.0 \
pubrepo.guance.com/googleimages/calico:v3.22.1 \
--masters 192.168.100.101 \
--nodes 192.168.100.102,192.168.100.103 \
--passwd [your-ssh-passwd]
Note: The IP addresses and password in the command must be modified.
You must be the root user, and the ports between node environments must be accessible.
Parameter description:
| Parameter | Example Value | Description |
|---|---|---|
| --masters | 192.168.100.101 | List of Kubernetes master node addresses |
| --nodes | 192.168.100.102,192.168.100.103 | List of Kubernetes node addresses |
| --passwd | [your-ssh-passwd] | SSH login password |
| kubernetes | labring/kubernetes:v1.24.0 | Kubernetes image |