Backend CRD
The Backend custom resource extends the Kubernetes API to let you manage how traffic is load balanced across pods.
Install the Backend custom resource
Before you can use the Backend custom resource, you must install its definition into your Kubernetes cluster.
-
Install the custom resource definition with
kubectl apply
:Community ingress controller
$ kubectl apply -f https://cdn.haproxy.com/documentation/kubernetes/1.7/community/crd/backend.yaml
-
Verify that the installation worked by listing custom resources defined in your cluster:
$ kubectl get crd
output
NAME CREATED AT backends.core.haproxy.org 2022-01-21T20:00:31Z
Use the Backend custom resource
With the Backend custom resource, you can manage how traffic is load balanced across pods. To use it:
-
Create a YAML file that declares a
Backend
resource and add properties to itsspec.config
section.In the example below, the
balance.algorithm
property changes the load balancing algorithm to least connections.example-backend.yaml
apiVersion: "core.haproxy.org/v1alpha1" kind: Backend metadata: name: example-backend namespace: default spec: config: balance: algorithm: "leastconn"
-
Deploy it to your cluster using
kubectl apply
.$ kubectl apply -f example-backend.yaml
-
Decide which Kubernetes services the resource should apply to. Do one of the following:
-
To have the properties apply to all services, create a new ConfigMap with the name
haproxy-kubernetes-ingress
to override the one that ships with the ingress controller. Add thecr-backend
key to thedata
section to implement the backend properties.example-configmap.yaml
apiVersion: v1 kind: ConfigMap metadata: name: haproxy-kubernetes-ingress namespace: haproxy-controller data: cr-backend: default/example-backend
Update the ConfigMap in your cluster by using
kubectl apply
:$ kubectl apply -f example-configmap.yaml
-
To have the properties apply to all services that the Ingress routes traffic to, add the
cr-backend
annotation to your Ingress definition . The Ingress below applies to the services example-service1 and example-service2:example-ingress.yaml
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress annotations: haproxy.org/cr-backend: default/example-backend spec: rules: - http: paths: - path: /example1 pathType: Prefix backend: service: name: example-service1 port: number: 80 - path: /example2 pathType: Prefix backend: service: name: example-service2 port: number: 80
Update the Ingress in your cluster by using
kubectl apply
:$ kubectl apply -f example-ingress.yaml
-
To have the properties apply to only a specific Kubernetes service, add the
cr-backend
annotation to your Service definition. The Service below applies the properties only to the service named example-service1.example-service.yaml
apiVersion: v1 kind: Service metadata: labels: run: app name: example-service1 annotations: haproxy.org/cr-backend: default/example-backend spec: selector: run: app ports: - name: http port: 80 protocol: TCP targetPort: 8080
Update the Service in your cluster by using
kubectl apply
:$ kubectl apply -f example-service.yaml
-
Backend custom resource reference
Version: core.haproxy.org/v1alpha1
abortonclose
Type | Values |
---|---|
string | enabled, disabled |
adv_check
Type | Values |
---|---|
string | ssl-hello-chk, smtpchk, ldap-check, mysql-check, pgsql-check, tcp-check, redis-check, httpchk |
allbackups
Type | Values |
---|---|
string | enabled, disabled |
balance
Type | Values | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||||||||||||||||||||||||||||||||
Child properties
|
bind_process
Type | Values |
---|---|
string |
check_timeout
Type | Values |
---|---|
integer |
connect_timeout
Type | Values |
---|---|
integer |
cookie
Type | Values | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||||||||||||||||||||||||||||||||
Child properties
|
default_server
Type | Values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Child properties
|
external_check
Type | Values |
---|---|
string | enabled, disabled |
external_check_command
Type | Values |
---|---|
string |
external_check_path
Type | Values |
---|---|
string |
forwardfor
Type | Values | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||||||||
Child properties
|
hash_type
Type | Values | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | |||||||||||||
Child properties
|
http-buffer-request
Type | Values |
---|---|
string | enabled, disabled |
http-check
Type | Values | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||||||||
Child properties
|
http-use-htx
Type | Values |
---|---|
string | enabled, disabled |
http_connection_mode
Type | Values |
---|---|
string | httpclose, http-server-close, http-keep-alive |
http_keep_alive_timeout
Type | Values |
---|---|
integer |
http_pretend_keepalive
Type | Values |
---|---|
string | enabled, disabled |
http_request_timeout
Type | Values |
---|---|
integer |
http_reuse
Type | Values |
---|---|
string | aggressive, always, never, safe |
httpchk_params
Type | Values | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | |||||||||||||
Child properties
|
log_tag
Type | Values |
---|---|
string |
mode
Type | Values |
---|---|
string | http, tcp |
mysql_check_params
Type | Values | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||
Child properties
|
name
Type | Values |
---|---|
string |
pgsql_check_params
Type | Values | ||||||
---|---|---|---|---|---|---|---|
object | |||||||
Child properties
|
queue_timeout
Type | Values |
---|---|
integer |
redispatch
Type | Values | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||
Child properties
|
retries
Type | Values |
---|---|
integer |
server_timeout
Type | Values |
---|---|
integer |
smtpchk_params
Type | Values | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||
Child properties
|
stats_options
Type | Values | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | ||||||||||||||||||||||||||||
Child properties
|
stick_table
Type | Values | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | |||||||||||||||||||||||||
Child properties
|
tunnel_timeout
Type | Values |
---|---|
integer |
Next up
Defaults CRD