环境准备三台:
master:192.168.100.200
node1:192.168.100.201
node2:192.168.100.202
1.初始化系统:
1).配置双击互信: [root@master ~]# ssh-keygen [root@master .ssh]# mv id_rsa.pub authorized_keys [root@master ~]# for i in 201 202;do scp -r /root/.ssh/ 192.168.100.$i:/root/;done 各个节点执行: [root@test1 yum.repos.d]# hostnamectl set-hostname master [root@test1 yum.repos.d]# hostnamectl set-hostname node1 [root@test1 yum.repos.d]# hostnamectl set-hostname node2 [root@master ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.100.200 master 192.168.100.201 node1 192.168.100.202 node2 [root@master .ssh]# for i in 201 202;do scp /etc/hosts 192.168.100.$i:/etc/;done 2).配置yum源: [root@test1 yum.repos.d]# cat > kubernetes.repo << EOF > [kubernetes] > name=a li yun > baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ > gpgcheck=0 > enabled=1 > EOF [root@test1 yum.repos.d]# cat > docker.repo << EOF > [docker] > name= a li yun > baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/ > gpgcheck=0 > enabled=1 > EOF [root@test1 yum.repos.d]# yum repolist Loaded plugins: fastestmirror ............................ kubernetes 421/421 repo id repo name status cdrom local yum 3,831 docker a li yun 61 kubernetes a li yun 421 repolist: 4,313 [root@test1 yum.repos.d]# yum makecache fast 3).关闭swap分区: [root@master yum.repos.d]# swapoff -a [root@master yum.repos.d]#sed -i '/swap/s@(.*)@#1@' /etc/fstab
2.安装docker:(各个节点需要安装)
[root@master .ssh]# yum list docker-ce.x86_64 --showduplicates | sort -r [root@master .ssh]# yum install docker-ce-19.03.4-3.el7 -y [root@master yum.repos.d]# systemctl enable docker [root@master yum.repos.d]# systemctl restart docker [root@master yum.repos.d]# 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 yum.repos.d]# cat > /etc/docker/daemon.json << EOF > { > "registry-mirrors": ["https://l6ydvf0r.mirror.aliyuncs.com"], > "exec-opts": ["native.cgroupdriver=cgroupfs"] > } > EOF
[root@master yum.repos.d]# systemctl daemon-reload && systemctl restart docker [root@master yum.repos.d]# docker info ................................. Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://l6ydvf0r.mirror.aliyuncs.com/ Live Restore Enabled: false ##其他两个节点同理以上操作。
3.使用kubeadm部署Kubernetes:
[root@master yum.repos.d]# yum install kubectl kubeadm kubectl -y node节点安装: [root@node1 ~]# yum install kubelet kubeadm -y [root@master yum.repos.d]# systemctl enable kubelet
4.初始化集群:
1.手动拉取镜像文件脚本: [root@master kubernetes]# cat docker_images.sh #!/bin/bash echo -e "