I. Introduction
1. I have written about the installation method usingkubeadm
in my previous article. You can refer to it. (2) k8s cluster installation , there are a series of k8s article descriptions
2. There are many ways to install k8s
- kubeadm
- sealos
- kubespray
- etc.
3. Regarding sealos to install k8s, it is also highly recommended that you read the official documentation. Install sealos and k8s, it is very good. Clear, you can tell at a glance
4. By the way, Sealos
and Sealer
are mentioned here. They are both tools related to Kubernetes, but have different purposes and capabilities.
-
Sealos:
Sealos is a tool for quickly deploying Kubernetes clusters. It is based on Ansible and KubeAdm and is designed to simplify the installation process of Kubernetes clusters. Sealos provides a fast and convenient way to deploy single-node or multi-node Kubernetes clusters. It automatically handles node initialization, deployment of Master and Worker nodes, and cluster configuration and initialization. Sealos mainly focuses on the deployment and initialization process of Kubernetes clusters, making it easier for users to set up a running Kubernetes environment. -
Sealer:
Sealer is a tool for encrypting and protecting Kubernetes configuration files. It can encrypt Kubernetes configuration files (such as kubeconfig files) to ensure that sensitive information is protected during storage and transmission. Sealer can encrypt configuration files using different encryption algorithms and then decrypt them when used. This helps improve the security of your Kubernetes cluster, especially when managing multiple clusters, by better protecting configuration information.
Summarize:
- Sealos is mainly used for rapid deployment and initialization of Kubernetes clusters.
- Sealer is mainly used to encrypt and protect Kubernetes configuration files and enhance the security of the cluster.
2. Preparation and instructions
2.1. Cluster type
Kubernetes clusters are generally divided into two categories: one master and multiple slaves and multiple masters and multiple slaves.
- One master and multiple slaves: one Master node and multiple Node nodes, but there is a risk of single machine failure, so it is suitable for test environments
- Multi-master and multi-slave: multiple Master nodes and multiple Node nodes, high security, suitable for use in production environments
Note: For the sake of simple testing, this time we built a cluster with one master and two slaves.
2.2. Host planning
1. Configuration of each machine
effect | ip | operating system | Configuration |
---|---|---|---|
k8s-master01 | 192.168.173.135 | Centos7.9 infrastructure server | 4 CPUs, 4G memory, 100G hard drive |
k8s-node01 | 192.168.173.136 | Centos7.9 infrastructure server | 2 CPUs, 4G memory, 100G hard drive |
k8s-node02 | 192.168.173.137 | Centos7.9 infrastructure server | 2 CPUs, 4G memory, 000G hard drive |
2. Related network configuration
IPADDR=xxxxxx
NETMASK=255.255.255.0
GATEWAY=192.168.173.2
3、DNS
nameserver 8.8.8.8
nameserver 114.114.114.114
2.3. Installation instructions
2.3.1. Environment initialization (need to be done by all nodes)
1. Check the version of the operating system, because it is required to install the kubernetes cluster in this wayThe Centos version must be 7.5 or above (otherwise, the node node may not be able to join the master)< /span>
cat /etc/redhat-release
2. Host name resolution. In order to facilitate direct calls between cluster nodes later, configure host name resolution here. It is recommended to use an internal DNS server in enterprises.
# 主机名成解析 编辑三台服务器的/etc/hosts文件,添加下面内容
192.168.173.135 k8s-master01
192.168.173.136 k8s-node01
192.168.173.137 k8s-node02
3. Set the host name of each node. This is so that when k8s is used later, the generated nodes will be named after our host name. Otherwise, the nodes generated after k8s is built will be master01, node01, etc.
hostnamectl set-hostname k8s-master01
hostnamectl set-hostname k8s-node01
hostnamectl set-hostname k8s-node02
3. After the modification is completed, test whether it is normal. Test each one to avoid discovering problems later during installation, which can be uncomfortable.
-
k8s-master01 node
-
k8s-node01 node
- k8s-node02 node
4. Time synchronization,kubernetes requires that the node time in the cluster must be accurate and consistent. Here, NTP is used to synchronize network time. Of course, if you are The internal network cannot connect to the external network, so you'd better build an internal time synchronization server within the enterprise, and other machines will synchronize from this time server to ensure complete consistency.
# 主机名成解析 编辑三台服务器的/etc/hosts文件,添加下面内容
yum install ntp -y //安装ntp服务
systemctl enable ntpd //开机启动服务
systemctl start ntpd //启动服务
timedatectl set-timezone Asia/Shanghai //更改时区
timedatectl set-ntp yes //启用ntp同步
ntpq -p //同步时间
2.3.2. Install sealos
1. There are many installation methods. You can also refer to the official website. There are four installation methods.
- Binary automatic download
- Binary manual download
- Package management tool installation
- Source code installation
2.3.2.1. Manual binary download and installation
1. As of the time I wrote this article, the current version of sealos
is as follows. We can choose to install v4.3.0
Note: When selecting a version, it is recommended to use a stable version such as v4.3.0. Versions like v4.3.0-rc1 and v4.3.0-alpha1 are pre-release versions, please use them with caution
2. Download from k8s-master01 node
wget https://github.com/labring/sealos/releases/download/v4.3.0/sealos_v4.3.0_linux_amd64.tar.gz
3. Rename after decompression sealos
. After decompression is completed, you will find that there is only one executable file
4. Grant executable permissions and move it to the bin directory of the current user so that we can use it anywhere
chmod +x sealos && mv sealos /usr/bin
2.3.3. Install k8s
Prerequisites,sealos is a simple go binary that can be installed on most Linux operating systems. Here are some basic installation requirements:
- Each cluster node should have a different hostname. Do not use underscores in the hostname.
- The time of all nodes is synchronized.
- Run the sealos run command on the first node of the Kubernetes cluster. Currently, cluster installation is not supported on nodes outside the cluster.
- It is recommended to use a clean operating system to create the cluster. Don't install Docker yourself.
- Supports most Linux distributions, such as: Ubuntu CentOS Rocky linux.
- Support Kubernetes versions supported in DockerHub.
- Supports using containerd as a container runtime.
- On public cloud please use private IP.
1. The installation command is as follows
This bottom layer uses
containerd
. If you want the bottom layer to still use docker, you can see step 6 below and changelabring/kubernetes:v1.25.0
in the following command. Just change the image tolabring/kubernetes-docker:v1.25.0
$ sealos run labring/kubernetes:v1.25.0 labring/helm:v3.8.2 labring/calico:v3.24.1 \
--masters 192.168.173.135 \
--nodes 192.168.173.136,192.168.173.137 -p 123456
If you need to install HA mode, that is, multiple master nodes with high availability, it is also very simple. The command is as follows, that is, separate the IP addresses of multiple master nodes with commas after the parameter masters.
$ sealos run labring/kubernetes:v1.25.0 labring/helm:v3.8.2 labring/calico:v3.24.1 \
--masters 192.168.64.2,192.168.64.22,192.168.64.20 \
--nodes 192.168.64.21,192.168.64.19 -p [your-ssh-passwd]
2. After executing the command, you will find that most of the time you are downloading the image, so this speed has a lot to do with your Internet speed.
There is no need to access the Internet scientifically here, because the image sealos here is downloaded from dockerHub, and sealos has already taken care of it for us.
3. The interface after the installation is completed
4. Check the cluster status
kubectl get node
5. Note that k8s no longer uses docker
starting from version 1.20, but uses the lower level containerd
, so after we complete the installation , there is no docker command
In fact, the bottom layer of docker is also the same
containerd
. K8s abandons docker because the functions are somewhat the same. For this aspect, you can refer to this article Installation and use of containerd It explains the relationship between k8s, docker and containerd in detail, simple and clear
6. If you want to install the docker version of k8s, you can change the installation command in the first step to the following.
$ sealos run labring/kubernetes-docker:v1.25.0 labring/helm:v3.8.2 labring/calico:v3.24.1 \
--masters 192.168.173.135 \
--nodes 192.168.173.136,192.168.173.137 -p 123456
The difference between the two is
- labring/kubernetes-docker:v1.25.0 (使用
docker
) - labring/kubernetes:v1.25.0 (use default
containerd
)
2.4. sealos related commands
2.4.1. Add nodes
1. Add node node:
sealos add --nodes 192.168.64.21,192.168.64.19
2. Add master node:
sealos add --masters 192.168.64.21,192.168.64.19
2.4.2. Delete nodes
1. Delete the node node:
sealos delete --nodes 192.168.64.21,192.168.64.19
2. Delete the master node:
sealos delete --masters 192.168.64.21,192.168.64.19
2.4.3. Clean up the cluster
$ sealos reset
3. Installation and deployment of page management tool (Kuboard)
1. You are free to use this chapter. If you do not install it, you can use the command line or use the k8s native page control. However, the native page console is not easy to use. I personally recommend installing this.
2. I also mentioned this in the k8s series of articles (11) k8s other help && single node deployment Here I won’t repeat it again, and the official document is in Chinese and very detailed.