|
| 1 | +# Custom Resources |
| 2 | + |
| 3 | +- In order to use custom resources, you will need to apply/update resource [definitions](../crs/definition/) |
| 4 | +- Custom Resources are used by Ingress Controller to implement HAProxy concepts like (backend, frontend, http rules, etc) which are all available under the `core.haproxy.org` API. |
| 5 | +- Current implementation relies on the [client-native](https://github.com/haproxytech/client-native) library and its [models](https://github.com/haproxytech/client-native/tree/master/models) to [configure HAProxy](https://cbonte.github.io/haproxy-dconv/2.4/configuration.html#4.1). |
| 6 | +- Custom resources are meant to **replace annotations** when possible. So they will have **precedance** when used. |
| 7 | + *Example:* if the backend resource is used no backend annotation will be processed which means a backend cannot be configured by mixing both the backend resource and backend annotations. |
| 8 | + |
| 9 | +## HAProxy concepts |
| 10 | +- Only HAProxy directives available in the resource [definitions](../crs/definition/) are supported, contributions and github requests to support new directives are welcome. |
| 11 | +- All timeout fields are integer input interpreted as time in **ms**. |
| 12 | + |
| 13 | +### Global |
| 14 | +The Global resource is used to configure the HAProxy global section by referencing the resouce via the `cr-global` annotation in the Ingress Controller ConfigMap. |
| 15 | + |
| 16 | +*Example:* |
| 17 | + |
| 18 | +1. Define a global resource |
| 19 | +```yaml |
| 20 | +apiVersion: "core.haproxy.org/v1alpha1" |
| 21 | +kind: Global |
| 22 | +metadata: |
| 23 | + name: myglobal |
| 24 | + namespace: haproxy-controller |
| 25 | +spec: |
| 26 | + config: |
| 27 | + maxconn: 1000 |
| 28 | + stats_timeout: 36000 |
| 29 | + tune_ssl_default_dh_param: 2048 |
| 30 | + ssl_default_bind_options: "no-sslv3 no-tls-tickets no-tlsv10" |
| 31 | + ssl_default_bind_ciphers: ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK |
| 32 | + hard_stop_after: 30000 |
| 33 | + server_state_base: /tmp/haproxy-ingress/state |
| 34 | + runtime_apis: |
| 35 | + - address: "0.0.0.0:31024" |
| 36 | +``` |
| 37 | +
|
| 38 | +2. Apply it: |
| 39 | +``` |
| 40 | +$ kubectl apply -f myglobal.yaml |
| 41 | +``` |
| 42 | + |
| 43 | +3. Update the ConfigMap |
| 44 | +``` |
| 45 | +apiVersion: v1 |
| 46 | +kind: ConfigMap |
| 47 | +metadata: |
| 48 | + name: kubernetes-ingress |
| 49 | + namespace: haproxy-controller |
| 50 | +data: |
| 51 | + cr-global: haproxy-controller/myglobal |
| 52 | +``` |
| 53 | + |
| 54 | +### Defaults |
| 55 | +The Defaults resource is used to configure the HAProxy defaults section by referencing the resouce via the `cr-defaults` annotation in the Ingress Controller ConfigMap. |
| 56 | + |
| 57 | +*Example:* |
| 58 | + |
| 59 | +1. Define a defaults resource |
| 60 | +```yaml |
| 61 | +apiVersion: "core.haproxy.org/v1alpha1" |
| 62 | +kind: Defaults |
| 63 | +metadata: |
| 64 | + name: mydefaults |
| 65 | + namespace: default |
| 66 | +spec: |
| 67 | + config: |
| 68 | + log_format: "'%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs \"%HM %[var(txn.base)] %HV\"'" |
| 69 | + redispatch: |
| 70 | + enabled: enabled |
| 71 | + interval: 0 |
| 72 | + dontlognull: enabled |
| 73 | + http_connection_mode: http-keep-alive |
| 74 | + http_request_timeout: 5000 |
| 75 | + connect_timeout: 5000 |
| 76 | + client_timeout: 50000 |
| 77 | + queue_timeout: 5000 |
| 78 | + server_timeout: 50000 |
| 79 | + tunnel_timeout: 3600000 |
| 80 | + http_keep_alive_timeout: 60000 |
| 81 | +``` |
| 82 | +
|
| 83 | +2. Apply it: |
| 84 | +``` |
| 85 | +$ kubectl apply -f mydefaults.yml |
| 86 | +``` |
| 87 | + |
| 88 | +3. Update the ConfigMap |
| 89 | +```yaml |
| 90 | +apiVersion: v1 |
| 91 | +kind: ConfigMap |
| 92 | +metadata: |
| 93 | + name: kubernetes-ingress |
| 94 | + namespace: haproxy-controller |
| 95 | +data: |
| 96 | + cr-global: haproxy-controller/myglobal |
| 97 | + cr-defaults: haproxy-controller/mydefaults |
| 98 | +``` |
| 99 | +
|
| 100 | +
|
| 101 | +### Backend |
| 102 | +The Backend resource is used to configure the HAProxy backend section by referencing the resouce via the `cr-backend` annotation in corresponding backend service. |
| 103 | +`cr-backend` annotation can be used also at the ConfigMap level (as default backend config for all services) or Ingress level (as a default backend config for the underlying services) |
| 104 | + |
| 105 | +*Example:* |
| 106 | + |
| 107 | +1. Define a backend resource |
| 108 | +```yaml |
| 109 | +apiVersion: "core.haproxy.org/v1alpha1" |
| 110 | +kind: Backend |
| 111 | +metadata: |
| 112 | + name: mybackend |
| 113 | + namespace: haproxy-controller |
| 114 | +spec: |
| 115 | + config: |
| 116 | + mode: http |
| 117 | + balance: |
| 118 | + algorithm: "leastconn" |
| 119 | + abortonclose: disabled |
| 120 | + default_server: |
| 121 | + verify: none |
| 122 | + resolve-prefer: ipv4 |
| 123 | + check-sni: example.com |
| 124 | + sni: str(example.com) |
| 125 | +``` |
| 126 | + |
| 127 | +2. Apply it: |
| 128 | +``` |
| 129 | +$ kubectl apply -f mybackend.yaml |
| 130 | +``` |
| 131 | + |
| 132 | +3. Annotate the corresponding service |
| 133 | +```yaml |
| 134 | +apiVersion: v1 |
| 135 | +kind: Service |
| 136 | +metadata: |
| 137 | + name: example |
| 138 | + namespace: external |
| 139 | + annotations: |
| 140 | + cr-backend: haproxy-controller/mybackend |
| 141 | +spec: |
| 142 | + type: ExternalName |
| 143 | + externalName: example.com |
| 144 | + ports: |
| 145 | + - protocol: TCP |
| 146 | + port: 443 |
| 147 | + name: https |
| 148 | + targetPort: 443 |
| 149 | +``` |
0 commit comments