k8s系列-08-kubespray的安装配置
主旨
[ ]
[ ]
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbdPY3FRjOrIgUmNUm71tQ6PoEc1qF6FHakITd+Ig/luEO3sWMWN/XpfEQY76effltPzQZ8OS7KI6uPg5qgtfFNOJjWE1JkeF55DYzBckYtJk98j05Hf+guP/FeKpZ8bWpQhonp0sAslw2N6SNQU56WIsFSTY8/QPXhOJ5/7djORY80mh6R7Xj8EZRMHw8TyRsYsJM1vNAYypUT+hHBuuP01TiI+Me7O2h0AyPjQxvwYcVQG7xca5gTS/xc+3RYswveS5FkY9ctvKiLyyyxs/uHt7RYlTMYt8d+6wDqo4gxBnsBDaylB9f1LYibyI+sqdGGztAQdm3eVy7aFUCEbjn root@node-1
[ ]
# node-1
[root@node-1 ~]# mkdir -p /root/.ssh
[root@node-1 ~]# echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbdPY3FRjOrIgUmNUm71tQ6PoEc1qF6FHakITd+Ig/luEO3sWMWN/XpfEQY76effltPzQZ8OS7KI6uPg5qgtfFNOJjWE1JkeF55DYzBckYtJk98j05Hf+guP/FeKpZ8bWpQhonp0sAslw2N6SNQU56WIsFSTY8/QPXhOJ5/7djORY80mh6R7Xj8EZRMHw8TyRsYsJM1vNAYypUT+hHBuuP01TiI+Me7O2h0AyPjQxvwYcVQG7xca5gTS/xc+3RYswveS5FkY9ctvKiLyyyxs/uHt7RYlTMYt8d+6wDqo4gxBnsBDaylB9f1LYibyI+sqdGGztAQdm3eVy7aFUCEbjn root@node-1" >> /root/.ssh/authorized_keys
# node-2
[root@node-2 ~]# mkdir -p /root/.ssh
[root@node-2 ~]# echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbdPY3FRjOrIgUmNUm71tQ6PoEc1qF6FHakITd+Ig/luEO3sWMWN/XpfEQY76effltPzQZ8OS7KI6uPg5qgtfFNOJjWE1JkeF55DYzBckYtJk98j05Hf+guP/FeKpZ8bWpQhonp0sAslw2N6SNQU56WIsFSTY8/QPXhOJ5/7djORY80mh6R7Xj8EZRMHw8TyRsYsJM1vNAYypUT+hHBuuP01TiI+Me7O2h0AyPjQxvwYcVQG7xca5gTS/xc+3RYswveS5FkY9ctvKiLyyyxs/uHt7RYlTMYt8d+6wDqo4gxBnsBDaylB9f1LYibyI+sqdGGztAQdm3eVy7aFUCEbjn root@node-1" >> /root/.ssh/authorized_keys
# node-3
[root@node-3 ~]# mkdir -p /root/.ssh
[root@node-3 ~]# echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbdPY3FRjOrIgUmNUm71tQ6PoEc1qF6FHakITd+Ig/luEO3sWMWN/XpfEQY76effltPzQZ8OS7KI6uPg5qgtfFNOJjWE1JkeF55DYzBckYtJk98j05Hf+guP/FeKpZ8bWpQhonp0sAslw2N6SNQU56WIsFSTY8/QPXhOJ5/7djORY80mh6R7Xj8EZRMHw8TyRsYsJM1vNAYypUT+hHBuuP01TiI+Me7O2h0AyPjQxvwYcVQG7xca5gTS/xc+3RYswveS5FkY9ctvKiLyyyxs/uHt7RYlTMYt8d+6wDqo4gxBnsBDaylB9f1LYibyI+sqdGGztAQdm3eVy7aFUCEbjn root@node-1" >> /root/.ssh/authorized_keys
[ ]
Last login: Thu Mar 10 11:16:21 2022 from node-1
[ ]
登出
Connection to 192.168.112.130 closed.
[ ]
Last login: Thu Mar 10 11:17:45 2022 from 192.168.112.130
[ ]
登出
Connection to 192.168.112.131 closed.
[ ]
Last login: Thu Mar 10 11:17:40 2022 from 192.168.112.130
[ ]
登出
Connection to 192.168.112.132 closed.
[ ]
依赖解决
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
ansible==2.9.16
jinja2==2.11.1
netaddr==0.7.19
pbr==5.4.4
jmespath==0.9.5
ruamel.yaml==0.16.10
[ ]
生成配置
# 拷贝一份集群配置示例,以供我们自己使用
[root@node-1 kubespray-2.15.0]# cp -rpf inventory/sample inventory/mycluster
# 环境变量配置
[root@node-1 kubespray-2.15.0]# export USE_REAL_HOSTNAME=true
[root@node-1 kubespray-2.15.0]# export CONFIG_FILE=inventory/mycluster/hosts.yaml
# 这里的IP地址一定要写成自己集群的IP地址哈,有几台就写几个
[root@node-1 kubespray-2.15.0]# declare -a IPS=(192.168.112.130 192.168.112.131 192.168.112.132)
# 生成配置文件,此处使用的是k8s提供的脚本来生成配置文件
[root@node-1 kubespray-2.15.0]# python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
个性化配置
[root@node-1 kubespray-2.15.0]# vim inventory/mycluster/hosts.yaml
all:
hosts:
node-1:
ansible_host: 192.168.112.130
ip: 192.168.112.130
access_ip: 192.168.112.130
node-2:
ansible_host: 192.168.112.131
ip: 192.168.112.131
access_ip: 192.168.112.131
node-3:
ansible_host: 192.168.112.132
ip: 192.168.112.132
access_ip: 192.168.112.132
children:
kube-master:
hosts:
node-1:
node-2:
kube-node:
hosts:
node-1:
node-2:
node-3:
etcd:
hosts:
node-1:
node-2:
node-3:
k8s-cluster:
children:
kube-master:
kube-node:
calico-rr:
hosts: {}
[ ]
[ ]
# 修改代理地址
[root@node-1 kubespray-2.15.0]# vim inventory/mycluster/group_vars/all/all.yml
# 找到以下两行,取消注释,然后写上自己的代理地址,别用我的哈,我的是内网,你连不上
http_proxy: "http://192.168.112.100"
https_proxy: "http://192.168.112.100"
[root@node-1 kubespray-2.15.0]#
[ ]
kube_service_addresses: 10.200.0.0/16
kube_pods_subnet: 10.233.0.0/16
container_manager: containerd
[ ]
[root@node-1 kubespray-2.15.0]# vim inventory/mycluster/group_vars/etcd.yml
etcd_deployment_type: host
[root@node-1 kubespray-2.15.0]#
[root@node-1 kubespray-2.15.0]# vim inventory/mycluster/group_vars/k8s-cluster/addons.yml
# 代理,默认是false
ingress_nginx_enabled: true
# 界面(可选),这里是默认注释的状态,取消注释即可
dashboard_enabled: true
往期推荐
添加关注,带你高效运维