cppla带你玩k8s之一(快速配置kubernets集群)
目录
一、集群
[初始化配置节点]
- master1 157.230.148.56
- node1 157.230.145.228
[动态添加节点]
- node2 157.230.176.176
二、注意
k8s设计出于性能的考虑,不使用swap 分区, “swapoff -a” or “echo “vm.swappiness = 0″>> /etc/sysctl.conf”
三、安装依赖环境
1 2 3 4 5 6 |
yum install python3-pip -y yum install git -y pip3 uninstall ansible ansible-base pip3 install ansible==2.9.14 pip3 install netaddr pip3 install Jinja2 |
1 2 3 4 |
# 停止防火墙 systemctl stop firewalld.service # 卸载 yum -y remove firewalld |
四、配置密钥互通
# 一、node A(master):
1 2 3 |
ssh-keygen -t rsa cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
# 二、node B:
1 2 3 |
# 上传密钥到node B # scp ~/.ssh/id_rsa.pub root@node B:/root/.ssh cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
# 三、ssh互通测试
1 |
ssh root@node B |
五、kubernetes集群配置
# 一、下载kubernetes
1 2 3 4 |
git clone https://github.com/kubernetes-sigs/kubespray cd kubespray pip3 install -r requirements.txt cp -r inventory/sample inventory/cppla |
# 二、初始化inventory文件
1 2 |
declare -a IPS=(157.230.148.56 157.230.145.228) CONFIG_FILE=inventory/cppla/hosts.ini python3 contrib/inventory_builder/inventory.py ${IPS[@]} |
# 三、调整集群配置cppla/inventory.ini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[all] node1 ansible_host=157.230.148.56 ip=157.230.148.56 node2 ansible_host=157.230.145.228 ip=157.230.145.228 [kube-master] node1 [etcd] node1 [kube-node] node2 [k8s-cluster:children] kube-master kube-node [calico-rr] |
六、启动kubernetes集群
1 |
ansible-playbook -i inventory/cppla/inventory.ini cluster.yml |
七、动态添加kubernetes节点
# 一、新节点添加密钥互通
1 |
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
# 二、调整集群配置cppla/inventory.ini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[all] node1 ansible_host=157.230.148.56 ip=157.230.148.56 node2 ansible_host=157.230.145.228 ip=157.230.145.228 node3 ansible_host=157.230.176.176 ip=157.230.176.176 [kube-master] node1 [etcd] node1 [kube-node] node2 node3 [k8s-cluster:children] kube-master kube-node [calico-rr] |
# 三、执行命令
1 |
ansible-playbook -i inventory/cppla/inventory.ini scale.yml |
八、验证kubernetes集群是否成功
1 2 3 4 5 |
# kubectl get node NAME STATUS ROLES AGE VERSION node1 Ready master 32m v1.13.2 node2 Ready node 32m v1.13.2 node3 Ready node 65s v1.13.2 |
以上测试on DigitalOcean Cloud Computing, time:20201201, by: cpp.la
One Reply to “cppla带你玩k8s之一(快速配置kubernets集群)”