Kubernetes haproxy load balancer with tcp services not forwarded

11/9/2021

I'm currently trying to autoscale my tcp services with kubernetes. I'm not using cloud infrastructure(amazon, aws..etc) so i use haproxy for load balancing. my tcp service isn't http protocol so i added my services with --configmap-tcp-services argument.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: prokittest
    spec:
      replicas: 1
      selector:
        matchLabels:
            app: prokit-server-label
      template:
        metadata:
          labels:
            app: prokit-server-label
        spec:
          volumes:
          - name: host-volume
            hostPath: 
              path: /cosmo/
              type: DirectoryOrCreate
          containers:
          - name: flask-web-server
            image: jakgon/app:2.2
            securityContext:
              privileged: true
            volumeMounts:
            - name: host-volume
              mountPath: /node/plugins
            env:
            - name: POD_HOSTNAME
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SERVER_GROUP
              value: "lobby"
            - name: MAX_PLAYER
              value: "100"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            ports:
            - name: server-port
              containerPort: 25565
            - name: healthz-checker
              containerPort: 8088
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: prokittest
      annotations:
        haproxy.org/send-proxy-protocol: proxy-v2
        haproxy.org/load-balance: "leastconn"
        haproxy.org/check: "true"
        haproxy.org/check-interval: "10s"
      labels:
        run: prokittest
        app: service-monitor-label
    spec:
      selector:
        app: prokit-server-label
      ports:
      - name: server-port
        port: 25565
      - name: healthz-checker
        port: 8088
        targetPort: 8088
    ---
    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: blog-service-monitor
      labels:
        release: prometheus-operator
    spec:
      selector:
        matchLabels:
            app: service-monitor-label
      endpoints:
      - port: healthz-checker

and following is my configmap for configmap-tcp-services

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: default
data:
  9000: "cosmoage/prokittest:25565"

After this applies, haproxy.cfg automatically changed when service pod resizing. But, I can't access to haproxy server without port-forwarding manually like this:

kubectl port-forward [[ingress pod name]] 9000:9000 --address 0.0.0.0

Am i misunderstanding about haproxy ConfigMap? ingress pod name is not fixed so port forward is not a good idea for using.

-- ChuYong
docker
haproxy
kubernetes
yaml

0 Answers