其他分享
首页 > 其他分享> > rke搭建k8s集群与rancher高可用部署

rke搭建k8s集群与rancher高可用部署

作者:互联网

rancher集群部署

在线部署

docker run -d --privileged --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  --privileged \
  rancher/rancher:latest
* arm64网络仅支持fannel
* 所有节点root权限
* 节点角色全部选择(crontolplane、etcd、worker)
* etcd集群要求节点数大于三个,因此集群节点不够三个时,集群不能移除节点
* 安装出错需要全部清理重来

离线部署

rke部署k8s集群

创建私有创库

### 加载仓库镜像
docker load registry.tar
### 设置仓库用户密码,用户名admin,密码sysadmin
mkdir -p /opt/registry/auth
docker run --entrypoint htpasswd registry:2.7.0 -Bbn admin sysadmin > /opt/registry/auth/htpasswd
### 开启镜像仓库
docker run  -d -p 5000:5000 --restart=always --name my_registry -v /opt/registry/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e  "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"  -e  REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry:2.7.0
### 验证登录
docker login 127.0.0.1 
将所需镜像推送到私有仓库

拉取镜像脚本地址
https://github.com/rancher/rancher/releases/tag/v2.5.5

./rancher-load-images.sh --image-list ./rancher-images.txt --registry 127.0.0.1:5000

安装rke

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub root@x.x.x.x
cp rke_linux-arm64 /usr/local/bin/rke
vi rke-cluster.yml
network:
  plugin: flannel
nodes:
  - address: 173.21.31.41 
    user: root  ### centos需要docker用户组的非root用户,
    role: ["controlplane", "etcd", "worker"]
    ssh_key_path: /root/.ssh/id_rsa
  - address: 173.21.31.42
    user: root
    role: ["controlplane", "etcd", "worker"]
    ssh_key_path: /root/.ssh/id_rsa
  - address: 173.21.31.43
    user: root
    role: ["controlplane", "etcd", "worker"]
    ssh_key_path: /root/.ssh/id_rsa

private_registries:  ## 联网环境可以不指定私有仓库
  - url: 127.0.0.1:5000
    user: admin
    password: sysadmin
    is_default: true

创建rke集群

rke up --config rke-cluster.yml
mkdir -p /root/.kube
cp kube_config_rke-cluster.yml /root/.kube/config
kubectl get nodes
NAME           STATUS   ROLES                      AGE   VERSION
173.21.31.41   Ready    controlplane,etcd,worker   27h   v1.19.7
173.21.31.42   Ready    controlplane,etcd,worker   27h   v1.19.7
173.21.31.43   Ready    controlplane,etcd,worker   27h   v1.19.7
 kubectl get pods -A
NAMESPACE                 NAME                                       READY   STATUS             RESTARTS   AGE
cattle-system             rancher-85c9cf85ff-bm5kl                   1/1     Running            80         21h
cattle-system             rancher-85c9cf85ff-fs5lc                   1/1     Running            4          21h
cattle-system             rancher-85c9cf85ff-v5g77                   1/1     Running            70         21h
cattle-system             rancher-webhook-b5b7b76c4-vx6m8            1/1     Running            1          21h
cert-manager              cert-manager-5fdd5877dc-tlddh              1/1     Running            6          23h
cert-manager              cert-manager-cainjector-54cbc96f6b-9t5dd   1/1     Running            6          23h
cert-manager              cert-manager-webhook-75c9994b75-mlwkb      1/1     Running            1          23h
fleet-system              fleet-agent-76fc77855-d78c4                1/1     Running            6          22h
fleet-system              fleet-controller-ccc95b8cd-pzpn2           1/1     Running            78         22h
fleet-system              gitjob-5997858b9c-bwch9                    1/1     Running            7          22h
ingress-nginx             default-http-backend-65dd5949d9-9stvt      1/1     Running            2          27h
ingress-nginx             nginx-ingress-controller-bng8g             0/1     CrashLoopBackOff   91         27h
ingress-nginx             nginx-ingress-controller-pxbhn             1/1     Running            0          27h
ingress-nginx             nginx-ingress-controller-qn7w2             1/1     Running            1          27h
kube-system               coredns-6f85d5fb88-bls28                   1/1     Running            1          27h
kube-system               coredns-6f85d5fb88-h4kst                   1/1     Running            0          26h
kube-system               coredns-6f85d5fb88-zt25r                   1/1     Running            1          26h
kube-system               coredns-autoscaler-79599b9dc6-xkfsq        1/1     Running            0          27h
kube-system               kube-flannel-57k2w                         2/2     Running            2          27h
kube-system               kube-flannel-mq7m8                         2/2     Running            0          27h
kube-system               kube-flannel-sljf8                         2/2     Running            2          27h
kube-system               metrics-server-8449844bf-d5zrz             1/1     Running            1          27h
kube-system               rke-coredns-addon-deploy-job-xh9dn         0/1     Completed          0          27h
kube-system               rke-ingress-controller-deploy-job-dfgkb    0/1     Completed          0          27h
kube-system               rke-metrics-addon-deploy-job-gdhxq         0/1     Completed          0          27h
kube-system               rke-network-plugin-deploy-job-n2r6l        0/1     Completed          0          27h
kube-system               tiller-deploy-6b6f975bcb-x4f8f             1/1     Running            1          23h
rancher-operator-system   rancher-operator-f54cf4887-r68cj           1/1     Running            6          23h

rancher高可用

安装cert_manager

# 安装 CustomResourceDefinition 资源
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.15.0/cert-manager.crds.yaml
# 为 cert-manager 创建命名空间
kubectl create namespace cert-manager
# 添加 Jetstack Helm 仓库
helm repo add jetstack https://charts.jetstack.io
# 更新本地 Helm chart 仓库缓存
helm repo update
# 安装 cert-manager Helm chart
helm install \
 cert-manager jetstack/cert-manager \
 --namespace cert-manager \
 --version v0.15.0
kubectl get pods --namespace cert-manager
NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-5fdd5877dc-tlddh              1/1     Running   6          28h
cert-manager-cainjector-54cbc96f6b-9t5dd   1/1     Running   6          28h
cert-manager-webhook-75c9994b75-mlwkb      1/1     Running   1          28h

安装rancher

helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm fetch rancher-stable/rancher
helm template rancher ./rancher-2.3.5.tgz \
     --namespace cattle-system --output-dir . \ --set hostname=qx.rancher.com
helm install rancher rancher-stable/rancher \
 --namespace cattle-system \
 --set hostname=qx.rancher.com

kubectl -n cattle-system rollout status deploy/rancher

UI访问

https://qx.rancher.com

用户名:admin,密码:sysadmin

标签:manager,kube,system,rke,Running,rancher,k8s
来源: https://blog.csdn.net/qq_43027317/article/details/113770598