本来想 docker-compose 一键启动的,不过 Rocky9.6Rocky9.7 一直不能成功。(WSL能成功,但是不想额外解决网络的问题。)

一、安装k3s

  1. 关防火墙(超级重要
1
systemctl disable --now firewalld.service
  1. 安装 k3s 集群
1
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
  1. 验证
1
2
3
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
echo 'export KUBECONFIG=/etc/rancher/k3s/k3s.yaml' >> ~/.bashrc # 让它永久生效
kubectl get nodes
  1. 卸载(不需要的时候可以删除)
1
/usr/local/bin/k3s-uninstall.sh

二、安装helm

  1. 安装 helm
1
2
curl -fsSL -o get_helm.sh https://g.bravexist.cn/https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod +x get_helm.sh && ./get_helm.sh
  1. 配置 harbor 代理,(Harbor 已 配置 Dockerhubquayio

注意: 记得安装自签名的 CA 证书。

1
vim /etc/rancher/k3s/registries.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mirrors:
docker.io:
endpoint:
- "https://harbor.lab.local"
rewrite:
"^(.*)$": "dockerhub/$1"
quay.io:
endpoint:
- "https://harbor.lab.local"
rewrite:
"^(.*)$": "quayio/$1"
configs:
"harbor.lab.local":
auth:
username: "admin" # 代理项目若是公开的,这两行可删
password: "Harbor12345"
tls:
insecure_skip_verify: true # Harbor 自签证书时保留;有受信证书可删
  1. 重启
1
systemctl restart k3s

三、安装cert-manager

Rancher 用它管 TLS 证书,必装

  1. 安装
1
2
3
4
5
6
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
--namespace cert-manager --create-namespace \
--set crds.enabled=true
kubectl -n cert-manager rollout status deploy/cert-manager # 等它 Running
  1. 卸载
1
2
3
kubectl get ns cert-manager -o json \
| jq '.spec.finalizers = []' \
| kubectl replace --raw "/api/v1/namespaces/cert-manager/finalize" -f -

四、安装 Rancher

  1. 获取机器的 ip
1
node_ip=$(hostname -I | awk '{print $1}')
  1. 安装
1
2
3
4
5
6
7
8
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm repo update
helm install rancher rancher-stable/rancher \
--namespace cattle-system --create-namespace \
--set hostname=${node_ip}.sslip.io \
--set replicas=1 \
--set bootstrapPassword=admin12345
kubectl -n cattle-system rollout status deploy/rancher # 等它滚动完成
  1. 访问
1
https://<你的IP>.sslip.io