ToB企服应用市场:ToB评测及商务社交产业平台

标题: K3S系列文章-使用AutoK3s在腾讯云上安装高可用K3S集群 [打印本页]

作者: 羊蹓狼    时间: 2023-2-26 06:45
标题: K3S系列文章-使用AutoK3s在腾讯云上安装高可用K3S集群
开篇

方案

在腾讯云上安装 K3S
后续会在这套 K3S 集群上安装 Rancher
方案目标

前提条件

K3S 安装注意事项

K3S 安装参数

本次 K3s 安装参数如下:
⚠️ Warning:
执行 autok3s 创建前, 如果选择已有的安全组, 那么 CVM 实例至少需要应用以下安全组规则:
  1. Rule        Protocol    Port      Source             Description
  2. InBound     TCP         22        ALL                SSH Connect Port
  3. InBound     TCP         6443      K3s agent nodes    Kubernetes API
  4. InBound     TCP         10250     K3s server & agent Kubelet
  5. InBound     UDP         8472      K3s server & agent (Optional) Required only for Flannel VXLAN
  6. InBound     TCP         2379,2380 K3s server nodes   (Optional) Required only for embedded ETCD
  7. OutBound    ALL         ALL       ALL                Allow All
复制代码
特别是: 22 端口必须要对操作机的公网IP 开放
原因: autok3s 自动部署公有云时, 通过公网IP 上传 KeyPair, 如果没有以上安全组, autok3s 会执行失败. 报错如下: (101.34.46.218 就是公网 IP)
  1. level=error msg="[ssh-dialer] init dialer [101.34.46.218:22] error: [tencent] calling getInstanceStatus error. region: ap-shanghai, zone: ap-shanghai-2, instanceName: [ins-ggxozpyl ins-cfi2vio1 ins-78rkem0b], message: not `RUNNING` status"
复制代码
安装步骤

AutoK3s

在操作机上安装,命令如下:
  1. curl -sS http://rancher-mirror.cnrancher.com/autok3s/install.sh  | INSTALL_AUTOK3S_MIRROR=cn sh
复制代码
过程如下:
  1. Downloading package http://rancher-mirror.rancher.cn/autok3s/v0.4.6/autok3s_linux_amd64 as /tmp/autok3s_linux_amd64
  2. Download complete.
  3. Running with sufficient permissions to attempt to move autok3s to /usr/local/bin
  4. New version of autok3s installed to /usr/local/bin
  5. Version: {"gitVersion":"v0.4.6","gitCommit":"4537e6ee2aea8b204a72f7b6c377edb154f7c058","gitTreeState":"","buildDate":"2021-12-28T04:15:30Z","goVersion":"go1.16.2","compiler":"gc","platform":"linux/amd64"}
  6. Downloading package http://rancher-mirror.rancher.cn/kube-explorer/v0.2.7/kube-explorer-linux-amd64 as /tmp/kube-explorer-linux-amd64
  7. Download complete.
  8. Running with sufficient permissions to attempt to move kube-explorer to /usr/local/bin
  9. New version of kube-explorer installed to /usr/local/bin
  10. Skipping /usr/local/bin/kubectl symlink to autok3s, already exists
复制代码
您可以通过以下 CLI 命令启动本地 UI。
  1. autok3s serve --bind-address 0.0.0.0 --bind-port 8087
复制代码
⚠️ Warning:
页面无登录认证,确保最小权限开放以及用完后及时关闭。
输出如下:
  1. INFO[0000] run as daemon, listening on 127.0.0.1:8087
复制代码
访问 UI:http://:8087
AutoK3s UI 模板

