Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 45bdc24

Browse files
authored
Merge pull request #1130 from aledbf/improve-docs
[nginx-ingress-controller] Improve docs and examples
2 parents 28813ae + 24df136 commit 45bdc24

File tree

7 files changed

+394
-108
lines changed

7 files changed

+394
-108
lines changed

hack/verify-flags/exceptions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ingress/controllers/nginx/configuration.md:**custom-http-errors:** Enables which HTTP codes should be passed for processing with the [error_page directive](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page)
2+
ingress/controllers/nginx/configuration.md:Setting at least one code this also enables [proxy_intercept_errors](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors) (required to process error_page)
13
ingress/controllers/nginx/nginx.tmpl: require("error_page")
24
ingress/controllers/nginx/nginx.tmpl: error_page {{ $errCode }} = @custom_{{ $errCode }};{{ end }}
35
ingress/controllers/nginx/nginx/config/config.go: // enables which HTTP codes should be passed for processing with the error_page directive

ingress/controllers/nginx/README.md

Lines changed: 50 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,34 @@
22

33
This is a nginx Ingress controller that uses [ConfigMap](https://github.com/kubernetes/kubernetes/blob/master/docs/proposals/configmap.md) to store the nginx configuration. See [Ingress controller documentation](../README.md) for details on how it works.
44

5+
## Contents
6+
* [Conventions](#conventions)
7+
* [Requirements](#what-it-provides)
8+
* [Dry running](#dry-running-the-ingress-controller)
9+
* [Deployment](#deployment)
10+
* [HTTP](#http)
11+
* [HTTPS](#https)
12+
* [HTTPS enforcement](#server-side-https-enforcement)
13+
* [HSTS](#http-strict-transport-security)
14+
* [TCP Services](#exposing-tcp-services)
15+
* [UDP Services](#exposing-udp-services)
16+
* [Proxy Protocol](#proxy-protocol)
17+
* [NGINX customization](configuration.md)
18+
* [NGINX status page](#nginx-status-page)
19+
* [Debug & Troubleshooting](#troubleshooting)
20+
* [Limitations](#limitations)
521

6-
## What it provides?
722

8-
- Ingress controller
9-
- nginx 1.9.x with
10-
- SSL support
11-
- custom ssl_dhparam (optional). Just mount a secret with a file named `dhparam.pem`.
12-
- support for TCP services (flag `--tcp-services-configmap`)
13-
- custom nginx configuration using [ConfigMap](https://github.com/kubernetes/kubernetes/blob/master/docs/proposals/configmap.md)
23+
## Conventions
24+
25+
Anytime we reference a tls secret, we mean (x509, pem encoded, RSA 2048, etc). You can generate such a certificate with:
26+
`openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout $(KEY) -out $(CERT) -subj "/CN=$(HOST)/O=$(HOST)"`
27+
and creat the secret via `kubectl create secret tls --key file --cert file`
28+
1429

1530

1631
## Requirements
17-
- default backend [404-server](https://github.com/kubernetes/contrib/tree/master/404-server)
32+
- Default backend [404-server](https://github.com/kubernetes/contrib/tree/master/404-server)
1833

1934

2035
## Dry running the Ingress controller
@@ -27,8 +42,7 @@ $ mkdir /etc/nginx-ssl
2742
$ ./nginx-ingress-controller --running-in-cluster=false --default-backend-service=kube-system/default-http-backend
2843
```
2944

30-
31-
## Deploy the Ingress controller
45+
## Deployment
3246

3347
First create a default backend:
3448
```
@@ -85,7 +99,7 @@ $ LBIP=$(kubectl get node `kubectl get po -l name=nginx-ingress-lb --template '{
8599
$ curl $LBIP/foo -H 'Host: foo.bar.com'
86100
```
87101

88-
## TLS
102+
## HTTPS
89103

90104
You can secure an Ingress by specifying a secret that contains a TLS private key and certificate. Currently the Ingress only supports a single TLS port, 443, and assumes TLS termination. This controller supports SNI. The TLS secret must contain keys named tls.crt and tls.key that contain the certificate and private key to use for TLS, eg:
91105

@@ -119,36 +133,25 @@ Please follow [test.sh](https://github.com/bprashanth/Ingress/blob/master/exampl
119133

120134
Check the [example](examples/tls/README.md)
121135

122-
### HTTP Strict Transport Security
123-
124-
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement specified through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS.
125-
126-
By default the controller redirects (301) to HTTPS if there is a TLS Ingress rule.
127-
128-
To disable this behavior use `hsts=false` in the NGINX ConfigMap.
136+
### Server-side HTTPS enforcement
129137

130-
#### Optimizing TLS Time To First Byte (TTTFB)
138+
By default the controller redirects (301) to HTTPS if TLS is enabled for that ingress . If you want to disable that behaviour globally, you can use `ssl-redirect: "false"` in the NGINX config map.
131139

132-
NGINX provides the configuration option [ssl_buffer_size](http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size) to allow the optimization of the TLS record size. This improves the [Time To First Byte](https://www.igvita.com/2013/12/16/optimizing-nginx-tls-time-to-first-byte/) (TTTFB). The default value in the Ingress controller is `4k` (nginx default is `16k`);
133-
134-
### Server-side HTTPS enforcement through redirect
140+
To configure this feature for specfic ingress resources, you can use the `ingress.kubernetes.io/ssl-redirect: "false"` annotation in theparticular resource.
135141

136-
By default the controller redirects (301) to HTTPS if TLS is enabled for that ingress . If you want to disable that behaviour globally, you can use `ssl-redirect: "false"` in the NGINX ConfigMap.
137142

138-
To configure this feature for specfic ingress resources, you can use the `ingress.kubernetes.io/ssl-redirect: "false"` annotation in theparticular resource.
143+
### HTTP Strict Transport Security
139144

140-
## Proxy Protocol
145+
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement specified through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send all communications over HTTPS.
141146

142-
If you are using a L4 proxy to forward the traffic to the NGINX pods and terminate HTTP/HTTPS there, you will lose the remote endpoint's IP addresses. To prevent this you could use the [Proxy Protocol](http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) for forwarding traffic, this will send the connection details before forwarding the acutal TCP connection itself.
147+
By default the controller redirects (301) to HTTPS if there is a TLS Ingress rule.
143148

144-
Amongst others [ELBs in AWS](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html) and [HAProxy](http://www.haproxy.org/) support Proxy Protocol.
149+
To disable this behavior use `hsts=false` in the NGINX config map.
145150

146-
Please check the [proxy-protocol](examples/proxy-protocol/) example
147151

148152
## Exposing TCP services
149153

150-
Ingress does not support TCP services (yet). For this reason this Ingress controller uses a ConfigMap where the key is the external port to use and the value is
151-
`<namespace/service name>:<service port>`
154+
Ingress does not support TCP services (yet). For this reason this Ingress controller uses the flag `--tcp-services-configmap` to point to an existing config map where the key is the external port to use and the value is `<namespace/service name>:<service port>`
152155
It is possible to use a number or the name of the port.
153156

154157
The next example shows how to expose the service `example-go` running in the namespace `default` in the port `8080` using the port `9000`
@@ -168,8 +171,7 @@ Please check the [tcp services](examples/tcp/README.md) example
168171

169172
Since 1.9.13 NGINX provides [UDP Load Balancing](https://www.nginx.com/blog/announcing-udp-load-balancing/).
170173

171-
Ingress does not support UDP services (yet). For this reason this Ingress controller uses a ConfigMap where the key is the external port to use and the value is
172-
`<namespace/service name>:<service port>`
174+
Ingress does not support UDP services (yet). For this reason this Ingress controller uses the flag `--udp-services-configmap` to point to an existing config map where the key is the external port to use and the value is `<namespace/service name>:<service port>`
173175
It is possible to use a number or the name of the port.
174176

175177
The next example shows how to expose the service `kube-dns` running in the namespace `kube-system` in the port `53` using the port `53`
@@ -185,91 +187,36 @@ data:
185187

186188
Please check the [udp services](examples/udp/README.md) example
187189

190+
## Proxy Protocol
188191

189-
## Custom NGINX configuration
190-
191-
Using a ConfigMap it is possible to customize the defaults in nginx.
192-
193-
Please check the [tcp services](examples/custom-configuration/README.md) example
194-
195-
196-
## Custom NGINX template
197-
198-
The NGINX template is located in the file `/etc/nginx/template/nginx.tmpl`. Mounting a volume is possible to use a custom version.
199-
Use the [custom-template](examples/custom-template/README.md) example as a guide
200-
201-
**Please note the template is tied to the go code. Be sure to no change names in the variable `$cfg`**
202-
203-
204-
### Custom NGINX upstream checks
205-
206-
NGINX exposes some flags in the [upstream configuration](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream) that enabled configuration of each server in the upstream. The ingress controller allows custom `max_fails` and `fail_timeout` parameters in a global context using `upstream-max-fails` or `upstream-fail-timeout` in the NGINX Configmap or in a particular Ingress rule. By default this values are 0. This means NGINX will respect the `livenessProbe`, if is defined. If there is no probe, NGINX will not mark a server inside an upstream down.
207-
208-
To use custom values in an Ingress rule define this annotations:
209-
210-
`ingress-nginx.kubernetes.io/upstream-max-fails`: number of unsuccessful attempts to communicate with the server that should happen in the duration set by the fail_timeout parameter to consider the server unavailable
192+
If you are using a L4 proxy to forward the traffic to the NGINX pods and terminate HTTP/HTTPS there, you will lose the remote endpoint's IP addresses. To prevent this you could use the [Proxy Protocol](http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) for forwarding traffic, this will send the connection details before forwarding the acutal TCP connection itself.
211193

212-
`ingress-nginx.kubernetes.io/upstream-fail-timeout`: time in seconds during which the specified number of unsuccessful attempts to communicate with the server should happen to consider the server unavailable. Also the period of time the server will be considered unavailable.
194+
Amongst others [ELBs in AWS](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html) and [HAProxy](http://www.haproxy.org/) support Proxy Protocol.
213195

214-
**Important:**
215-
The upstreams are shared. i.e. Ingress rule using the same service will use the same upstream.
216-
This means only one of the rules should define annotations to configure the upstream servers
196+
Please check the [proxy-protocol](examples/proxy-protocol/) example
217197

218198

219-
Please check the [auth](examples/custom-upstream-check/README.md) example
199+
### Custom errors
220200

221-
### Authentication
222-
223-
Is possible to add authentication adding additional annotations in the Ingress rule. The source of the authentication is a secret that contains usernames and passwords inside the the key `auth`
224-
225-
The annotations are:
226-
227-
```
228-
ingress-nginx.kubernetes.io/auth-type:[basic|digest]
229-
```
230-
231-
Indicates the [HTTP Authentication Type: Basic or Digest Access Authentication](https://tools.ietf.org/html/rfc2617).
232-
233-
```
234-
ingress-nginx.kubernetes.io/auth-secret:secretName
235-
```
236-
237-
Name of the secret that contains the usernames and passwords with access to the `path/s` defined in the Ingress Rule.
238-
The secret must be created in the same namespace than the Ingress rule
239-
240-
```
241-
ingress-nginx.kubernetes.io/auth-realm:"realm string"
242-
```
201+
In case of an error in a request the body of the response is obtained from the `default backend`. Each request to the default backend includes two headers:
202+
- `X-Code` indicates the HTTP code
203+
- `X-Format` the value of the `Accept` header
243204

205+
Using this two headers is possible to use a custom backend service like [this one](https://github.com/aledbf/contrib/tree/nginx-debug-server/Ingress/images/nginx-error-server) that inspect each request and returns a custom error page with the format expected by the client. Please check the example [custom-errors](examples/custom-errors/README.md)
244206

245207
### NGINX status page
246208

247209
The ngx_http_stub_status_module module provides access to basic status information. This is the default module active in the url `/nginx_status`.
248210
This controller provides an alternitive to this module using [nginx-module-vts](https://github.com/vozlt/nginx-module-vts) third party module.
249-
To use this module just provide a ConfigMap with the key `enable-vts-status=true`. The URL is exposed in the port 8080.
211+
To use this module just provide a config map with the key `enable-vts-status=true`. The URL is exposed in the port 8080.
250212
Please check the example `example/rc-default.yaml`
251213

252214
![nginx-module-vts screenshot](https://cloud.githubusercontent.com/assets/3648408/10876811/77a67b70-8183-11e5-9924-6a6d0c5dc73a.png "screenshot with filter")
253215

254216
To extract the information in JSON format the module provides a custom URL: `/nginx_status/format/json`
255217

256218

257-
### Custom errors
258-
259-
In case of an error in a request the body of the response is obtained from the `default backend`. Each request to the default backend includes two headers:
260-
- `X-Code` indicates the HTTP code
261-
- `X-Format` the value of the `Accept` header
262-
263-
Using this two headers is possible to use a custom backend service like [this one](https://github.com/aledbf/contrib/tree/nginx-debug-server/Ingress/images/nginx-error-server) that inspect each request and returns a custom error page with the format expected by the client. Please check the example [custom-errors](examples/custom-errors/README.md)
264-
265-
266-
## Troubleshooting
267-
268-
Problems encountered during [1.2.0-alpha7 deployment](https://github.com/kubernetes/kubernetes/blob/master/docs/getting-started-guides/docker.md):
269-
* make setup-files.sh file in hypercube does not provide 10.0.0.1 IP to make-ca-certs, resulting in CA certs that are issued to the external cluster IP address rather then 10.0.0.1 -> this results in nginx-third-party-lb appearing to get stuck at "Utils.go:177 - Waiting for default/default-http-backend" in the docker logs. Kubernetes will eventually kill the container before nginx-third-party-lb times out with a message indicating that the CA certificate issuer is invalid (wrong ip), to verify this add zeros to the end of initialDelaySeconds and timeoutSeconds and reload the RC, and docker will log this error before kubernetes kills the container.
270-
* To fix the above, setup-files.sh must be patched before the cluster is inited (refer to https://github.com/kubernetes/kubernetes/pull/21504)
271-
272-
### Debug
219+
### Debug & Troubleshooting
273220

274221
Using the flag `--v=XX` it is possible to increase the level of logging.
275222
In particular:
@@ -295,13 +242,14 @@ I0316 12:24:37.610073 1 command.go:69] change in configuration detected. R
295242

296243

297244

298-
### Retries in no idempotent methods
245+
*These issues were encountered in past versions of Kubernetes:*
299246

300-
Since 1.9.13 NGINX will not retry non-idempotent requests (POST, LOCK, PATCH) in case of an error.
301-
The previous behavior can be restored using `retry-non-idempotent=true` in the configuration ConfigMap
247+
[1.2.0-alpha7 deployment](https://github.com/kubernetes/kubernetes/blob/master/docs/getting-started-guides/docker.md):
248+
249+
* make setup-files.sh file in hypercube does not provide 10.0.0.1 IP to make-ca-certs, resulting in CA certs that are issued to the external cluster IP address rather then 10.0.0.1 -> this results in nginx-third-party-lb appearing to get stuck at "Utils.go:177 - Waiting for default/default-http-backend" in the docker logs. Kubernetes will eventually kill the container before nginx-third-party-lb times out with a message indicating that the CA certificate issuer is invalid (wrong ip), to verify this add zeros to the end of initialDelaySeconds and timeoutSeconds and reload the RC, and docker will log this error before kubernetes kills the container.
250+
* To fix the above, setup-files.sh must be patched before the cluster is inited (refer to https://github.com/kubernetes/kubernetes/pull/21504)
302251

303252

304253
## Limitations
305254

306255
- Ingress rules for TLS require the definition of the field `host`
307-
- The IP address in the status of loadBalancer could contain old values

0 commit comments

Comments
 (0)