一. 创建RKE配置文件

使用下面的示例创建rancher-cluster.yml文件,使用创建的3个节点的IP地址或域名替换列表中的IP地址。

注意: 如果节点有公网地址 和 内网地址,建议手动设置internal_address:以便Kubernetes将内网地址用于集群内部通信。

nodes:
- address: 10.10.3.187            # node air gap network IP
  internal_address: 172.31.7.22   # node intra-cluster IP
  user: rancher
  role: [ "controlplane", "etcd", "worker" ]
  ssh_key_path: /home/user/.ssh/id_rsa
- address: 10.10.3.254            # node air gap network IP
  internal_address: 172.31.13.132 # node intra-cluster IP
  user: rancher
  role: [ "controlplane", "etcd", "worker" ]
  ssh_key_path: /home/user/.ssh/id_rsa
- address: 10.10.3.89             # node air gap network IP
  internal_address: 172.31.3.216  # node intra-cluster IP
  user: rancher
  role: [ "controlplane", "etcd", "worker" ]
  ssh_key_path: /home/user/.ssh/id_rsa

private_registries:
- url: <REGISTRY.YOURDOMAIN.COM:PORT> # private registry url
  user: rancher
  password: "*********"
  is_default: true

services:
  etcd:
    extra_args:
        auto-compaction-retention: 240 #(单位小时)
        # 修改空间配额为$((6*1024*1024*1024)),默认2G,最大8G
        quota-backend-bytes: '6442450944'
    # rke 0.2之前版本
    snapshot: true
    creation: 6h
    retention: 24h
    # rke 0.2之后版本 (两段配置二选一)
    backup_config:
      enabled: true     # enables recurring etcd snapshots
      interval_hours: 6 # time increment between snapshots
      retention: 60     # time in days before snapshot purge
      # Optional S3
      s3_backup_config:
        access_key: "myaccesskey"
        secret_key:  "myaccesssecret"
        bucket_name: "my-backup-bucket"
        endpoint: "s3.eu-west-1.amazonaws.com"
        region: "eu-west-1"

1、常规RKE节点选项

Option Required Description
address yes 公共域名或IP地址
user yes 可以运行docker命令的用户
role yes 分配给节点的Kubernetes角色列表
internal_address no 内部集群通信的私有域名或IP地址
ssh_key_path no 用于对节点进行身份验证的SSH私钥的路径(默认为~/.ssh/id_rsa)

完整的配置示例,请参考完整-cluster-yml-示例

2、高级配置

RKE有许多配置选项可用于自定义安装以适合您的特定环境。

有关选项和功能的完整列表,请查看RKE文档

二、创建Kubernetes集群

运行RKE命令创建Kubernetes集群

rke up --config ./rancher-cluster.yml

完成后,它应显示:Finished building Kubernetes cluster successfully

三、测试集群

RKE应该已经创建了一个文件kube_config_rancher-cluster.yml。这个文件包含kubectl和helm访问K8S的凭据。

注意: 如果您使用的文件不叫rancher-cluster.yml, 那么这个kube config配置文件将被命名为kube_config_<FILE_NAME>.yml

您可以将此文件复制到$HOME/.kube/config,或者如果您正在使用多个Kubernetes集群,请将KUBECONFIG环境变量设置为kube_config_rancher-cluster.yml文件路径。

export KUBECONFIG=$(pwd)/kube_config_rancher-cluster.yml

通过kubectl测试您的连接,并查看您的所有节点是否处于Ready状态。

kubectl --kubeconfig=kube_configxxx.yml  get  nodes

NAME                          STATUS    ROLES                      AGE       VERSION
165.227.114.63                Ready     controlplane,etcd,worker   11m       v1.10.1
165.227.116.167               Ready     controlplane,etcd,worker   11m       v1.10.1
165.227.127.226               Ready     controlplane,etcd,worker   11m       v1.10.1

四、检查集群Pod的运行状况

Check that all the required pods and containers are healthy are ready to continue.

  • Pods是Running或者Completed状态。
  • READY列显示所有正在运行的容器 (i.e. 3/3),STATUS显示POD是Running
  • Pods的STATUSCompletedrun-one Jobs,这些podsREADY应该为0/1
kubectl --kubeconfig=kube_configxxx.yml  get  pods --all-namespaces

NAMESPACE       NAME                                      READY     STATUS      RESTARTS   AGE
ingress-nginx   nginx-ingress-controller-tnsn4            1/1       Running     0          30s
ingress-nginx   nginx-ingress-controller-tw2ht            1/1       Running     0          30s
ingress-nginx   nginx-ingress-controller-v874b            1/1       Running     0          30s
kube-system     canal-jp4hz                               3/3       Running     0          30s
kube-system     canal-z2hg8                               3/3       Running     0          30s
kube-system     canal-z6kpw                               3/3       Running     0          30s
kube-system     kube-dns-7588d5b5f5-sf4vh                 3/3       Running     0          30s
kube-system     kube-dns-autoscaler-5db9bbb766-jz2k6      1/1       Running     0          30s
kube-system     metrics-server-97bc649d5-4rl2q            1/1       Running     0          30s
kube-system     rke-ingress-controller-deploy-job-bhzgm   0/1       Completed   0          30s
kube-system     rke-kubedns-addon-deploy-job-gl7t4        0/1       Completed   0          30s
kube-system     rke-metrics-addon-deploy-job-7ljkc        0/1       Completed   0          30s
kube-system     rke-network-plugin-deploy-job-6pbgj       0/1       Completed   0          30s

五、保存配置文件

保存kube_config_rancher-cluster.ymlrancher-cluster.yml文件的副本,您将需要这些文件来维护和升级Rancher实例。

六、Issues or errors

查看Troubleshooting页面。