环境

可以忽略下计算机名,用现有的环境安装的,实际使用请规范命名。

root@gateway01:/data# cat /etc/hosts
192.168.233.12 gateway01
192.168.233.13 gateway02
192.168.233.14 gateway03

基本的安装要求:

  • 每个集群节点应该有不同的主机名。主机名不要带下划线。
  • 所有节点的时间需要同步。
  • 需要在 K8S 集群的第一个 master 节点上运行 sealos run 命令,目前集群外的节点不支持集群安装。
  • 使用干净的操作系统来创建集群,不要自己装 Docker!
  • 支持大多数 Linux 发行版,例如:Ubuntu、CentOS、Rocky linux。
  • 支持 Docker Hub 中的所有 Kubernetes 版本。
  • 支持使用 Containerd 作为容器运行时。
  • 在公有云上安装请使用私有 IP。


安装

首先需要在 master 节点下载 Sealos 命令行工具,我们可以通过运行命令来获取版本列表:

curl --silent "https://api.github.com/repos/labring/sealos/releases" | jq -r '.[].tag_name'

设置 VERSION 环境变量为 latest 版本号,或者将 VERSION 替换为您要安装的 Sealos 版本:

VERSION=`curl -s https://api.github.com/repos/labring/sealos/releases/latest | grep -oE '"tag_name": "[^"]+"' | head -n1 | cut -d'"' -f4`

这里使用的版本为 v4.3.7,然后可以使用下面的命令自动下子二进制文件:

curl -sfL https://mirror.ghproxy.com/https://raw.githubusercontent.com/labring/sealos/main/scripts/install.sh | PROXY_PREFIX=https://mirror.ghproxy.com sh -s ${VERSION} labring/sealos

也可以直接使用包管理器安装(Ubuntu)

echo "deb [trusted=yes] https://apt.fury.io/labring/ /" | sudo tee /etc/apt/sources.list.d/labring.list && apt update && apt install sealos && sealos version

Sealos 安装 Kubernetes 集群,只需要在 master 节点上运行 sealos run 命令,然后指定参数即可。比如这里指定一个VIP,安装一个 v1.27.11 版本的集群,并使用 Cilium 网络插件,指定 master 的 IP 地址,最后指定 ssh 的密码。这里我把三个节点都指定为master:

sealos run -e defaultVIP=192.168.233.3 registry.cn-shanghai.aliyuncs.com/labring/kubernetes:v1.27.11 registry.cn-shanghai.aliyuncs.com/labring/helm:v3.9.4 registry.cn-shanghai.aliyuncs.com/labring/cilium:v1.13.4 \
			--masters 192.168.233.12,192.168.233.13,192.168.233.14 -p password
.......

192.168.233.14:22       To start administering your cluster from this node, you need to run the following as a regular user:
192.168.233.14:22
192.168.233.14:22               mkdir -p $HOME/.kube
192.168.233.14:22               sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
192.168.233.14:22               sudo chown $(id -u):$(id -g) $HOME/.kube/config
192.168.233.14:22
192.168.233.14:22       Run 'kubectl get nodes' to see this node join the cluster.
192.168.233.14:22
192.168.233.14:22       2024-03-06T14:40:59 info domain apiserver.cluster.local delete success
192.168.233.14:22       2024-03-06T14:40:59 info domain apiserver.cluster.local:192.168.233.14 append success
2024-03-06T14:40:59 info succeeded in joining 192.168.233.14:22 as master
2024-03-06T14:40:59 info Executing pipeline RunGuest in CreateProcessor.
ℹ️  Using Cilium version 1.13.4
🔮 Auto-detected cluster name: kubernetes
🔮 Auto-detected datapath mode: tunnel
🔮 Auto-detected kube-proxy has been installed
2024-03-06T14:41:04 info succeeded in creating a new cluster, enjoy it!
2024-03-06T14:41:04 info 
      ___           ___           ___           ___       ___           ___
     /\  \         /\  \         /\  \         /\__\     /\  \         /\  \
    /::\  \       /::\  \       /::\  \       /:/  /    /::\  \       /::\  \
   /:/\ \  \     /:/\:\  \     /:/\:\  \     /:/  /    /:/\:\  \     /:/\ \  \
  _\:\~\ \  \   /::\~\:\  \   /::\~\:\  \   /:/  /    /:/  \:\  \   _\:\~\ \  \
 /\ \:\ \ \__\ /:/\:\ \:\__\ /:/\:\ \:\__\ /:/__/    /:/__/ \:\__\ /\ \:\ \ \__\
 \:\ \:\ \/__/ \:\~\:\ \/__/ \/__\:\/:/  / \:\  \    \:\  \ /:/  / \:\ \:\ \/__/
  \:\ \:\__\    \:\ \:\__\        \::/  /   \:\  \    \:\  /:/  /   \:\ \:\__\
   \:\/:/  /     \:\ \/__/        /:/  /     \:\  \    \:\/:/  /     \:\/:/  /
    \::/  /       \:\__\         /:/  /       \:\__\    \::/  /       \::/  /
     \/__/         \/__/         \/__/         \/__/     \/__/         \/__/

                  Website: https://www.sealos.io/
                  Address: github.com/labring/sealos
                  Version: 4.3.7-f39b2339

查看集群信息:

root@gateway01:/data/sealos# kubectl get nodes
NAME        STATUS   ROLES           AGE   VERSION
gateway01   Ready    control-plane   11m   v1.27.11
gateway02   Ready    control-plane   11m   v1.27.11
gateway03   Ready    control-plane   10m   v1.27.11
root@gateway01:/data/sealos# kubectl get pods -n kube-system
NAME                                READY   STATUS    RESTARTS      AGE
cilium-d4hx7                        1/1     Running   0             10m
cilium-kr6ss                        1/1     Running   0             10m
cilium-operator-86666d88cb-z7qlv    1/1     Running   0             10m
cilium-x9dbt                        1/1     Running   0             10m
coredns-5d78c9869d-b89lt            1/1     Running   0             11m
coredns-5d78c9869d-gk46c            1/1     Running   0             11m
etcd-gateway01                      1/1     Running   0             11m
etcd-gateway02                      1/1     Running   0             10m
etcd-gateway03                      1/1     Running   0             10m
kube-apiserver-gateway01            1/1     Running   0             12m
kube-apiserver-gateway02            1/1     Running   0             11m
kube-apiserver-gateway03            1/1     Running   0             10m
kube-controller-manager-gateway01   1/1     Running   1 (10m ago)   11m
kube-controller-manager-gateway02   1/1     Running   0             10m
kube-controller-manager-gateway03   1/1     Running   0             10m
kube-proxy-76dnd                    1/1     Running   0             11m
kube-proxy-b5cjb                    1/1     Running   0             11m
kube-proxy-j2d2n                    1/1     Running   0             10m
kube-scheduler-gateway01            1/1     Running   0             11m
kube-scheduler-gateway02            1/1     Running   0             11m
kube-scheduler-gateway03            1/1     Running   0             10m

增加 master 节点,可使用如下命令:

sealos add --masters ip1,ip2

增加一个 node 节点,可使用如下命令:

sealos add --nodes ip1,ip2

增加 node 节点,可使用如下命令:

sealos add --nodes ip1,ip2

删除节点:

sealos delete xx

重置集群:

sealos reset