Skip to content

CAPD Custom Loadbalancer Config

Richard Case edited this page Oct 30, 2023 · 1 revision

If you want to use the upstream version of CAPD (instead of the fork) you will need to use a custom load banacer config. This is available in CAPI/CAPD v1.6.0 and higher.

The custom load balancer config needs to be created in a configmap in the same namespace as the cluster definitions:

apiVersion: v1
data:
  value: |-
    # generated by kind
    global
      log /dev/log local0
      log /dev/log local1 notice
      daemon
      # limit memory usage to approximately 18 MB
      # (see https://github.com/kubernetes-sigs/kind/pull/3115)
      maxconn 100000

    resolvers docker
      nameserver dns 127.0.0.11:53

    defaults
      log global
      mode tcp
      option dontlognull
      # TODO: tune these
      timeout connect 5000
      timeout client 50000
      timeout server 50000
      # allow to boot despite dns don't resolve backends
      default-server init-addr none

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

    frontend control-plane
      bind *:{{ .FrontendControlPlanePort }}
      {{ if .IPv6 -}}
      bind :::{{ .FrontendControlPlanePort }};
      {{- end }}
      default_backend kube-apiservers

    backend kube-apiservers
      option httpchk GET /healthz
      http-check expect status 401
      # TODO: we should be verifying (!)
      {{range $server, $address := .BackendServers}}
      server {{ $server }} {{ JoinHostPort $address $.BackendControlPlanePort }} check check-ssl verify none resolvers docker resolve-prefer {{ if $.IPv6 -}} ipv6 {{- else -}} ipv4 {{- end }}
      {{- end}}

    frontend rke2-join
      bind *:9345
      {{ if .IPv6 -}}
      bind :::9345;
      {{- end }}
      default_backend rke2-servers

    backend rke2-servers
      option httpchk GET /v1-rke2/readyz
      http-check expect status 403
      {{range $server, $address := .BackendServers}}
      server {{ $server }} {{ $address }}:9345 check check-ssl verify none
      {{- end}}
kind: ConfigMap
metadata:
  name: test-lb-config
  namespace: default

You then need to reference this config map from the DockerCluster definition:

apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerCluster
metadata:
  name: test1
  namespace: default
spec:
  loadBalancer:
    customHAProxyConfigTemplateRef:
      name: test-lb-config
Clone this wiki locally