3 - RKE安装K8S


一. 创建RKE配置文件

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

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

  1. nodes:
  2. - address: 10.10.3.187 # node air gap network IP
  3. internal_address: 172.31.7.22 # node intra-cluster IP
  4. user: rancher
  5. role: [ "controlplane", "etcd", "worker" ]
  6. ssh_key_path: /home/user/.ssh/id_rsa
  7. - address: 10.10.3.254 # node air gap network IP
  8. internal_address: 172.31.13.132 # node intra-cluster IP
  9. user: rancher
  10. role: [ "controlplane", "etcd", "worker" ]
  11. ssh_key_path: /home/user/.ssh/id_rsa
  12. - address: 10.10.3.89 # node air gap network IP
  13. internal_address: 172.31.3.216 # node intra-cluster IP
  14. user: rancher
  15. role: [ "controlplane", "etcd", "worker" ]
  16. ssh_key_path: /home/user/.ssh/id_rsa
  17. private_registries:
  18. - url: <REGISTRY.YOURDOMAIN.COM:PORT> # private registry url
  19. user: rancher
  20. password: "*********"
  21. is_default: true
  22. services:
  23. etcd:
  24. # rke 0.2之前版本
  25. snapshot: true
  26. creation: 6h
  27. retention: 24h
  28. # rke 0.2之后版本 (两段配置二选一)
  29. backup_config:
  30. enabled: true # enables recurring etcd snapshots
  31. interval_hours: 6 # time increment between snapshots
  32. retention: 60 # time in days before snapshot purge
  33. # Optional S3
  34. s3_backup_config:
  35. access_key: "myaccesskey"
  36. secret_key: "myaccesssecret"
  37. bucket_name: "my-backup-bucket"
  38. endpoint: "s3.eu-west-1.amazonaws.com"
  39. region: "eu-west-1"

1、常规RKE节点选项

OptionRequiredDescription
addressyes公共域名或IP地址
useryes可以运行docker命令的用户
roleyes分配给节点的Kubernetes角色列表
internal_addressno内部集群通信的私有域名或IP地址
ssh_key_pathno用于对节点进行身份验证的SSH私钥的路径(默认为~/.ssh/id_rsa)

2、高级配置

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

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

二、创建Kubernetes集群

运行RKE命令创建Kubernetes集群

  1. 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配置文件将被命名为kubeconfig<FILE_NAME>.yml

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

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

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

  1. kubectl --kubeconfig=kube_configxxx.yml get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. 165.227.114.63 Ready controlplane,etcd,worker 11m v1.10.1
  4. 165.227.116.167 Ready controlplane,etcd,worker 11m v1.10.1
  5. 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
  1. kubectl --kubeconfig=kube_configxxx.yml get pods --all-namespaces
  2. NAMESPACE NAME READY STATUS RESTARTS AGE
  3. ingress-nginx nginx-ingress-controller-tnsn4 1/1 Running 0 30s
  4. ingress-nginx nginx-ingress-controller-tw2ht 1/1 Running 0 30s
  5. ingress-nginx nginx-ingress-controller-v874b 1/1 Running 0 30s
  6. kube-system canal-jp4hz 3/3 Running 0 30s
  7. kube-system canal-z2hg8 3/3 Running 0 30s
  8. kube-system canal-z6kpw 3/3 Running 0 30s
  9. kube-system kube-dns-7588d5b5f5-sf4vh 3/3 Running 0 30s
  10. kube-system kube-dns-autoscaler-5db9bbb766-jz2k6 1/1 Running 0 30s
  11. kube-system metrics-server-97bc649d5-4rl2q 1/1 Running 0 30s
  12. kube-system rke-ingress-controller-deploy-job-bhzgm 0/1 Completed 0 30s
  13. kube-system rke-kubedns-addon-deploy-job-gl7t4 0/1 Completed 0 30s
  14. kube-system rke-metrics-addon-deploy-job-7ljkc 0/1 Completed 0 30s
  15. 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页面。