操作系统:CentOS Linux release 7.6.1810 (Core)
安装软件:
docker:18.06.3-ce
kubernetes:v1.15.4
部署开始前,先把主机名改成如上图所示。
同时修改/etc/hosts,如下:
sudo yum remove docker docker-common container-selinux docker-selinux docker-engine
sudo yum install -y yum-utils
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo ##更新索引 sudo yum clean all##推荐先清空索引,特别是新版本docker需要换成老版本docker的时候 sudo yum makecache fast
##查看下自己能安装的版本都有哪些 yum list docker-ce --showduplicates | sort -r ##不指定版本,安装最新版本的docker sudo yum install docker-ce ##此处也可以安装指定版本的docker,如下: sudo yum install -y docker-ce-18.09.9-3.el7
systemctl enable docker && systemctl start docker
[root@master ~]# vi /etc/docker/daemon.json { "registry-mirrors": ["https://4ym6pzzt.mirror.aliyuncs.com"] }
systemctl restart docker
[root@master yum.repos.d]# cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
yum list kubelet --showduplicates | sort -r
找到我们需要安装的版本
yum install -y kubelet-1.15.4 kubeadm-1.15.4 kubectl-1.15.4
sed -i "s#^ExecStart=/usr/bin/dockerd.*#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd#g" /usr/lib/systemd/system/docker.service
kubeadm init --apiserver-advertise-address=10.0.0.17 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.15.4 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
[root@master ~]# mkdir -p $HOME/.kube [root@master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config [root@master ~]# chown $(id -u):$(id -g) $HOME/.kube/config
# 手动拉取flannel的docker镜像 docker pull easzlab/flannel:v0.11.0-amd64 # 修改镜像名称 docker tag easzlab/flannel:v0.11.0-amd64 quay.io/coreos/flannel:v0.11.0-amd64 # wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml # kubectl apply -f kube-flannel.yml
至此,master节点部署完毕
[root@master ~]# kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS qb289r.phfyq6rd0vlf19w7 23h 2021-07-07T03:47:46-04:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token
证书有效期仅为24小时,若过期后需添加node节点,可重新生成:
kubeadm token create
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
kubeadm join --token qb289r.phfyq6rd0vlf19w7 10.0.0.17:6443 --discovery-token-ca-cert-hash sha256:1823760d5ae6223edc3d8f44ec82a28b4d1d4cf31002968f64daacde4eb64a2e
scp /etc/kubernetes/admin.conf 10.0.0.27:/etc/kubernetes/ scp /etc/kubernetes/admin.conf 10.0.0.37:/etc/kubernetes/ #添加到环境变量 echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile #使环境变量生效 source ~/.bash_profile
[root@master ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready master 59m v1.15.4 node01 Ready <none> 31m v1.15.4 node02 Ready <none> 32m v1.15.4
查看POD
可见集群已成功同步并已调度到node节点。
至此,kubernetes集群搭建完毕!