2017-01-28 01:51:00 +00:00
|
|
|
# TLS termination
|
|
|
|
|
2023-05-05 16:31:13 +00:00
|
|
|
This example demonstrates how to terminate TLS through the Ingress-Nginx Controller.
|
2017-01-28 01:51:00 +00:00
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
2017-10-13 13:55:03 +00:00
|
|
|
You need a [TLS cert](../PREREQUISITES.md#tls-certificates) and a [test HTTP service](../PREREQUISITES.md#test-http-service) for this example.
|
2017-01-28 01:51:00 +00:00
|
|
|
|
|
|
|
## Deployment
|
|
|
|
|
2020-05-06 14:39:55 +00:00
|
|
|
Create a `ingress.yaml` file.
|
2018-10-02 06:22:12 +00:00
|
|
|
|
|
|
|
```yaml
|
2021-08-21 20:42:00 +00:00
|
|
|
apiVersion: networking.k8s.io/v1
|
2018-10-02 06:22:12 +00:00
|
|
|
kind: Ingress
|
|
|
|
metadata:
|
|
|
|
name: nginx-test
|
|
|
|
spec:
|
|
|
|
tls:
|
|
|
|
- hosts:
|
|
|
|
- foo.bar.com
|
2019-12-12 23:12:12 +00:00
|
|
|
# This assumes tls-secret exists and the SSL
|
2018-10-02 06:22:12 +00:00
|
|
|
# certificate contains a CN for foo.bar.com
|
|
|
|
secretName: tls-secret
|
2021-11-09 15:43:49 +00:00
|
|
|
ingressClassName: nginx
|
2018-10-02 06:22:12 +00:00
|
|
|
rules:
|
|
|
|
- host: foo.bar.com
|
|
|
|
http:
|
|
|
|
paths:
|
|
|
|
- path: /
|
2021-11-02 00:12:58 +00:00
|
|
|
pathType: Prefix
|
2018-10-02 06:22:12 +00:00
|
|
|
backend:
|
|
|
|
# This assumes http-svc exists and routes to healthy endpoints
|
2021-11-02 00:12:58 +00:00
|
|
|
service:
|
|
|
|
name: http-svc
|
2021-11-09 15:43:49 +00:00
|
|
|
port:
|
2021-11-02 00:12:58 +00:00
|
|
|
number: 80
|
2018-10-02 06:22:12 +00:00
|
|
|
```
|
|
|
|
|
2019-12-12 23:12:12 +00:00
|
|
|
The following command instructs the controller to terminate traffic using the provided
|
2017-10-13 13:55:03 +00:00
|
|
|
TLS cert, and forward un-encrypted HTTP traffic to the test HTTP service.
|
2017-01-28 01:51:00 +00:00
|
|
|
|
|
|
|
```console
|
2017-10-13 13:55:03 +00:00
|
|
|
kubectl apply -f ingress.yaml
|
2017-01-28 01:51:00 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Validation
|
|
|
|
|
|
|
|
You can confirm that the Ingress works.
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ kubectl describe ing nginx-test
|
|
|
|
Name: nginx-test
|
|
|
|
Namespace: default
|
|
|
|
Address: 104.198.183.6
|
|
|
|
Default backend: default-http-backend:80 (10.180.0.4:8080,10.240.0.2:8080)
|
|
|
|
TLS:
|
|
|
|
tls-secret terminates
|
|
|
|
Rules:
|
|
|
|
Host Path Backends
|
|
|
|
---- ---- --------
|
|
|
|
*
|
|
|
|
http-svc:80 (<none>)
|
|
|
|
Annotations:
|
|
|
|
Events:
|
|
|
|
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
|
|
|
|
--------- -------- ----- ---- ------------- -------- ------ -------
|
2021-11-28 21:11:22 +00:00
|
|
|
7s 7s 1 {ingress-nginx-controller } Normal CREATE default/nginx-test
|
|
|
|
7s 7s 1 {ingress-nginx-controller } Normal UPDATE default/nginx-test
|
|
|
|
7s 7s 1 {ingress-nginx-controller } Normal CREATE ip: 104.198.183.6
|
|
|
|
7s 7s 1 {ingress-nginx-controller } Warning MAPPING Ingress rule 'default/nginx-test' contains no path definition. Assuming /
|
2017-01-28 01:51:00 +00:00
|
|
|
|
|
|
|
$ curl 104.198.183.6 -L
|
|
|
|
curl: (60) SSL certificate problem: self signed certificate
|
|
|
|
More details here: http://curl.haxx.se/docs/sslcerts.html
|
|
|
|
|
|
|
|
$ curl 104.198.183.6 -Lk
|
|
|
|
CLIENT VALUES:
|
|
|
|
client_address=10.240.0.4
|
|
|
|
command=GET
|
|
|
|
real path=/
|
|
|
|
query=nil
|
|
|
|
request_version=1.1
|
|
|
|
request_uri=http://35.186.221.137:8080/
|
|
|
|
|
|
|
|
SERVER VALUES:
|
|
|
|
server_version=nginx: 1.9.11 - lua: 10001
|
|
|
|
|
|
|
|
HEADERS RECEIVED:
|
|
|
|
accept=*/*
|
|
|
|
connection=Keep-Alive
|
|
|
|
host=35.186.221.137
|
|
|
|
user-agent=curl/7.46.0
|
|
|
|
via=1.1 google
|
|
|
|
x-cloud-trace-context=f708ea7e369d4514fc90d51d7e27e91d/13322322294276298106
|
|
|
|
x-forwarded-for=104.132.0.80, 35.186.221.137
|
|
|
|
x-forwarded-proto=https
|
|
|
|
BODY:
|
|
|
|
|
|
|
|
```
|