Kubernetes(k8s)1.18.3高可用集群部署(多master多node)(三)

Kubernetes(k8s)1.18.3高可用集群部署(多master多node)(三) 第三部分:部署k8s集群(多master多node) 创建kubeadm配置文件  (在主master上) cat > ./kubeadm-config.yaml &l...

Kubernetes(k8s)1.18.3高可用集群部署(多master多node)(三)


第三部分:部署k8s集群(多master多node)


创建kubeadm配置文件  (在主master上)


cat > ./kubeadm-config.yaml <<EOF

apiVersion: kubeadm.k8s.io/v1beta2

kind: ClusterConfiguration

kubernetesVersion: v1.18.3

apiServer:

  certSANs:

  - "127.0.0.1"

  - "k8s-vip"

  - "k8s-m1"

  - "k8s-m2"

  - "k8s-m3"

  - "192.168.40.9"

  - "192.168.40.81"

  - "192.168.40.82"

  - "192.168.40.83"

imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers

controlPlaneEndpoint: "k8s-vip:16443"

networking:

  serviceSubnet: "10.96.0.0/16"

  podSubnet: "10.244.0.0/16"

EOF


初始化master 

(在主master上)

# kubeadm init --config=kubeadm-config.yaml --upload-certs

attachments-2020-05-PfrmUocK5ed0edecc22ef.png

attachments-2020-05-19KsUzIj5ed0ee1dd35c1.png

按照说明进行设置:

[[email protected] ~]# mkdir -p $HOME/.kube

[[email protected] ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

[[email protected] ~]# chown $(id -u):$(id -g) $HOME/.kube/config



部署flannel网络


[[email protected] ~]# mkdir -p ~/k8s_flannel && cd ~/k8s_flannel

[[email protected] k8s_flannel]# wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml


修改kube-flannel.yml配置文件

# vim kube-flannel.yml

集群容器网段要与集群的pod-network一致

attachments-2020-05-pJOt9QjB5ed0f00ce3bfa.png

flanneld启动参数加上–-iface=<iface-name>  本例中的网卡为 eth0(单网卡可选  多个网卡必须指定网络接口否则nds解析错误)


attachments-2020-05-PRbSTVJO5ed0f02901534.png

启动flannel

# kubectl apply -f  kube-flannel.yml       启动flannel网络插件


attachments-2020-05-uHOCSHch5ed0f0481bedd.png

检查pod与node

attachments-2020-05-GizlBXve5ed0f0706d75a.png


master other 加入集群

 

先复制密钥及相关文件:



vipmaster1上把相关密钥与文件scp到其他所有master

 

# ssh [email protected] mkdir -p /etc/kubernetes/pki/etcd

# scp /etc/kubernetes/admin.conf [email protected]:/etc/kubernetes/admin.conf

# scp /etc/kubernetes/pki/{ca.*,sa.*,front-proxy-ca.*} [email protected]:/etc/kubernetes/pki

# scp /etc/kubernetes/pki/etcd/ca.* [email protected]:/etc/kubernetes/pki/etcd

 

# ssh [email protected] mkdir -p /etc/kubernetes/pki/etcd

# scp /etc/kubernetes/admin.conf [email protected]:/etc/kubernetes/admin.conf

# scp /etc/kubernetes/pki/{ca.*,sa.*,front-proxy-ca.*} [email protected]:/etc/kubernetes/pki

# scp /etc/kubernetes/pki/etcd/ca.* [email protected]:/etc/kubernetes/pki/etcd


加入集群


在k8s-m2 k8s-m3 分别输入join命令:


kubeadm join k8s-vip:16443 --token cf1xoc.etmcuyk8d8ms138j \

    --discovery-token-ca-cert-hash sha256:1b177dfd0be798642fb643f5a7c23aa92e8f1f11fd5619c7dcf8e815c69ce2c1 \

    --control-plane --certificate-key 680e691bf851059d00ba25e96a4d2f68825965c56e15d2020b305a17fc6cc1b0

attachments-2020-05-yDUPpAld5ed0f19b69d50.png


按照说明进行设置:

[[email protected] ~]# mkdir -p $HOME/.kube

[[email protected] ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

[[email protected] ~]# chown $(id -u):$(id -g) $HOME/.kube/config



node节点加入集群


在各nodework)节点输入join命令:    


[[email protected] ~]# kubeadm join k8s-vip:16443 --token cf1xoc.etmcuyk8d8ms138j \
>     --discovery-token-ca-cert-hash sha256:1b177dfd0be798642fb643f5a7c23aa92e8f1f11fd5619c7dcf8e815c69ce2c1

attachments-2020-05-UJOOqG0f5ed0f229cca80.png

Master上查看集群信息:

attachments-2020-05-kXePjXmS5ed0f277da02d.png

kube-proxy开启ipvs (修改vipmaster即可) (k8s自身对于多个pod的负载均衡尽量采用ipvs lvs

修改ConfigMapkube-system/kube-proxy中的config.conf文件     填写mode: “ipvs”

# kubectl edit cm kube-proxy -n kube-system

attachments-2020-05-FqEKSkFN5ed0f2a3e2d41.png

重制master节点上的kube-proxy pod

# kubectl get pod -n kube-system | grep kube-proxy | awk '{system("kubectl delete pod "$1" -n kube-system")}'

删除后会重新启动新的proxy pod

attachments-2020-05-v2pyFxtV5ed0f2df3b917.png

检查kube-proxy

# kubectl get pod -n kube-system | grep kube-proxy

# kubectl logs kube-proxy-jllpr -n kube-system 查看其中一个的log   日志中需打印出了Using ipvs Proxier


attachments-2020-05-grmx3A6C5ed0f2ed95422.png

还可以使用 # ipvsadm -Ln 来查询kube-proxy的负载均衡情况 


attachments-2020-05-XtuIG4XS5ed0f308378bf.png


接下来我们进行第四步:检测与故障模拟




  • 发表于 2020-05-29 19:16
  • 阅读 ( 86 )
  • 分类:Kubenetes

0 条评论

请先 登录 后评论
zhik8sadm9
zhik8sadm9

运维工程师

10 篇文章

作家榜 »

  1. zhik8sadm9 10 文章
  2. ares 0 文章
  3. jenningszheng 0 文章
  4. Jennings 0 文章
  5. xiechl 0 文章
  6. 阿弱 0 文章
  7. zhqsdhr 0 文章
  8. sunny 0 文章