概览
使用kubeadm部署高可用的k8s集群
环境&版本
centos 7.4+
kubernetes 1.14
3台机器,ip为ip1,ip2,ip3,机器配置4核8G
准备工作
所有集群机器都需要执行如下操作
配置yum源
使用阿里源
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=[https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64](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/yum-key.gpg)[https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg](https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg)
EOF
系统配置
关闭selinux
# 临时关闭
setenforce 0
# 永久关闭修改/etc/selinux/config
SELINUX=disabled
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭swap
swapoff -a #临时关闭,重启后恢复
sed -i 's/.*swap.*/#&/' /etc/fstab #从开机启动中去掉
安装依赖
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet.service
systemctl enable docker
部署架构
vip:虚拟ip,apiserver的外部访问ip,需要和所有node ip在同一网段
etcd:ip1,ip2,ip3
keepalived:ip1,ip2
master:ip1,ip2,ip3
部署keepalived
部署机器ip1,ip2
部署方法
https://qizhanming.com/blog/2018/05/17/how-to-config-keepalived-on-centos-7
准备kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: stable
apiServer:
certSANs:
- "vip" # apiserver对外地址
- "ip1"
- "ip2"
- "ip3"
controlPlaneEndpoint: "vip:6443" # apiserver对外地址
networking:
dnsDomain: cluster.local
podSubnet: 10.244.0.0/16
初始化第一个master
kubeadm init --config kubeadm.yaml
执行成功会显示token,用于其他节点加入,记录下来
部署网络插件,使用flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
拷贝证书到其他master
# 打包证书
$ sudo tar zcvf certs.tar.gz /etc/kubernetes/admin.conf /etc/kubernetes/pki/ca.crt /etc/kubernetes/pki/ca.key /etc/kubernetes/pki/sa.key /etc/kubernetes/pki/sa.pub /etc/kubernetes/pki/front-proxy-ca.crt /etc/kubernetes/pki/front-proxy-ca.key /etc/kubernetes/pki/etcd/ca.crt /etc/kubernetes/pki/etcd/ca.key
# 将证书拷贝到其他master对应的位置,解压
初始化其他master
kubeadm join vip:6443 --token --discovery-token-ca-cert-hash sha256: --experimental-control-plane
设置master参与调度
可选
kubectl taint nodes --all node-role.kubernetes.io/master-
完成安装