Skip to content

Commit faac9e1

Browse files
authored
Merge pull request #460 from caiyixiang/scaling_haproxy
add example of 'run multiple haproxy ingress controllers as a deployment'
2 parents 35e4311 + ee63e45 commit faac9e1

File tree

4 files changed

+155
-2
lines changed

4 files changed

+155
-2
lines changed

examples/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Re-encrypty | terminate, apply routing rules, re-encrypt | nginx | Advanced
2828

2929
Name | Description | Platform | Complexity Level
3030
-----| ----------- | ---------- | ----------------
31-
Daemonset | run multiple controllers in a daemonset | nginx | Intermediate
32-
Deployment | run multiple controllers as a deployment | nginx | Intermediate
31+
Daemonset | run multiple controllers in a daemonset | nginx/haproxy | Intermediate
32+
Deployment | run multiple controllers as a deployment | nginx/haproxy | Intermediate
3333
Multi-zone | bridge different zones in a single cluster | gce | Intermediate
3434
Static-ip | a single ingress gets a single static ip | * | Intermediate
3535
Geo-routing | route to geographically closest endpoint | nginx | Advanced
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Deploying multi Haproxy Ingress Controllers
2+
3+
This example aims to demonstrate the Deployment of multi haproxy ingress controllers.
4+
5+
## Prerequisites
6+
7+
This ingress controller doesn't yet have support for
8+
[ingress classes](/examples/PREREQUISITES.md#ingress-class). You MUST turn
9+
down any existing ingress controllers before running HAProxy Ingress controller or
10+
they will fight for Ingresses. This includes any cloudprovider controller.
11+
12+
This document has also the following prerequisites:
13+
14+
* Create a [TLS secret](/examples/PREREQUISITES.md#tls-certificates) named `tls-secret` to be used as default TLS certificate
15+
16+
Creating the TLS secret:
17+
18+
```console
19+
$ openssl req \
20+
-x509 -newkey rsa:2048 -nodes -days 365 \
21+
-keyout tls.key -out tls.crt -subj '/CN=localhost'
22+
$ kubectl create secret tls tls-secret --cert=tls.crt --key=tls.key
23+
$ rm -v tls.crt tls.key
24+
```
25+
26+
## Default Backend
27+
28+
The default backend is a service of handling all url paths and hosts the haproxy controller doesn't understand. Deploy the default-http-backend as follow:
29+
30+
```console
31+
$ kubectl create -f default-backend.yaml
32+
deployment "default-http-backend" created
33+
service "default-http-backend" created
34+
35+
$ kubectl get svc
36+
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
37+
default-http-backend 192.168.3.4 <none> 80/TCP 30m
38+
39+
$ kubectl get pods
40+
NAME READY STATUS RESTARTS AGE
41+
default-http-backend-q5sb6 1/1 Running 0 30m
42+
```
43+
44+
## Ingress Deployment
45+
46+
Deploy the Deployment of multi controllers as follows:
47+
48+
```console
49+
$ kubectl apply -f haproxy-ingress-deployment.yaml
50+
deployment "haproxy-ingress" created
51+
```
52+
53+
Check if the controller was successfully deployed:
54+
```console
55+
$ kubectl get deployment
56+
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
57+
default-http-backend 1 1 1 1 30m
58+
haproxy-ingress 2 2 2 2 45s
59+
60+
$ kubectl get pods
61+
NAME READY STATUS RESTARTS AGE
62+
default-http-backend-q5sb6 1/1 Running 0 35m
63+
haproxy-ingress-1779899633-k045t 1/1 Running 0 1m
64+
haproxy-ingress-1779899633-mhthv 1/1 Running 0 1m
65+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: default-http-backend
5+
labels:
6+
k8s-app: default-http-backend
7+
spec:
8+
replicas: 1
9+
template:
10+
metadata:
11+
labels:
12+
k8s-app: default-http-backend
13+
spec:
14+
terminationGracePeriodSeconds: 60
15+
containers:
16+
- name: default-http-backend
17+
# Any image is permissable as long as:
18+
# 1. It serves a 404 page at /
19+
# 2. It serves 200 on a /healthz endpoint
20+
image: gcr.io/google_containers/defaultbackend:1.0
21+
livenessProbe:
22+
httpGet:
23+
path: /healthz
24+
port: 8080
25+
scheme: HTTP
26+
initialDelaySeconds: 30
27+
timeoutSeconds: 5
28+
ports:
29+
- containerPort: 8080
30+
resources:
31+
limits:
32+
cpu: 10m
33+
memory: 20Mi
34+
requests:
35+
cpu: 10m
36+
memory: 20Mi
37+
---
38+
apiVersion: v1
39+
kind: Service
40+
metadata:
41+
name: default-http-backend
42+
labels:
43+
k8s-app: default-http-backend
44+
spec:
45+
ports:
46+
- port: 80
47+
targetPort: 8080
48+
selector:
49+
k8s-app: default-http-backend
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
run: haproxy-ingress
6+
name: haproxy-ingress
7+
spec:
8+
replicas: 2
9+
selector:
10+
matchLabels:
11+
run: haproxy-ingress
12+
template:
13+
metadata:
14+
labels:
15+
run: haproxy-ingress
16+
spec:
17+
containers:
18+
- name: haproxy-ingress
19+
image: quay.io/jcmoraisjr/haproxy-ingress
20+
imagePullPolicy: IfNotPresent
21+
args:
22+
- --default-backend-service=default/default-http-backend
23+
- --default-ssl-certificate=default/tls-secret
24+
ports:
25+
- name: http
26+
containerPort: 80
27+
- name: https
28+
containerPort: 443
29+
- name: stat
30+
containerPort: 1936
31+
env:
32+
- name: POD_NAME
33+
valueFrom:
34+
fieldRef:
35+
fieldPath: metadata.name
36+
- name: POD_NAMESPACE
37+
valueFrom:
38+
fieldRef:
39+
fieldPath: metadata.namespace

0 commit comments

Comments
 (0)