[关闭]
@zhangyy 2020-01-17T15:45:23.000000Z 字数 4398 阅读 180

kubernetes 的多节点集群与高可用配置

kubernetes系列


  • 一: kubernetes master 节点的 高可用

  • 二: 配置nginx 服务器

  • 三: 配置nginx 的LB 的 keepalived 高可用


一: kubernetes master 节点的 高可用

  1. kubernetes 的多master集群架构
  2. kubernetes 高可用主要在于apiserver

image_1dkhotd53bpl9cl1s82qt0g8e9.png-519.8kB

  1. 部署master01 IP 地址: 192.168.100.12
  2. 192.168.100.12 部署与 master01 一样的 服务
  3. scp -r /opt/kubernetes/ root@192.168.100.12:/opt/
  4. scp -r /opt/etcd/ root@192.168.100.12:/opt/
  5. scp /usr/bin/kubectl root@192.168.20.12:/usr/bin/
  6. scp /usr/lib/systemd/system/kube-* root@192.168.100.12:/usr/lib/systemd/system/

image_1dkhpddb51u5g3s17ra1ktmbjs16.png-711kB

image_1dkhvjrhh2t1ilu56n1knh1ldm3n.png-271.7kB

image_1dki04i9s1inp11uo19l7qp0f074g.png-111.3kB

image_1dkhpdthu1da6tcarpb19mf1avk1j.png-214.9kB


  1. 修改 配置文件
  2. cd /opt/kubernetes/cfg
  3. vim kube-apiserver
  4. ---
  5. --bind-address=192.168.100.12
  6. --advertise-address=192.168.100.12

image_1dkhpivse19oi49k1iie135c1tvt20.png-428.3kB

  1. 启动服务:
  2. service kube-apiserver start
  3. service kube-controller-manager start
  4. service kube-scheduler start

image_1dkhpojvi150r10eltli5l19i42d.png-332.5kB

image_1dkhq05d01qfcldj1a5e9qt2u3a.png-558.4kB

1.png-490.1kB


  1. login :
  2. 192.168.20.12
  3. kubectl get cs

image_1dki06f5p16mq1aq11j7l116gs1h4t.png-180.2kB

配置负载均衡nginx

  1. nginx 服务器 地址: 192.168.100.15
  2. nginx yum 包地址
  3. http://nginx.org/en/linux_packages.html
  4. cd /etc/yum.repos.d/
  5. vim nginx.repo
  6. ---
  7. [nginx-stable]
  8. name=nginx stable repo
  9. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  10. gpgcheck=1
  11. enabled=1
  12. gpgkey=https://nginx.org/keys/nginx_signing.key
  13. [nginx-mainline]
  14. name=nginx mainline repo
  15. baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
  16. gpgcheck=1
  17. enabled=0
  18. gpgkey=https://nginx.org/keys/nginx_signing.key
  19. ---
  1. yum install nignx

image_1dki10vsl1g5f1tdj2q1i513tv5a.png-399.3kB


image_1dki139jv1vsg18d314m719vp1cec5n.png-404.7kB

  1. cd /etc/nginx/
  2. vim nginx.conf
  3. 增加:
  4. ---
  5. stream {
  6. log_format main "$remote_addr $upstream_addr $time_local $status";
  7. access_log /var/log/nginx/k8s-access.log main;
  8. upstream k8s-apiserver {
  9. server 192.168.100.11:6443;
  10. server 192.168.100.12:6443;
  11. }
  12. server {
  13. listen 192.168.100.15:6443;
  14. proxy_pass k8s-apiserver;
  15. }
  16. }

2.png-180.6kB

image_1dki1l9jeuaotgklfprf81gan71.png-335.4kB

···

  1. 修改node 节点的 master 服务器指向
  2. login : 192.168.20.13
  3. cd /opt/kubernetes/cfg/
  4. vim bootstrap.kubeconfig
  5. ---
  6. server: https://192.168.100.11:6443 改成:
  7. server: https://192.168.100.15:6443
  8. ---
  9. vim kubelet.kubeconfig
  10. ----
  11. server: https://192.168.100.11:6443 改成:
  12. server: https://192.168.100.15:6443
  13. ----
  14. vim kube-proxy.kubeconfig
  15. ----
  16. server: https://192.168.100.11:6443 改成:
  17. server: https://192.168.100.15:6443
  18. ----
  19. scp bootstrap.kubeconfig kubelet.kubeconfig kube-proxy.kubeconfig root@192.168.100.14:/opt/kubernetes/cfg/

image_1dki27qdl7341bb71d0gd8211357u.png-196.4kB

  1. 重新启动 node 节点的 kubelet kube-proxy
  2. service kubelet restart
  3. service kube-proxy restart

image_1dki2cv411gei28h1g501jdb17768b.png-130.9kB

image_1dki2g6sk72b1o0u1joplmk100h95.png-365.1kB
image_1dki2erf51sl4t6885h14he1cpf8o.png-400.4kB

  1. 使用 主节点 配置 测试
  2. kubectl get nodes

image_1dki36rt7vef1tvjpbk150f1l2q12.png-246.5kB

image_1dki35tv1kp93cu9651bj415s29.png-345.8kB

