本来想 docker-compose 一键启动的,不过 Rocky9.6,Rocky9.7 一直不能成功。(WSL能成功,但是不想额外解决网络的问题。)
一、安装k3s
- 关防火墙(超级重要)
1
| systemctl disable --now firewalld.service
|
- 安装
k3s 集群
1
| curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
|
- 验证
1 2 3
| export KUBECONFIG=/etc/rancher/k3s/k3s.yaml echo 'export KUBECONFIG=/etc/rancher/k3s/k3s.yaml' >> ~/.bashrc kubectl get nodes
|
- 卸载(不需要的时候可以删除)
1
| /usr/local/bin/k3s-uninstall.sh
|
二、安装helm
- 安装
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
|
- 配置
harbor 代理,(Harbor 已 配置 Dockerhub、quayio)
注意: 记得安装自签名的 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
|
- 重启
三、安装cert-manager
Rancher 用它管 TLS 证书,必装
- 安装
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
|
- 卸载
1 2 3
| kubectl get ns cert-manager -o json \ | jq '.spec.finalizers = []' \ | kubectl replace --raw "/api/v1/namespaces/cert-manager/finalize" -f -
|
四、安装 Rancher
- 获取机器的 ip
1
| node_ip=$(hostname -I | awk '{print $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
|
- 访问