需要四台機器第一台:ansible 機建立 conda 虛擬環境建立 ansible 環境(只要裝一台!)查看是否安裝成功安裝 kubespray編輯 kubespray/inventory/XXXXXX/host.yaml在 /kubespray 啟動 playbook第N台:master + node安裝 kubectl 確認安裝成功
需要四台機器
ansible 部署機 *1
master *1
worker *2
第一台:ansible 機
建立 conda 虛擬環境
由於 ansible 安裝會需要用到 python 套件
所以我們新建一個虛擬環境來處理
就叫這個環境 ansible 吧
conda create -n ansible python=3.8.5
建立 ansible 環境(只要裝一台!)
sudo pip install ansible
查看是否安裝成功
ansible --version
安裝 kubespray
git clone https://github.com/kubernetes-sigs/kubespray.git cd kubespray sudo pip install -r requirements.txt
編輯 kubespray/inventory/XXXXXX/host.yaml
ansible_host 可以自己取名
但要注意不可以包含大寫、奇怪的符號
# ## Configure 'ip' variable to bind kubernetes services on a # ## different ip than the default iface # ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value. [all] k0s ansible_host=140.119.19.25 ansible_user=seco # ip=10.3.0.1 etcd_member_name=etcd1 k1s ansible_host=140.119.19.24 ansible_user=brandon # ip=10.3.0.2 etcd_member_name=etcd2 # ip-172-31-18-25 ansible_host=18.139.136.159 ansible_user=ubuntu # ip=10.3.0.3 etcd_member_name=etcd3 # node4 ansible_host=95.54.0.15 # ip=10.3.0.4 etcd_member_name=etcd4 # node5 ansible_host=95.54.0.16 # ip=10.3.0.5 etcd_member_name=etcd5 # node6 ansible_host=95.54.0.17 # ip=10.3.0.6 etcd_member_name=etcd6 # ## configure a bastion host if your nodes are not directly reachable # [bastion] # bastion ansible_host=x.x.x.x ansible_user=some_user [kube_control_plane] k0s [etcd] k0s [kube_node] k1s # ip-172-31-18-25 # node4 # node5 # node6 [calico_rr] [k8s_cluster:children] kube_control_plane kube_node calico_rr
在 /kubespray
啟動 playbook
ansible-playbook -i inventory/mycluster/hosts.yaml cluster.yml -b -v
第N台:master + node
安裝 kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
確認安裝成功
kubectl version --client