如果今后要多次安装,可以在 UI 上创建可复用的模板,模板包括如下固定参数:
registries.yaml:
  1. mirrors:
  2.   docker.io:
  3.     endpoint:
  4.       - "https://mirror.ccs.tencentyun.com"
  5.       - "https://registry.cn-hangzhou.aliyuncs.com"
  6.       - "https://docker.mirrors.ustc.edu.cn"
  7.   quay.io:
  8.     endpoint:
  9.       - "https://mirror.ccs.tencentyun.com"   
  10. configs:
  11.   'ccr.ccs.tencentyun.com':
  12.     auth:
  13.       username: <your-account-id>
  14.       password: <your-registry-password>
复制代码
AutoK3s 通过 UI 创建 K3S 集群

访问 UI 界面, 点击 Quick Start,  Provider 选择 tencent;
然后在下方填入自定义的信息, 主要是填写 Network 的信息, 如下图:

点击 Create, 等待返回结果即可.
AutoK3s CLI 命令

您也可以通过以下 CLI 在 腾讯云上快速创建一个 3 master, 0 worker 节点的 K3s 高可用集群。
  1. autok3s create --provider tencent --cluster --enable [ "explorer" ] --k3s-channel stable --k3s-install-mirror INSTALL_K3S_MIRROR=cn --k3s-install-script http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh --k3s-version v1.21.7+k3s1 --master 3 --master-extra-args '--write-kubeconfig-mode "644" --pause-image registry.cn-hangzhou.aliyuncs.com/rancher/pause:3.6 --etcd-s3 --etcd-snapshot-schedule-cron 0 0 * * * --etcd-s3-endpoint cos.ap-shanghai.myqcloud.com --etcd-s3-access-key <your-cos-access-key> --etcd-s3-secret-key <your-cos-secret-key> --etcd-s3-bucket <your-cos-bucket> --etcd-s3-folder /rancher/k3s' --name rancher-1 --ssh-port 22 --ssh-user ubuntu --tls-sans <your-clb-ip> --worker 0 --disk-category CLOUD_SSD --disk-size 50 --image img-22trbn9x --instance-type S5.MEDIUM8 --internet-max-bandwidth-out 5 --keypair-id <your-keypair-id> --region ap-shanghai --secret-id <your-tencent-secret-id> --secret-key <your-tencent-secret-key> --tags 'app=rancher' --tags 'env=prod' --tags 'provider=k3s' --zone ap-shanghai-2 --vpc <your-vpc-id> --subnet <your-subnet-id> --registry /etc/autok3s/registries.yaml
