Skip to content

Commit 0ad0daf

Browse files
authored
Merge pull request #2699 from sawsa307/redirect-example
Add examples for HTTP-to-HTTPS redirects.
2 parents 8b197c1 + 619a2a7 commit 0ad0daf

File tree

4 files changed

+76
-10
lines changed

4 files changed

+76
-10
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#$ Used in:
2+
#$ - site-src/guides/http-redirect-rewrite.md
3+
apiVersion: gateway.networking.k8s.io/v1
4+
kind: Gateway
5+
metadata:
6+
name: redirect-gateway
7+
spec:
8+
gatewayClassName: foo-lb
9+
listeners:
10+
- name: http
11+
protocol: HTTP
12+
port: 80
13+
- name: https
14+
protocol: HTTPS
15+
port: 443
16+
tls:
17+
mode: Terminate
18+
certificateRefs:
19+
- name: redirect-example
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#$ Used in:
2+
#$ - site-src/guides/http-redirect-rewrite.md
3+
apiVersion: gateway.networking.k8s.io/v1
4+
kind: HTTPRoute
5+
metadata:
6+
name: http-filter-redirect
7+
spec:
8+
parentRefs:
9+
- name: redirect-gateway
10+
sectionName: http
11+
hostnames:
12+
- redirect.example
13+
rules:
14+
- filters:
15+
- type: RequestRedirect
16+
requestRedirect:
17+
scheme: https
18+
statusCode: 301
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#$ Used in:
2-
#$ - site-src/api-types/httproute.md
3-
apiVersion: gateway.networking.k8s.io/v1beta1
2+
#$ - site-src/guides/http-redirect-rewrite.md
3+
apiVersion: gateway.networking.k8s.io/v1
44
kind: HTTPRoute
55
metadata:
6-
name: http-filter-redirect
6+
name: https-route
7+
labels:
8+
gateway: redirect-gateway
79
spec:
10+
parentRefs:
11+
- name: redirect-gateway
12+
sectionName: https
813
hostnames:
9-
- redirect.example
14+
- redirect.example
1015
rules:
11-
- filters:
12-
- type: RequestRedirect
13-
requestRedirect:
14-
scheme: https
15-
statusCode: 301
16+
- backendRefs:
17+
- name: example-svc
18+
port: 80

site-src/guides/http-redirect-rewrite.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ example, to issue a permanent redirect (301) from HTTP to HTTPS, configure
2121
`requestRedirect.statusCode=301` and `requestRedirect.scheme="https"`:
2222

2323
```yaml
24-
{% include 'standard/http-redirect-rewrite/httproute-redirect-https.yaml' %}
24+
{% include 'standard/http-redirect-rewrite/httproute-redirect-http.yaml' %}
2525
```
2626

2727
Redirects change configured URL components to match the redirect configuration
@@ -31,6 +31,32 @@ example, the request `GET http://redirect.example/cinnamon` will result in a
3131
hostname (`redirect.example`), path (`/cinnamon`), and port (implicit) remain
3232
unchanged.
3333

34+
### HTTP-to-HTTPS redirects
35+
36+
To redirect HTTP traffic to HTTPS, you need to have a Gateway with both HTTP
37+
and HTTPS listeners.
38+
39+
```yaml
40+
{% include 'standard/http-redirect-rewrite/gateway-redirect-http-https.yaml' %}
41+
```
42+
There are multiple ways to secure a Gateway. In this example, it is secured
43+
using a Kubernetes Secret(`redirect-example` in the `certificateRefs` section).
44+
45+
You need a HTTPRoute that attaches to the HTTP listener and does the redirect
46+
to HTTPS. Here we set `sectionName` to be `http` so it only selects the
47+
listener named `http`.
48+
49+
```yaml
50+
{% include 'standard/http-redirect-rewrite/httproute-redirect-http.yaml' %}
51+
```
52+
53+
You also need a HTTPRoute that attaches to the HTTPS listener that forwards
54+
HTTPS traffic to application backends.
55+
56+
```yaml
57+
{% include 'standard/http-redirect-rewrite/httproute-redirect-https.yaml' %}
58+
```
59+
3460
### Path redirects
3561

3662
Path redirects use an HTTP Path Modifier to replace either entire paths or path

0 commit comments

Comments
 (0)