-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaproxy-statefulset.yaml
69 lines (69 loc) · 2.11 KB
/
haproxy-statefulset.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: haproxy
namespace: jitsi
labels:
k8s-app: haproxy
spec:
replicas: 2 # use two replicas for high availability
serviceName: haproxy
selector:
matchLabels:
k8s-app: haproxy
template:
metadata:
labels:
k8s-app: haproxy
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '9090'
spec:
affinity:
# HAProxy pods should run in different availability zones
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- haproxy
topologyKey: "topology.kubernetes.io/zone"
volumes:
- name: haproxy-config
configMap:
name: haproxy-config
items:
- key: haproxy.cfg
path: haproxy.cfg
containers:
- name: haproxy
image: haproxy:2.1
# enable peering between HAProxy-pods
# look up ip address of other HAProxy instance and export it
# those variables are then used in haproxy.cfg defined in ./haproxy-configmap.yaml
command: ["bash", "-c"]
args:
- >-
apt-get update && apt-get install -y dnsutils;
[[ $HOSTNAME = 'haproxy-1' ]] &&
export OTHER_HOSTNAME=haproxy-0 OTHER_IP=$(nslookup haproxy-0 | awk 'NR==5 {print $2}') ||
export OTHER_HOSTNAME=haproxy-1 OTHER_IP=$(nslookup haproxy-1 | awk 'NR==5 {print $2}');
exec /docker-entrypoint.sh haproxy -f /usr/local/etc/haproxy/haproxy.cfg
env:
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
ports:
- name: http
containerPort: 80
- name: metrics
containerPort: 9090
- name: peering
containerPort: 1024
volumeMounts:
- mountPath: /usr/local/etc/haproxy/haproxy.cfg
name: haproxy-config
subPath: haproxy.cfg