复制代码
安装成功日志显示如下:
  1. time="2022-02-12T14:52:16+08:00" level=info msg="[tencent] executing create logic..."
  2. INFO[0000] [tencent] use existing key pair
  3. time="2022-02-12T14:52:16+08:00" level=info msg="[tencent] 3 masters and 0 workers will be added"
  4. time="2022-02-12T14:52:16+08:00" level=info msg="[tencent] check default security group autok3s in region ap-shanghai"
  5. time="2022-02-12T14:52:16+08:00" level=info msg="[tencent] create default security group autok3s in region ap-shanghai"
  6. time="2022-02-12T14:52:16+08:00" level=info msg="[tencent] check rules of security group autok3s"
  7. time="2022-02-12T14:52:18+08:00" level=info msg="[tencent] 3 number of master instances will be created"
  8. time="2022-02-12T14:52:23+08:00" level=info msg="[tencent] 3 number of master instances successfully created"
  9. time="2022-02-12T14:52:23+08:00" level=info msg="[tencent] waiting for the instances [ins-xxxxx] to be in `RUNNING` status..."
  10. time="2022-02-12T14:52:54+08:00" level=info msg="[tencent] instances [ins-xxxxx] are in `RUNNING` status"
  11. time="2022-02-12T14:52:54+08:00" level=info msg="[tencent] executing init k3s cluster logic..."
  12. time="2022-02-12T14:52:54+08:00" level=info msg="[tencent] creating k3s master-1..."
  13. mirrors:
  14.     docker.io:
  15.         endpoint:
  16.             - https://mirror.ccs.tencentyun.com
  17.             - https://registry.cn-hangzhou.aliyuncs.com
  18.             - https://docker.mirrors.ustc.edu.cn
  19.     quay.io:
  20.         endpoint:
  21.             - https://mirror.ccs.tencentyun.com
  22. configs:
  23.     ccr.ccs.tencentyun.com:
  24.         auth:
  25.             username:
  26.             password:
  27.             auth: ""
  28.             identity_token: ""
  29.         tls: null
  30. auths: {}
  31. time="2022-02-12T14:53:26+08:00" level=info msg="[cluster] k3s master command: curl -sLS http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_TOKEN='xxxxxxx' INSTALL_K3S_EXEC='server  --tls-san xxxxx --tls-san xxxxxxxx --tls-san xxxxxxx --node-external-ip xxxxxx --write-kubeconfig-mode "644" --pause-image registry.cn-hangzhou.aliyuncs.com/rancher/pause:3.6 --disable-cloud-controller --cluster-cidr 10.42.0.0/16 --cluster-init' INSTALL_K3S_VERSION='v1.21.7+k3s1' sh -"
  32. [INFO]  Using v1.21.7+k3s1 as release
  33. [INFO]  Downloading hash http://rancher-mirror.cnrancher.com/k3s/v1.21.7-k3s1/sha256sum-amd64.txt
  34. [INFO]  Downloading binary http://rancher-mirror.cnrancher.com/k3s/v1.21.7-k3s1/k3s
  35. [INFO]  Verifying binary download
  36. [INFO]  Installing k3s to /usr/local/bin/k3s
  37. [INFO]  Creating /usr/local/bin/kubectl symlink to k3s
  38. [INFO]  Creating /usr/local/bin/crictl symlink to k3s
  39. [INFO]  Creating /usr/local/bin/ctr symlink to k3s
  40. [INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
  41. [INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
  42. [INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
  43. [INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
  44. [INFO]  systemd: Enabling k3s unit
  45. [INFO]  systemd: Starting k3s
  46. time="2022-02-12T14:53:59+08:00" level=info msg="[tencent] successfully created k3s master-1"
  47. time="2022-02-12T14:53:59+08:00" level=info msg="[tencent] creating k3s master-2..."
  48. ...
  49. time="2022-02-12T14:54:35+08:00" level=info msg="[tencent] successfully created k3s master-2"
  50. time="2022-02-12T14:54:35+08:00" level=info msg="[tencent] creating k3s master-3..."
  51. ...
  52. time="2022-02-12T14:55:06+08:00" level=info msg="[tencent] successfully created k3s master-3"
  53. apiVersion: v1
  54. clusters:
  55. - cluster:
  56.     certificate-authority-data: ......
  57.     server: https://127.0.0.1:6443
  58.   name: default
  59. contexts:
  60. - context:
  61.     cluster: default
  62.     user: default
  63.   name: default
  64. current-context: default
  65. kind: Config
  66. preferences: {}
  67. users:
  68. - name: default
  69.   user:
  70.     client-certificate-data: ......
  71.     client-key-data: ......
  72. time="2022-02-12T14:55:06+08:00" level=info msg="[tencent] deploying additional manifests"
  73. time="2022-02-12T14:55:06+08:00" level=info msg="[tencent] successfully deployed additional manifests"
  74. time="2022-02-12T14:55:06+08:00" level=info msg="[tencent] successfully executed init k3s cluster logic"
  75. ---
  76. time="2022-02-12T14:55:07+08:00" level=info msg="[tencent] successfully deployed manifests"
  77. time="2022-02-12T14:55:07+08:00" level=info msg="=========================== Prompt Info ==========================="
  78. time="2022-02-12T14:55:07+08:00" level=info msg="Use 'autok3s kubectl config use-context prod-ha.ap-shanghai.tencent'"
  79. time="2022-02-12T14:55:07+08:00" level=info msg="Use 'autok3s kubectl get pods -A' get POD status`"
复制代码

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4