-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from aledbf/set-headers
Add support for custom proxy headers using a ConfigMap
- Loading branch information
Showing
11 changed files
with
254 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Deploying the Nginx Ingress controller | ||
|
||
This example aims to demonstrate the deployment of an nginx ingress controller and | ||
use a ConfigMap to configure a custom list of headers to be passed to the upstream | ||
server | ||
|
||
## Default Backend | ||
|
||
The default backend is a Service capable of handling all url paths and hosts the | ||
nginx controller doesn't understand. This most basic implementation just returns | ||
a 404 page: | ||
|
||
```console | ||
$ kubectl apply -f default-backend.yaml | ||
deployment "default-http-backend" created | ||
service "default-http-backend" created | ||
|
||
$ kubectl -n kube-system get po | ||
NAME READY STATUS RESTARTS AGE | ||
default-http-backend-2657704409-qgwdd 1/1 Running 0 28s | ||
``` | ||
|
||
## Custom configuration | ||
|
||
```console | ||
$ cat nginx-load-balancer-conf.yaml | ||
apiVersion: v1 | ||
data: | ||
proxy-set-headers: "default/custom-headers" | ||
kind: ConfigMap | ||
metadata: | ||
name: nginx-load-balancer-conf | ||
``` | ||
|
||
```console | ||
$ kubectl create -f nginx-load-balancer-conf.yaml | ||
``` | ||
|
||
## Custom headers | ||
|
||
```console | ||
$ cat custom-headers.yaml | ||
apiVersion: v1 | ||
data: | ||
X-Different-Name: "true" | ||
X-Request-Start: t=${msec} | ||
X-Using-Nginx-Controller: "true" | ||
kind: ConfigMap | ||
metadata: | ||
name: proxy-headers | ||
namespace: default | ||
|
||
``` | ||
|
||
```console | ||
$ kubectl create -f custom-headers.yaml | ||
``` | ||
|
||
## Controller | ||
|
||
You can deploy the controller as follows: | ||
|
||
```console | ||
$ kubectl apply -f nginx-ingress-controller.yaml | ||
deployment "nginx-ingress-controller" created | ||
|
||
$ kubectl -n kube-system get po | ||
NAME READY STATUS RESTARTS AGE | ||
default-http-backend-2657704409-qgwdd 1/1 Running 0 2m | ||
nginx-ingress-controller-873061567-4n3k2 1/1 Running 0 42s | ||
``` | ||
|
||
## Test | ||
|
||
Check the contents of the configmap is present in the nginx.conf file using: | ||
`kubectl exec nginx-ingress-controller-873061567-4n3k2 -n kube-system cat /etc/nginx/nginx.conf` |
9 changes: 9 additions & 0 deletions
9
examples/customization/custom-headers/nginx/custom-headers.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: v1 | ||
data: | ||
X-Different-Name: "true" | ||
X-Request-Start: t=${msec} | ||
X-Using-Nginx-Controller: "true" | ||
kind: ConfigMap | ||
metadata: | ||
name: proxy-headers | ||
namespace: kube-system |
51 changes: 51 additions & 0 deletions
51
examples/customization/custom-headers/nginx/default-backend.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: default-http-backend | ||
labels: | ||
k8s-app: default-http-backend | ||
namespace: kube-system | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: default-http-backend | ||
spec: | ||
terminationGracePeriodSeconds: 60 | ||
containers: | ||
- name: default-http-backend | ||
# Any image is permissable as long as: | ||
# 1. It serves a 404 page at / | ||
# 2. It serves 200 on a /healthz endpoint | ||
image: gcr.io/google_containers/defaultbackend:1.0 | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8080 | ||
scheme: HTTP | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 5 | ||
ports: | ||
- containerPort: 8080 | ||
resources: | ||
limits: | ||
cpu: 10m | ||
memory: 20Mi | ||
requests: | ||
cpu: 10m | ||
memory: 20Mi | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: default-http-backend | ||
namespace: kube-system | ||
labels: | ||
k8s-app: default-http-backend | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
selector: | ||
k8s-app: default-http-backend |
53 changes: 53 additions & 0 deletions
53
examples/customization/custom-headers/nginx/nginx-ingress-controller.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-ingress-controller | ||
labels: | ||
k8s-app: nginx-ingress-controller | ||
namespace: kube-system | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: nginx-ingress-controller | ||
spec: | ||
# hostNetwork makes it possible to use ipv6 and to preserve the source IP correctly regardless of docker configuration | ||
# however, it is not a hard dependency of the nginx-ingress-controller itself and it may cause issues if port 10254 already is taken on the host | ||
# that said, since hostPort is broken on CNI (https://github.com/kubernetes/kubernetes/issues/31307) we have to use hostNetwork where CNI is used | ||
# like with kubeadm | ||
# hostNetwork: true | ||
terminationGracePeriodSeconds: 60 | ||
containers: | ||
- image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.1 | ||
name: nginx-ingress-controller | ||
readinessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 10254 | ||
scheme: HTTP | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 10254 | ||
scheme: HTTP | ||
initialDelaySeconds: 10 | ||
timeoutSeconds: 1 | ||
ports: | ||
- containerPort: 80 | ||
hostPort: 80 | ||
- containerPort: 443 | ||
hostPort: 443 | ||
env: | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
- name: POD_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
args: | ||
- /nginx-ingress-controller | ||
- --default-backend-service=$(POD_NAMESPACE)/default-http-backend | ||
- --configmap=$(POD_NAMESPACE)/nginx-load-balancer-conf |
7 changes: 7 additions & 0 deletions
7
examples/customization/custom-headers/nginx/nginx-load-balancer-conf.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
data: | ||
proxy-set-headers: "kube-system/custom-headers" | ||
kind: ConfigMap | ||
metadata: | ||
name: nginx-load-balancer-conf | ||
namespace: kube-system |