使用RKE快速部署k8s集群


目標

安全
穩定
廉價
快速
容災
擴展

服務器

基礎數據

騰訊雲 2核 8GB 5Mbps

安全組配置

開放80、443,允許全部ip訪問
開放22、6443,開放當前ip訪問

image

環境

# 卸載firewalld,由安全組統一管理端口
sudo dnf remove firewalld
# 關閉交換分區
sudo swapoff -a
# 使用iptables處理ipv4橋接數據
sudo sysctl net.bridge.bridge-nf-call-iptables=1
#
sysctl --system
# 添加docker阿里雲源
sudo dnf config-manager --add-repo  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 查看docker版本
sudo dnf list docker-ce --showduplicates | sort -r
# 安裝docker
dnf install docker-ce-20.10.6-3.el8
# 配置docker

## 使用systemd管理cgroup
## 騰訊雲加速docker鏡像下載
## 限制日志文件大小為100m
## 采用overlay2存儲驅動
sudo mkdir /etc/docker
cat <<EOF | sudo tee /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": [
    "https://mirror.ccs.tencentyun.com"
  ],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
## 開機運行並重啟docker
sudo systemctl enable docker
sudo systemctl daemon-reload
sudo systemctl restart docker

用戶

# 添加rke用戶
sudo useradd -m rke
# 本地生成rke用戶密鑰對
ssh-keygen -t rsa
# 在本地將公鑰傳輸到雲服務器
# 具體可以參見參考內容中“密鑰管理”一節
ssh-copy-id -i ~/.ssh/id_rsa.pub rke@yunfuwuqi
# 將rke添加到docker用戶組
sudo usermod -aG docker rke

安裝

下載RKE

下載地址:
https://github.com/rancher/rke/releases
支持版本:
macOS:rke_darwin-amd64
Linux (Intel/AMD):rke_linux-amd64
Linux (ARM 32-bit):rke_linux-arm
Linux (ARM 64-bit):rke_linux-arm64
Windows (32-bit):rke_windows-386.exe
Windows (64-bit):rke_windows-amd64.exe

生成集群配置

# 在當前路徑下創建cluster.yml配置文件
rke config

官方配置示例:
https://docs.rancher.cn/docs/rke/example-yamls/_index

單節點配置:

# If you intened to deploy Kubernetes in an air-gapped environment,
# please consult the documentation on how to configure custom RKE images.
nodes:
- address: "0.0.0.0"
  port: "22"
  # 內網ip
  internal_address: "172.21.3.9"
  # 全角色
  role:
  - controlplane
  - worker
  - etcd
  # 不覆蓋hostname
  hostname_override: ""
  # 用戶名
  user: rke
# 全局ssh key
ssh_key_path: ./id_rsa_rke
ssh_cert_path: ""
ssh_agent_auth: false
services:
  etcd:
    # 集群數據備份
    backup_config:
      # 創建快照的間隔時間,單位小時,12表示每12個小時創建一個快照
      interval_hours: 1
      # 快照的存活時間,單位小時
      retention: 48
  kube-api:
    service_cluster_ip_range: 10.43.0.0/16
    service_node_port_range: "30000-32767"
    pod_security_policy: false
    always_pull_images: false
    extra_args:
      # 審計日志
      audit-log-path: "-"
  kube-controller:
    cluster_cidr: 10.42.0.0/16
    service_cluster_ip_range: 10.43.0.0/16
  scheduler:
  kubelet:
    cluster_domain: k8s.qcloud
    cluster_dns_server: 10.43.0.10
    # 如果存在交換分區則報錯
    fail_swap_on: false
    generate_serving_certificate: false
    # 最大pod數
    extra_args:
      max-pods: 250
    # 掛載本地磁盤
    extra_binds:
    - "/home/rke/data:/home/rke/data"
  kubeproxy:
network:
  plugin: canal
authentication:
  strategy: x509
  sans: []
  webhook: null
