Giter VIP home page Giter VIP logo

ha-k8s's Introduction

##大致环境说明一下
有两台master 一台是192.168.11.122 , 192.168.11.118 ,
122的网卡名为eth0,118的网卡名为eth0,
这个在keepalived的docker要注意一下,
122上面有安装kubernetes,
而118上没有安装,
所以用nc来开一个6443的端口来模拟api-server的服务

192.168.11.127是VIP
haproxy和keepalived镜像地址:
docker pull qjpoo/haproxy-k8s
docker pull qjpoo/keepalived-k8s
###haproxy.cfg 配置文件,放在了/tmp/a目录下面

cat haproxy.cfg

global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
#chroot /usr/share/haproxy
#user haproxy
#group haproxy
daemon

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  50000
    timeout server  50000

frontend stats-front
  bind *:8081
  mode http
  default_backend stats-back

frontend fe_k8s_6444
  bind *:6444
  mode tcp
  timeout client 1h
  log global
  option tcplog
  default_backend be_k8s_6443
  acl is_websocket hdr(Upgrade) -i WebSocket
  acl is_websocket hdr_beg(Host) -i ws

backend stats-back
  mode http
  balance roundrobin
  stats uri /haproxy/stats
  stats auth pxcstats:secret

backend be_k8s_6443
  mode tcp
  timeout queue 1h
  timeout server 1h
  timeout connect 1h
  log global
  balance roundrobin
  server master01 192.168.11.122:6443 check inter 2000 rise 2 fall 3
  server master02 192.168.11.118:6443 check inter 2000 rise 2 fall 3

192,168.11.122上执行

docker run -d --restart=always \
--name haproxy \
-p 6444:6444 \
-e MasterIP1=192.168.11.122 \
-e MasterIP2=192.168.11.118 \
-e MasterPort=6443 \
-v /tmp/a/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg \
qjpoo/haproxy-k8s
docker run -itd --restart=always \
--name=keepalived \
--net=host --cap-add=NET_ADMIN \
-e VIRTUAL_IP=192.168.11.127 \
-e INTERFACE=eth0 \
-e CHECK_PORT=6444 \
-e RID=10 \
-e VRID=160 \
-e NETMASK_BIT=24 \
-e MCAST_GROUP=224.0.0.18 \
qjpoo/keepalived-k8s

###在192.168.11.118上执行 由于我在118上没有安装kubernetes,所以用nc来模拟一个6443的端口 nc -l -k 6443

docker run -d --restart=always \
--name haproxy \
-p 6444:6444 \
-e MasterIP1=192.168.11.122 \
-e MasterIP2=192.168.11.118 \
-e MasterPort=6443 \
-v /tmp/a/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg \
qjpoo/haproxy-k8s
docker run -itd --restart=always --name=keepalived \
--net=host --cap-add=NET_ADMIN \
-e VIRTUAL_IP=192.168.11.127 \
-e INTERFACE=ens3 \
-e CHECK_PORT=6444 \
-e RID=10 \
-e VRID=160 \
-e NETMASK_BIT=24 \
-eMCAST_GROUP=224.0.0.18 \
qjpoo/keepalived-k8s

测试

1)首先把192.168.11.122上的haproxy停用,看vip会不会到192.168.11.118上
image
image
image

2)首先把192.168.11.122上的keepalived停用,看vip会不会到192.168.11.118上, tcping test image


没有配置成抢占模式,当192.168.11.122业务都恢复正常了之后,VIP是不会到192.168.11.118上面的来

ha-k8s's People

Contributors

qjpoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.