按照如下配置准备云主机
主机名IP地址最低配置master192.168.1.212CPU,2G内存node-0001192.168.1.312CPU,2G内存node-0002192.168.1.322CPU,2G内存node-0003192.168.1.332CPU,2G内存registry192.168.1.1001CPU,1G内存参考前面知识点完成禁用 selinux,禁用 swap,卸载 firewalld-*
安装kubeadm、kubectl、kubelet、docker-ce
[root@master ~]# yum makecache [root@master ~]# yum install -y kubeadm kubelet kubectl docker-ce [root@master ~]# mkdir -p /etc/docker [root@master ~]# vim /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "registry-mirrors": ["https://hub-mirror.c.163.com"], "insecure-registries":["192.168.1.100:5000", "registry:5000"] } [root@master ~]# systemctl enable --now docker kubelet [root@master ~]# docker info |grep Cgroup Cgroup Driver: systemd [root@master ~]# vim /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 [root@master ~]# modprobe br_netfilter [root@master ~]# sysctl --system根据提示排错若干
[root@master ~]# vim /etc/hosts 192.168.1.21 master 192.168.1.31 node-0001 192.168.1.32 node-0002 192.168.1.33 node-0003 192.168.1.100 registry [root@master ~]# kubeadm init --dry-run应答文件在云盘的 kubernetes/v1.17.6/config 目录下
[root@master ~]# mkdir init;cd init # 拷贝 kubeadm-init.yaml 到 master 云主机 init 目录下 [root@master init]# kubeadm init --config=kubeadm-init.yaml |tee master-init.log # 根据提示执行命令 [root@master init]# mkdir -p $HOME/.kube [root@master init]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config [root@master init]# sudo chown $(id -u):$(id -g) $HOME/.kube/confignode-0001,node-0002 上执行
[root@node-0001 ~]# docker rm -f $(docker ps -aq) ----------------------------------------------------------------------------------------- [root@node-0002 ~]# docker rm -f $(docker ps -aq)拷贝云盘上 kubernetes/v1.17.6/node-install 到跳板机
[root@ecs-proxy ~]# cd node-install/ [root@ecs-proxy node-install]# vim files/hosts ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 192.168.1.21 master 192.168.1.31 node-0001 192.168.1.32 node-0002 192.168.1.33 node-0003 192.168.1.100 registry [root@ecs-proxy node-install]# vim node_install.yaml ... ... vars: master: '192.168.1.21:6443' token: 'fm6kui.mp8rr3akn74a3nyn' token_hash: 'sha256:f46dd7ee29faa3c096cad189b0f9aedf59421d8a881f7623a543065fa6b0088c' ... ... [root@ecs-proxy node-install]# ansible-playbook node_install.yaml拷贝云盘 kubernetes/v1.17.6/flannel 目录到 master 上