【问题标题】:HAProxy peering in kubernetesKubernetes 中的 HAProxy 对等互连
【发布时间】:2022-06-15 09:44:22
【问题描述】:

背景

由于我们的应用程序需要为自定义标题使用粘性表格,我们决定使用 HAProxy,我们的布局如下所示:

Nginx Ingress -> HAproxy 服务 -> 有状态应用的无头服务

到目前为止,粘性工作正常,但有一种情况,如果由其他 HAproxy 副本处理,它会失败。我们正在尝试使用同行来解决这个问题。

我使用bitnami helm chart 来部署它,这是我的值文件:

metadata:
  chartName: bitnami/haproxy
  chartVersion: 0.3.7
service:
  type: ClusterIP
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 8080
    - name: https
      protocol: TCP
      port: 443
      targetPort: 8080
    - name: peers
      protocol: TCP
      port: 10000
      targetPort: 10000
containerPorts:
  - name: http
    containerPort: 8080
  - name: https
    containerPort: 8080
  - name: peers
    containerPort: 10000

configuration: |
  global
    log stdout format raw local0 debug

  defaults
    mode http
    option  httplog
    timeout client 10s
    timeout connect 5s
    timeout server 10s
    timeout http-request 10s
    log global

  resolvers default
    nameserver dns1 172.20.0.10:53
    hold timeout         30s
    hold refused         30s
    hold valid           10s

    resolve_retries 3
    timeout retry 3s

  peers hapeers  

    peer $(MY_POD_IP):10000  # I attempted to do something like this
    peer $(REPLICA_2_IP):10000 #

  frontend stats
    bind *:8404
    stats enable
    stats uri /
    stats refresh 10s

  frontend myfrontend
    mode http
    option httplog
    bind *:8080
    default_backend webservers

  backend webservers
    mode http
    log stdout local0 debug
    stick-table type string len 64 size 1m expire 1d peers hapeers
    stick on req.hdr(MyHeader)
    server s1 headless-service-1:8080 resolvers default check port 8080 inter 5s rise 2 fall 20
    server s2 headless-service-2:8080 resolvers default check port 8080 inter 5s rise 2 fall 20
    server s3 headless-service-3:8080 resolvers default check port 8080 inter 5s rise 2 fall 20

replicaCount: 2
extraEnvVars:
  - name: LOG_LEVEL
    value: debug
  - name: MY_POD_IP
    valueFrom:
      fieldRef:
        fieldPath: status.podIP

根据我在 HAProxy 文档中阅读的内容,它需要对等 IP,在本例中是副本 IP。但是,configmap 不允许从 HAProxy 副本注入 IP。

我还想过使用 initContainer 在部署时使用正确的 IP 修改 haproxy.cfg,但该卷是只读的,我必须更改图表的一个分支来自定义它。

如果有人知道不同的方法或解决方法,我将不胜感激 cmets。谢谢!

【问题讨论】:

    标签: kubernetes haproxy kubernetes-statefulset


    【解决方案1】:

    ...the configmap does not allow injecting IPs from the HAProxy replicas.

    HAProxy 的配置支持environment variables。例如。对等 $(MY_POD_IP):10000 => 对等 ${MY_POD_IP}:10000

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 2017-06-08
      • 2017-06-23
      • 1970-01-01
      • 2021-11-08
      相关资源
      最近更新 更多