addons: ""
addons_include: []
system_images:
  etcd: rancher/mirrored-coreos-etcd:v3.4.15-rancher1
  alpine: rancher/rke-tools:v0.1.74
  nginx_proxy: rancher/rke-tools:v0.1.74
  cert_downloader: rancher/rke-tools:v0.1.74
  kubernetes_services_sidecar: rancher/rke-tools:v0.1.74
  kubedns: rancher/mirrored-k8s-dns-kube-dns:1.15.10
  dnsmasq: rancher/mirrored-k8s-dns-dnsmasq-nanny:1.15.10
  kubedns_sidecar: rancher/mirrored-k8s-dns-sidecar:1.15.10
  kubedns_autoscaler: rancher/mirrored-cluster-proportional-autoscaler:1.8.1
  coredns: rancher/mirrored-coredns-coredns:1.8.0
  coredns_autoscaler: rancher/mirrored-cluster-proportional-autoscaler:1.8.1
  nodelocal: rancher/mirrored-k8s-dns-node-cache:1.15.13
  kubernetes: rancher/hyperkube:v1.20.6-rancher1
  flannel: rancher/coreos-flannel:v0.13.0-rancher1
  flannel_cni: rancher/flannel-cni:v0.3.0-rancher6
  calico_node: rancher/mirrored-calico-node:v3.17.2
  calico_cni: rancher/mirrored-calico-cni:v3.17.2
  calico_controllers: rancher/mirrored-calico-kube-controllers:v3.17.2
  calico_ctl: rancher/mirrored-calico-ctl:v3.17.2
  calico_flexvol: rancher/mirrored-calico-pod2daemon-flexvol:v3.17.2
  canal_node: rancher/mirrored-calico-node:v3.17.2
  canal_cni: rancher/mirrored-calico-cni:v3.17.2
  canal_controllers: rancher/mirrored-calico-kube-controllers:v3.17.2
  canal_flannel: rancher/coreos-flannel:v0.13.0-rancher1
  canal_flexvol: rancher/mirrored-calico-pod2daemon-flexvol:v3.17.2
  weave_node: weaveworks/weave-kube:2.8.1
  weave_cni: weaveworks/weave-npc:2.8.1
  pod_infra_container: rancher/mirrored-pause:3.2
  ingress: rancher/nginx-ingress-controller:nginx-0.43.0-rancher3
  ingress_backend: rancher/mirrored-nginx-ingress-controller-defaultbackend:1.5-rancher1
  metrics_server: rancher/mirrored-metrics-server:v0.4.1
  windows_pod_infra_container: rancher/kubelet-pause:v0.1.6
  aci_cni_deploy_container: noiro/cnideploy:5.1.1.0.1ae238a
  aci_host_container: noiro/aci-containers-host:5.1.1.0.1ae238a
  aci_opflex_container: noiro/opflex:5.1.1.0.1ae238a
  aci_mcast_container: noiro/opflex:5.1.1.0.1ae238a
  aci_ovs_container: noiro/openvswitch:5.1.1.0.1ae238a
  aci_controller_container: noiro/aci-containers-controller:5.1.1.0.1ae238a
  aci_gbp_server_container: noiro/gbp-server:5.1.1.0.1ae238a
  aci_opflex_server_container: noiro/opflex-server:5.1.1.0.1ae238a
authorization:
  mode: rbac
  options: {}
ignore_docker_version: null
kubernetes_version: ""
private_registries: []
# 不使用ingress
ingress:
  provider: "none"
addon_job_timeout: 0
bastion_host:
monitoring:
restore:
  restore: false
  snapshot_name: ""
rotate_encryption_key: false
dns: null

安裝

rke up

查看集群狀況

./kube-explorer-linux-amd64  --kubeconfig=kube_config_cluster.yml --http-listen-port=9898 --https-listen-port=0

image

參考

Docekr版本選擇
https://github.com/kubernetes/kubernetes/blob/master/build/dependencies.yaml
使用iptables處理ipv4橋接數據
https://www.ibm.com/docs/en/fci/1.0.2?topic=SSCKRH_1.0.2/platform/r_software_requirements_fci_kubernetes.html
密鑰管理
https://upcloud.com/community/tutorials/use-ssh-keys-authentication/
集群管理工具
https://github.com/cnrancher/kube-explorer


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM