本文共 3016 字,大约阅读时间需要 10 分钟。
针对后续高版本会有更多优化
大概原理是为了减少大家搭建ansible和sealos的环境,客户端的东西都放到docker里,把安装包挂载到容器中,然后ansible脚本会把包分发到你在hosts文件中配置的所有服务器上
所以大概分成三步:
下面逐一说明:
找台宿主机如你的PC,或者一台服务器,把下载好的离线包拷贝到/data目录,启动sealos容器,把离线包挂载进去:
docker run --rm -v /data/kube1.12.0.tar.gz:/data/kube1.12.0.tar.gz -it -w /etc/ansible fanux/sealos:v1.12.0-beta bash
在容器里面执行:
mkdir ~/.ssh cd ~/.ssh ssh-keygen -t rsa
ssh public key:
cat ~/.ssh/id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7fTirP9zPcx7wIjhsF+Dyu0A2sV5llC8jsmp/xtiyuJirE3mclpNEqgrzHC26f+ckfzwoE0HPU0wDPxbWFl3B0K89EwJSBsVZSZ0VLYnZp0u2JgwCLZzZzKfY0018yoqoL9KHz/68RpqtG2bWVf0/WSj+4hN7xTRpRTtXJHBOQRQBfqVSIcfMBSEnO15buUbDaLol/HvQd0YBrWwafQtMacmBlqDG0Z6/yeY4sTNRVRV2Uu5TeaHfzgYgmY9+NxtvPn8Td6tgZtq7cVU//kSsbzkUzDSD8zsh8kPUm4yljT5tYM1cPFLGM4m/zqAjAZN2YaEdFckJFAQ7TWAK857d root@8682294b9464
这样公钥就生成了
cd ~/.sshecho "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7fTirP9zPcx7wIjhsF+Dyu0A2sV5llC8jsmp/xtiyuJirE3mclpNEqgrzHC26f+ckfzwoE0HPU0wDPxbWFl3B0K89EwJSBsVZSZ0VLYnZp0u2JgwCLZzZzKfY0018yoqoL9KHz/68RpqtG2bWVf0/WSj+4hN7xTRpRTtXJHBOQRQBfqVSIcfMBSEnO15buUbDaLol/HvQd0YBrWwafQtMacmBlqDG0Z6/yeY4sTNRVRV2Uu5TeaHfzgYgmY9+NxtvPn8Td6tgZtq7cVU//kSsbzkUzDSD8zsh8kPUm4yljT5tYM1cPFLGM4m/zqAjAZN2YaEdFckJFAQ7TWAK857d root@8682294b9464" >> authorized_keys
这样公钥分发工作完成了,所有的机器直接ssh无需输入密码即可登录
Config your own hosts
# cd /etc/ansible # vim hosts
配置说明:
[k8s-master]10.1.86.204 name=node01 order=1 role=master lb=MASTER lbname=lbmaster priority=10010.1.86.205 name=node02 order=2 role=master lb=BACKUP lbname=lbbackup priority=8010.1.86.206 name=node03 order=3 role=master [k8s-node]10.1.86.207 name=node04 role=node[k8s-all:children]k8s-masterk8s-node[all:vars]vip=10.1.86.209 # 同网段未被占用IPk8s_version=1.12.0 # kubernetes版本ip_interface=eth.*etcd_crts=["ca-key.pem","ca.pem","client-key.pem","client.pem","member1-key.pem","member1.pem","server-key.pem","server.pem","ca.csr","client.csr","member1.csr","server.csr"]k8s_crts=["apiserver.crt","apiserver-kubelet-client.crt","ca.crt", "front-proxy-ca.key","front-proxy-client.key","sa.pub", "apiserver.key","apiserver-kubelet-client.key", "ca.key", "front-proxy-ca.crt", "front-proxy-client.crt" , "sa.key"]
注意role=master的会装etcd与kubernetes控制节点,role=node即k8s node节点,配置比较简单,除了改IP和版本,其它基本不用动
# ansible-playbook roles/install-all.yaml
# ansible-playbook roles/uninstall-all.yaml本文转自SegmentFault-
转载地址:http://vhxsa.baihongyu.com/