三: 配置nginx 的LB 的 keepalived 高可用

  1. login 192.168.100.16
  2. 安装nginx 服务器 同上 192.168.100.15 一样
  3. 修改
  4. vim /etc/nginx/nginx.conf
  5. ----
  6. stream {
  7. log_format main "$remote_addr $upstream_addr $time_local $status";
  8. access_log /var/log/nginx/k8s-access.log main;
  9. upstream k8s-apiserver {
  10. server 192.168.100.11:6443;
  11. server 192.168.100.12:6443;
  12. }
  13. server {
  14. listen 192.168.100.16:6443;
  15. proxy_pass k8s-apiserver;
  16. }
  17. }
  18. ---
  19. service nginx start

image_1dki55f8bh2dtjn10vclvv1bet2v.png-367.7kB

  1. 配置keepalive 高可用
  2. yum install keepalived
  3. keepalived 的配置文件
  4. cd /etc/keepalived/
  5. vim keepalived.conf
  6. ---
  7. ! Configuration File for keepalived
  8. global_defs {
  9. # 接收邮件地址
  10. notification_email {
  11. acassen@firewall.loc
  12. failover@firewall.loc
  13. sysadmin@firewall.loc
  14. }
  15. # 邮件发送地址
  16. notification_email_from Alexandre.Cassen@firewall.loc
  17. smtp_server 127.0.0.1
  18. smtp_connect_timeout 30
  19. router_id NGINX_MASTER
  20. }
  21. vrrp_script check_nginx {
  22. script "/etc/keepalived/check_nginx.sh"
  23. }
  24. vrrp_instance VI_1 {
  25. state MASTER
  26. interface ens33
  27. virtual_router_id 51 # VRRP 路由 ID实例,每个实例是唯一的
  28. priority 100 # 优先级,备192.168.100.16服务器设置 90
  29. advert_int 1 # 指定VRRP 心跳包通告间隔时间,默认1秒
  30. authentication {
  31. auth_type PASS
  32. auth_pass 1111
  33. }
  34. virtual_ipaddress {
  35. 192.168.100.70/24
  36. }
  37. track_script {
  38. check_nginx
  39. }
  40. }
  41. ----
  42. 配置 检查 nginx 进程 检查
  43. cd /etc/keepalived/
  44. vim check_nginx.sh
  45. ---
  46. #!/bin/bash
  47. count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
  48. if [ "$count" -eq 0 ];then
  49. /etc/init.d/keepalived stop
  50. fi
  51. ---
  1. service keepalived start
  2. ps -ef |grep keepalived

image_1dki6q3gm1qameqk1v5n1tr1nd23c.png-664.4kB

  1. cd /etc/keepalived
  2. scp check_nginx.sh keepalived.conf root@192.168.100.16:/etc/keepalived/

  1. login: 192.168.100.16
  2. cd /etc/keepalived/
  3. vim keepalived.conf
  4. ---
  5. priority 100 priority 90
  6. ----
  7. serivice keepalived start
  8. ps -ef |grep keepalived

image_1dki71lik1prc1vhg1nlni7t3ja3s.png-311.9kB


  1. node 节点的 IP 地址
  2. 修改node 节点的 master 服务器指向
  3. login : 192.168.20.13
  4. cd /opt/kubernetes/cfg/
  5. vim bootstrap.kubeconfig
  6. ---
  7. server: https://192.168.100.15:6443 改成:
  8. server: https://192.168.100.70:6443
  9. ---
  10. vim kubelet.kubeconfig
  11. ----
  12. server: https://192.168.100.15:6443 改成:
  13. server: https://192.168.100.70:6443
  14. ----
  15. vim kube-proxy.kubeconfig
  16. ----
  17. server: https://192.168.100.15:6443 改成:
  18. server: https://192.168.100.70:6443
  19. ----
  20. scp bootstrap.kubeconfig kubelet.kubeconfig kube-proxy.kubeconfig root@192.168.100.14:/opt/kubernetes/cfg/

  1. 重新启动 node 节点的 kubelet kube-proxy
  2. service kubelet restart
  3. service kube-proxy restart

image_1dki82iapuip56n1o0aj3k5f949.png-169.5kB

image_1dki838n61jej1a13k0oa4is644m.png-173.4kB

  1. login: 192.168.100.15
  2. 修改 nginx 配置文件
  3. cd /etc/nginx/
  4. vim nginx.conf
  5. ----
  6. linsten 192.168.100.156443 改为: 0.0.0.06443
  7. ----
  8. service nginx restart

image_1dki8amqm8uo1dg24961t36cnp53.png-123.6kB
image_1dki8b5tl141gglj1gkkr2v1g2p5g.png-140kB

  1. login: 192.168.100.16
  2. 修改 nginx 配置文件
  3. cd /etc/nginx/
  4. vim nginx.conf
  5. ----
  6. linsten 192.168.100.166443 改为: 0.0.0.06443
  7. ----
  8. service nginx restart

image_1dki8k1tj1q6b1oc817n8f1a10e46a.png-237.2kB

image_1dki8j2hc1c44mb17ht2pr1vdb5t.png-103.4kB

  1. master01 节点上面查看
  2. kubectl get svc
  3. kubectl get svc,pods -n kube-system --all-namespaces

image_1dki8nr8rol3n41pnu58510jr77.png-187.9kB

image_1dki8pe9b1ev0i601thf1v52ou37k.png-298kB

  1. master02 节点上面查看
  2. kubectl get svc
  3. kubectl get svc,pods -n kube-system --all-namespaces

image_1dki8rlou15q011e916vp11hq1cuk81.png-443kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注