利用sealos快速安装kubernetes集群
1.环境 准备
准备三台干净的(未安装过k8s环境)的虚拟机
# 所有的主机都要配置主机名和域名映射
# 设置主机名
hostnamectl set-hostname k8s-master01
#vim /etc/hosts
192.168.28.161 k8s-master01
192.168.28.171 k8s-worker01
192.168.28.172 k8s-workder01
2.安装sealos
官方文档:https://sealos.run/docs/self-hosting/lifecycle-management/quick-start/install-cli
下载地址:https://github.com/labring/sealos/releases
# 安装环境:Rocky9
# 获取版本列表
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`
# 下载sealos,解压并安装
$ wget https://mirror.ghproxy.com/https://github.com/labring/sealos/releases/download/${VERSION}/sealos_${VERSION#v}_linux_amd64.tar.gz \
&& tar zxvf sealos_${VERSION#v}_linux_amd64.tar.gz sealos && chmod +x sealos && mv sealos /usr/bin
3.安装kubernetes集群
官方文档:https://sealos.run/docs/self-hosting/lifecycle-management/quick-start/deploy-kubernetes/
安装方式一
# 安装kubernetes集群
sealos run registry.cn-shanghai.aliyuncs.com/labring/kubernetes:v1.27.7 registry.cn-shanghai.aliyuncs.com/labring/helm:v3.9.4 \
registry.cn-shanghai.aliyuncs.com/labring/cilium:v1.13.4 \
--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]
注意:labring/helm应当在labring/cilium之前
参数说明:
参数名 | 参数值示例 | 参数说明 |
–masters | 192.168.28.161 | kubernetes master节点地址列表 |
–nodes | 192.168.28.171 | kubernetes node节点地址列表 |
–ssh-passwd | [your-ssh-passwd] | ssh登录密码 |
–kubernetes | labring/kubernetes:v1.25.0 | K8s 集群镜像 |
在干净的服务器上直接执行上面命令,不要做任何多余操作即可启动一个高可用的kubernetes集钔。
安装成功后输出如下内容:
验证k8s是否安装成功
安装方式二
# 生成配置文件
sealos gen registry.cn-shanghai.aliyuncs.com/labring/kubernetes:v1.27.7 registry.cn-shanghai.aliyuncs.com/labring/helm:v3.9.4 \
registry.cn-shanghai.aliyuncs.com/labring/cilium:v1.13.4 registry.cn-shanghai.aliyuncs.com/labring/openebs:v3.7.0 \
--masters 192.168.64.2,192.168.64.22,192.168.64.20 \
--nodes 192.168.64.21,192.168.64.19 -p root > Clusterfile
# 执行配置文件
sealos apply -f Clusterfile
安装其他组件
sealos run registry.cn-shanghai.aliyuncs.com/labing/openebs:v3.7.0
sealos run registry.cn-shanghai.aliyuncs.com/labring/cert-manager:v1.12.3
sealos run registry.cn-shanghai.aliyuncs.com/labring/minio-operator:v4.5.5 registry.cn-shanghai.aliyuncs.com/labring/ingress-nginx:v1.8.1 \
labring/mysql-operator:8.0.27-18.1 labring/redis-operator:v1.2.4
增加节点
增加node节点
$seals add --nodes 192.168.28.171,192.168.28.172
增加master节点
$seals add --masters 192.168.28.171,192.168.28.172
删除节点
删除node节点
$seals delete --nodes 192.168.28.171,192.168.28.172
删除master节点
$seals delete --masters 192.168.28.171,192.168.28.172
清理集群
$seals reset
helm install jenkins jenkins/jenkins
–set controller.admin.password=admin
–set controller.serviceType=NodePort