以下是在 CentOS 7 上安装 Rancher 2.7.2 并设置域名 rancher.ctyunai.cn 的步骤:

  1. 安装 Docker 和 Helm

确保已经安装了 Docker 和 Helm。如果没有安装,请参考以下命令进行安装:

# 安装 Docker
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker

# 安装 Helm
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
  1. 安装 Rancher

使用以下命令添加 Rancher Helm Chart 仓库:

helm repo add rancher-stable https://releases.rancher.com/server-charts/stable

使用以下命令安装 Rancher:

helm install rancher rancher-stable/rancher \
  --namespace cattle-system \
  --set hostname=rancher.ctyunai.cn \
  --set ingress.tls.source=secret \
  --set privateCA=true \
  --set tls=external \
  --set privateCAKey=自签名证书的私钥 \
  --set privateCACert=自签名证书的公钥 \
  --set rancherPassword=ndED8erWE4PaRhzc

其中,--set 参数指定了 Rancher 的一些配置,包括使用自签名证书 (--set privateCA=true)、自定义密码 (--set rancherPassword=ndED8erWE4PaRhzc) 等。

  1. 创建自签名证书

使用以下命令创建自签名证书:

openssl req -newkey rsa:2048 -nodes -keyout rancher.key \
  -x509 -days 365 -out rancher.crt \
  -subj "/C=CN/ST=Beijing/L=Beijing/O=Ctyunai/CN=rancher.ctyunai.cn"

其中,-subj 参数指定了证书的主题信息,包括国家、省份、城市、组织和域名等。

  1. 将证书添加到 Kubernetes

使用以下命令将自签名证书添加到 Kubernetes:

kubectl create secret tls rancher-tls \
  --cert=rancher.crt \
  --key=rancher.key \
  -n cattle-system
  1. 配置 Ingress

使用以下命令创建 Ingress 资源:

cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rancher
  namespace: cattle-system
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
  - secretName: rancher-tls
  rules:
  - host: rancher.ctyunai.cn
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: rancher
            port:
              name: http
EOF

其中,-host 参数指定了 Ingress 的域名,-tls 参数指定了使用的证书。

  1. 访问 Rancher

现在,可以使用浏览器访问 https://rancher.ctyunai.cn,使用之前设置的密码 ndED8erWE4PaRhzc 登录 Rancher。

注意:由于使用的是自签名证书,浏览器会提示证书不受信任,需要手动信任证书才能访问。

helm 安装 Rancher 272 设置域名:rancherctyunaicn rancher登陆密码:ndED8erWE4PaRhzc 使用自签名请给出步骤。

原文地址: https://www.cveoy.top/t/topic/b177 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录