4.部署kuberntes node
[N1,N2,N3]添加Yum源
移除可能存在的组件
yum remove docker docker-common docker-selinux docker-engine
安装一些依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
配置Docker CE 源
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
配置Kubernetes源
cat > /etc/yum.repos.d/kubernetes.repo <<EOF
[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 makecache fast
[N1,N2,N3]安装组件
kubeadm:集群部署工具
kubectl:集群管理工具
kubelet:集群引擎
docker-ce:容器驱动
yum -y install docker-ce kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0
[N1,N2,N3]添加docker配置
在国内可以加速镜像下载速度
mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],"exec-opts": ["native.cgroupdriver=systemd"],"log-driver": "json-file","log-opts": {"max-size": "100m","max-file": "10"},"oom-score-adjust": -1000,"live-restore": true
}
EOF
[N1,N2,N3]启动服务
启动并配置开机自启动
systemctl start docker kubelet
systemctl enable docker kubelet
INFO:
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
[N1,N2,N3]手动下载镜像,加速集群初始化
KUBE_VERSION=v1.15.0
KUBE_PAUSE_VERSION=3.1GCR_URL=k8s.gcr.io
ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containersimages=(kube-proxy:${KUBE_VERSION}
pause:${KUBE_PAUSE_VERSION})for imageName in ${images[@]} ; dodocker pull $ALIYUN_URL/$imageNamedocker tag $ALIYUN_URL/$imageName $GCR_URL/$imageNamedocker rmi $ALIYUN_URL/$imageName
done
[N1,N2,N3]加入集群
此命令在初始化Master集群时有记录
kubeadm join 192.168.83.3:6443 --token mpzs9m.oec6ixeesemzbxle \--discovery-token-ca-cert-hash sha256:7c05c8001693061902d6f20947fbc60c1b6a12e9ded449e6c59a71e6448fac5d
如果找不到了用上面的命令或者Token如果过期,在master节点执行即可
kubeadm token create --print-join-command
在Master节点查看node节点状态
kubectl get node
以下为输出
NAME STATUS ROLES AGE VERSION
k8s-test-master-1 Ready master 73m v1.15.0
k8s-test-master-2 Ready master 68m v1.15.0
k8s-test-master-3 Ready master 67m v1.15.0
k8s-test-node-1 Ready <none> 75s v1.15.0 #状态为Ready即为成功加入集群
k8s-test-node-2 Ready <none> 63s v1.15.0 #状态为Ready即为成功加入集群
k8s-test-node-3 Ready <none> 59s v1.15.0 #状态为Ready即为成功加入集群