Skip to content

Commit e3b0b23

Browse files
authored
FEAT: haproxy: Conditionalize config volumeMount subpath (#285)
* FEAT: haproxy: Conditionalize subPath for haproxy-config configmap Submitted-by: Timur-ND Signed-off-by: Antonio Huete Jimenez <[email protected]> * FEATURE/MINOR: haproxy: add basic instructions for haproxy config reload Thanks-to: Timur-ND Signed-off-by: Antonio Huete Jimenez <[email protected]> --------- Signed-off-by: Antonio Huete Jimenez <[email protected]>
1 parent 5172c7d commit e3b0b23

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

haproxy/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,67 @@ extraEnvs:
232232
fieldPath: status.podIP
233233
```
234234

235+
### Automatic configuration reloading
236+
237+
In some cases, configuration changes are frequent and constantly restarting HAProxy is not optimal. For those cases the HAProxy hot-reload feature
238+
can be used.
239+
240+
In master-worker mode, sending a USR2 signal to the HAProxy process will trigger a configuration reload.
241+
242+
```yaml
243+
config: |
244+
global
245+
log stdout format raw local0
246+
master-worker
247+
daemon
248+
maxconn 1024
249+
defaults
250+
log global
251+
timeout client 60s
252+
timeout connect 60s
253+
timeout server 60s
254+
frontend fe_main
255+
mode http
256+
bind :80
257+
http-request redirect scheme https code 301 unless { ssl_fc }
258+
default_backend be_main
259+
backend be_main
260+
mode http
261+
server web1 10.0.0.1:8080 check
262+
```
263+
264+
Make sure you are not specifying subPath for any of your volumeMounts so that Kubernetes will automatically update the volumes created from
265+
ConfigMaps.
266+
267+
And finally, use some sidecar container which will be delivering the signal to the process. The shareProcessNamespace Pod property is required
268+
for the sidecars to be able to access other containers' processes.
269+
270+
```yaml
271+
shareProcessNamespace:
272+
enabled: true
273+
sidecarContainers:
274+
- name: reflex
275+
image: acim/go-reflex:1.17.3
276+
command: ["reflex", "-d", "fancy"]
277+
workingDir: /usr/local/etc/haproxy
278+
args:
279+
- -svr
280+
- "..data"
281+
- --
282+
- bash
283+
- -c
284+
- 'pkill -SIGUSR2 "haproxy|hapee-lb"'
285+
volumeMounts:
286+
- name: haproxy-config
287+
mountPath: /usr/local/etc/haproxy
288+
resources:
289+
limits:
290+
memory: 128Mi
291+
requests:
292+
cpu: 50m
293+
memory: 64Mi
294+
```
295+
235296
## Installing as non-root with binding to privileged ports
236297

237298
To be able to bind to privileged ports such as tcp/80 and tcp/443 without root privileges (UID and GID are set to 1000 in the example, as HAProxy Docker image has UID/GID of 1000 reserved for HAProxy), there is a special workaround required as `NET_BIND_SERVICE` capability is [not propagated](https://github.com/kubernetes/kubernetes/issues/56374), so we need to use `initContainers` feature as well:

haproxy/templates/daemonset.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ spec:
154154
volumeMounts:
155155
- name: haproxy-config
156156
mountPath: {{ .Values.configMount.mountPath }}
157+
{{- if .Values.configMount.subPath }}
157158
subPath: {{ .Values.configMount.subPath }}
159+
{{- end }}
158160
{{- if .Values.includes }}
159161
- name: includes
160162
mountPath: {{ .Values.includesMountPath }}

haproxy/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ spec:
156156
volumeMounts:
157157
- name: haproxy-config
158158
mountPath: {{ .Values.configMount.mountPath }}
159+
{{- if .Values.configMount.subPath }}
159160
subPath: {{ .Values.configMount.subPath }}
161+
{{- end }}
160162
{{- if .Values.includes }}
161163
- name: includes
162164
mountPath: {{ .Values.includesMountPath }}

0 commit comments

Comments
 (0)