差異處
這裏顯示兩個版本的差異處。
| 下次修改 | 前次修改 | ||
| tech:rke-k8s [2021/04/07 00:27] – 建立 jonathan | tech:rke-k8s [2022/07/19 16:55] (目前版本) – [關閉 rke (移除 K8s Cluster)] jonathan | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== 使用 rke 安裝 K8s 的程序 ====== | ====== 使用 rke 安裝 K8s 的程序 ====== | ||
| * 安裝環境 Ubuntu 20.04.2 LTS x86_64 | * 安裝環境 Ubuntu 20.04.2 LTS x86_64 | ||
| - | * 單一節點 IP : 10.20.0.35 | + | * 兩個節點 IP : 10.20.0.35 |
| - | ===== | + | ===== 前置作業 ===== |
| + | * apt 更新與安裝套件 < | ||
| + | sudo apt update | ||
| + | sudo apt-get install unzip curl software-properties-common snap -y | ||
| + | </ | ||
| + | * 安裝 Docker 19.03.14 < | ||
| + | curl -fsSL https:// | ||
| + | sudo add-apt-repository "deb [arch=amd64] https:// | ||
| + | sudo apt-get install docker-ce=5: | ||
| + | </ | ||
| + | * 安裝 kubectl < | ||
| + | sudo curl -LO https:// | ||
| + | sudo chmod a+x kubectl | ||
| + | sudo mv ./kubectl / | ||
| + | mkdir -p ~/.kube/ | ||
| + | </ | ||
| + | * 關閉 swap < | ||
| - | | + | ===== 各主機節點建立與設定 rkeuser 用戶 ===== |
| + | | ||
| + | sudo useradd -s /bin/bash -d / | ||
| + | sudo passwd rkeuser | ||
| + | sudo usermod -aG docker rkeuser | ||
| + | </ | ||
| + | * 配置免密登入-master節點-10.20.0.35 | ||
| + | * master節點-10.20.0.35 產生公鑰< | ||
| + | ssh-keygen | ||
| + | </ | ||
| + | * 將公鑰複製到各節點的 rkeuser 用戶內 < | ||
| + | ssh-copy-id [email protected] | ||
| + | ssh-copy-id [email protected] | ||
| + | </ | ||
| + | * 確認所有節點 rkeuser 可以執行 docker 命令 < | ||
| + | ssh [email protected] | ||
| + | docker ps | ||
| + | </ | ||
| + | * 如有啟動 firewall 要開啟 port | ||
| + | * 6443-KubeAPI | ||
| + | * 2379-etcd | ||
| + | * SSH server配置 TCP 轉發 < | ||
| + | sudo vi / | ||
| + | </ | ||
| + | : | ||
| + | AllowTcpForwarding yes | ||
| + | : | ||
| + | </ | ||
| + | sudo systemctl reload sshd | ||
| + | </ | ||
| + | |||
| + | ===== 安裝 rke 與建立 K8s Cluster ===== | ||
| + | * 參考 - https:// | ||
| + | * 下載 rke 1.2.7 < | ||
| + | wget https:// | ||
| + | sudo mv rke_linux-amd64 / | ||
| + | sudo chmod +x / | ||
| + | rke --version | ||
| + | </ | ||
| + | * 產生 rke 配置 K8s Cluster 檔< | ||
| + | rke config --name cluster.yml | ||
| + | </ | ||
| + | * ++看輸入資訊|< | ||
| + | localadmin@Cori-test3: | ||
| + | [+] Cluster Level SSH Private Key Path [~/ | ||
| + | [+] Number of Hosts [1]: 2 | ||
| + | [+] SSH Address of host (1) [none]: 10.20.0.35 | ||
| + | [+] SSH Port of host (1) [22]: | ||
| + | [+] SSH Private Key Path of host (10.20.0.35) [none]: | ||
| + | [-] You have entered empty SSH key path, trying fetch from SSH key parameter | ||
| + | [+] SSH Private Key of host (10.20.0.35) [none]: | ||
| + | [-] You have entered empty SSH key, defaulting to cluster level SSH key: ~/ | ||
| + | [+] SSH User of host (10.20.0.35) [ubuntu]: rkeuser | ||
| + | [+] Is host (10.20.0.35) a Control Plane host (y/n)? [y]: | ||
| + | [+] Is host (10.20.0.35) a Worker host (y/n)? [n]: y | ||
| + | [+] Is host (10.20.0.35) an etcd host (y/n)? [n]: y | ||
| + | [+] Override Hostname of host (10.20.0.35) [none]: | ||
| + | [+] Internal IP of host (10.20.0.35) [none]: 10.20.0.35 | ||
| + | [+] Docker socket path on host (10.20.0.35) [/ | ||
| + | [+] SSH Address of host (2) [none]: 10.20.0.37 | ||
| + | [+] SSH Port of host (2) [22]: | ||
| + | [+] SSH Private Key Path of host (10.20.0.37) [none]: | ||
| + | [-] You have entered empty SSH key path, trying fetch from SSH key parameter | ||
| + | [+] SSH Private Key of host (10.20.0.37) [none]: | ||
| + | [-] You have entered empty SSH key, defaulting to cluster level SSH key: ~/ | ||
| + | [+] SSH User of host (10.20.0.37) [ubuntu]: rkeuser | ||
| + | [+] Is host (10.20.0.37) a Control Plane host (y/n)? [y]: n | ||
| + | [+] Is host (10.20.0.37) a Worker host (y/n)? [n]: y | ||
| + | [+] Is host (10.20.0.37) an etcd host (y/n)? [n]: n | ||
| + | [+] Override Hostname of host (10.20.0.37) [none]: | ||
| + | [+] Internal IP of host (10.20.0.37) [none]: 10.20.0.37 | ||
| + | [+] Docker socket path on host (10.20.0.37) [/ | ||
| + | [+] Network Plugin Type (flannel, calico, weave, canal, aci) [canal]: calico | ||
| + | [+] Authentication Strategy [x509]: | ||
| + | [+] Authorization Mode (rbac, none) [rbac]: | ||
| + | [+] Kubernetes Docker image [rancher/ | ||
| + | [+] Cluster domain [cluster.local]: | ||
| + | [+] Service Cluster IP Range [10.43.0.0/ | ||
| + | [+] Enable PodSecurityPolicy [n]: | ||
| + | [+] Cluster Network CIDR [10.42.0.0/ | ||
| + | [+] Cluster DNS Service IP [10.43.0.10]: | ||
| + | [+] Add addon manifest URLs or YAML files [no]: | ||
| + | </ | ||
| + | * 檢視與編輯 | ||
| nodes: | nodes: | ||
| - | - address: | + | - address: 10.20.0.35 |
| port: " | port: " | ||
| - | internal_address: | + | internal_address: |
| role: | role: | ||
| - controlplane | - controlplane | ||
| - worker | - worker | ||
| - etcd | - etcd | ||
| - | hostname_override: | + | hostname_override: |
| + | user: rkeuser | ||
| + | docker_socket: | ||
| + | ssh_key: "" | ||
| + | ssh_key_path: | ||
| + | ssh_cert: "" | ||
| + | ssh_cert_path: | ||
| + | labels: {} | ||
| + | taints: [] | ||
| + | - address: 10.20.0.37 | ||
| + | port: " | ||
| + | internal_address: | ||
| + | role: | ||
| + | - worker | ||
| + | hostname_override: | ||
| + | user: rkeuser | ||
| + | docker_socket: | ||
| + | ssh_key: "" | ||
| + | ssh_key_path: | ||
| + | ssh_cert: "" | ||
| + | ssh_cert_path: | ||
| + | labels: {} | ||
| + | taints: [] | ||
| + | services: | ||
| + | etcd: | ||
| + | image: "" | ||
| + | : | ||
| + | : | ||
| + | </ | ||
| + | * 開始執行安裝 < | ||
| + | rke up --config cluster.yml | ||
| + | </ | ||
| + | : | ||
| + | INFO[0378] [addons] Executing deploy job rke-ingress-controller | ||
| + | INFO[0405] [ingress] ingress controller nginx deployed successfully | ||
| + | INFO[0405] [addons] Setting up user addons | ||
| + | INFO[0405] [addons] no user addons defined | ||
| + | INFO[0405] Finished building Kubernetes cluster successfully | ||
| + | </ | ||
| + | * 將產生的檔案備份起來 < | ||
| + | $ ls -lt | ||
| + | total 4476 | ||
| + | -rw-r----- | ||
| + | -rw-r----- | ||
| + | -rw-r----- | ||
| + | </ | ||
| + | * 複製 kubeconfig 檔案及驗證 kubeconfig 檔案< | ||
| + | cp kube_config_cluster.yml ~/ | ||
| + | kubectl get nodes | ||
| + | </ | ||
| + | $ kubectl get node | ||
| + | NAME | ||
| + | 10.20.0.35 | ||
| + | 10.20.0.37 | ||
| + | </ | ||
| + | |||
| + | ===== 新增與移除 K8s Node ==== | ||
| + | * 只要修改 cluster.yml 節點資料, | ||
| + | * Exp. 加上 10.20.0.36 | ||
| + | * 前面所有節點準備程序都要進行 | ||
| + | * 修改 cluster.yml < | ||
| + | nodes: | ||
| + | - address: 10.20.0.35 | ||
| + | port: " | ||
| + | internal_address: | ||
| + | role: | ||
| + | - controlplane | ||
| + | - worker | ||
| + | - etcd | ||
| + | hostname_override: | ||
| + | user: rkeuser | ||
| + | docker_socket: | ||
| + | ssh_key: "" | ||
| + | ssh_key_path: | ||
| + | ssh_cert: "" | ||
| + | ssh_cert_path: | ||
| + | labels: {} | ||
| + | taints: [] | ||
| + | - address: 10.20.0.36 | ||
| + | port: " | ||
| + | internal_address: | ||
| + | role: | ||
| + | - worker | ||
| + | hostname_override: | ||
| + | user: rkeuser | ||
| + | docker_socket: | ||
| + | ssh_key: "" | ||
| + | ssh_key_path: | ||
| + | ssh_cert: "" | ||
| + | ssh_cert_path: | ||
| + | labels: {} | ||
| + | taints: [] | ||
| + | - address: 10.20.0.37 | ||
| + | port: " | ||
| + | internal_address: | ||
| + | role: | ||
| + | - worker | ||
| + | hostname_override: | ||
| user: rkeuser | user: rkeuser | ||
| docker_socket: | docker_socket: | ||
| 行 28: | 行 224: | ||
| : | : | ||
| </ | </ | ||
| + | * 執行更新 <cli> | ||
| + | rke up --update-only --config cluster.yml | ||
| + | </ | ||
| + | ===== 關閉 rke (移除 K8s Cluster) ==== | ||
| + | * 直接執行 rke remove 就會將 K8s 移除 <cli> | ||
| + | rke remove --config cluster.yml | ||
| + | </ | ||
| + | * 執行後原本運行中的 rancher 服務還會持續運行, | ||
| ===== 參考網址 ===== | ===== 參考網址 ===== | ||
| * https:// | * https:// | ||
| + | * https:// | ||
| - | {{tag> | + | {{tag>Rancher |