配置kubernetes cluster流程记录
准备三台centos机器
- 每台机器需要配置/etc/hosts ip+name,三台机器的都写进里面
- 下载docker:
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
$ sudo yum install yum-utils
$ sudo yum-config-manager \
--add-repo \
https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo(推荐使用国内源,速度快)
$ sudo yum install docker-ce docker-ce-cli containerd.io
$ sudo systemctl enable docker
$ sudo systemctl start docker
$ sudo docker run hello-world
- 下载kubectl,kubelet,kubeadm
$ vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
$ yum -y install kubectl kubeadm kubelet
- 配置docker cgroups
$ cat <<EOF | sudo tee /etc/docker/daemon.json
{
"registry-mirrors": ["https://d1zbnocg.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
$ systemctl daemon-reload
$ systemctl restart docker
- kubeadm初始化
kubeadm --apiserver-advertise-address 本机IP(如果只有一个网卡可以不用管这个参数)--pod-network-cidr=10.20.0.0/16(自己指定的网段)
- 安装pod网络
k8s支持多种网络方案,这里使用flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- 添加节点
根据提示(init之后会显示)在其他节点执行kubeadm join命令