github地址
https://github.com/clkevin/k8s-ansible
release-1.24分支
准备工作
节点准备,可增减node节点,要求2c 2g 20g+,内核5以上
10.0.2.11 k8s-master
10.0.2.10 k8s-node1
10.0.2.12 k8s-node2
环境准备(以下操作针对master节点)
- 按上述节点名称在k8s-master中配置各节点,使k8s-master能够通过ssh免密访问master及其它各节点
- 安装git
yum install -y git
- 安装ansible
yum install -y ansible
如果无法安装,先安装epel
yum install -y epel-release
- 在master用户home下
git clone https://github.com/clkevin/k8s-ansible.git
- 切换k8s-ansible分支
cd k8s-ansible
git checkout release-1.24
- 修改~/k8s-ansible/customer/hosts中的节点名称及ip
- 修改~/k8s-ansible/customer/ansible-hosts 下的ip等信息
- 将hosts复制到/etc/ansible/下
cp ~/k8s-ansible/customer/ansible-hosts /etc/ansible/hosts
- 通过ansible all -m ping测试是否正常
安装k8s
- build节点初始化脚本:
ansible-playbook ~/k8s-ansible/ansible/0.build.init.yml
- 所有节点配置脚本:
ansible-playbook ~/k8s-ansible/ansible/1.all.yml
- 部署节点脚本:
ansible-playbook ~/k8s-ansible/ansible/2.build.yml
- master安装apiserver脚本:
ansible-playbook ~/k8s-ansible/ansible/3.master.apiserver.yml
- master安装scheduler、controller-manager、kubectl
ansible-playbook ~/k8s-ansible/ansible/4.master.component.yml
- 安装nodes
ansible-playbook 5.node.yml
- master approve kublet node
ansible-playbook 6.master.post.yaml
检查
- 新建busybox
- 新建nginx
- expose nginx
- busybox wget gnixn
- 通过~/k8s-ansible/customer/token访问dashboard