-
Notifications
You must be signed in to change notification settings - Fork 594
/
Copy pathkong-service-facade.yaml
215 lines (215 loc) · 6.09 KB
/
kong-service-facade.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# This example demonstrates how to use the KongServiceFacade resource to
# configure Kong to route traffic to a Kubernetes Service, and secure it
# with a different plugin for each KongServiceFacade.
#
# To verify the example:
#
# 1. Install the KongServiceFacade CRD:
# $ kubectl apply -k "github.com/Kong/kubernetes-configuration/config/crd/ingress-controller-incubator?ref=main"
#
# 2. Install the Kong Ingress Controller with KongServiceFacade feature gate enabled:
# $ helm upgrade --install kong -n kong --create-namespace --repo https://charts.konghq.com ingress \
# --set controller.ingressController.env.feature_gates=KongServiceFacade=true \
# --set controller.ingressController.image.repository=kong/nightly-ingress-controller \
# --set controller.ingressController.image.tag=2023-12-07 \
# --set controller.ingressController.image.effectiveSemver=3.1.0
#
# 3. Apply the example manifest:
#
# $ kubectl apply -f https://raw.githubusercontent.com/Kong/kubernetes-ingress-controller/main/examples/kong-service-facade.yaml
#
# 4. Wait for KongServiceFacades to be configured in Kong:
#
# $ kubectl wait --for=condition=Programmed=True kongservicefacade/svc-facade-alpha kongservicefacade/svc-facade-beta
#
# 5. Get Proxy's Service external IP:
#
# $ export PROXY_IP=$(kubectl get service -n kong kong-gateway-proxy -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')
# $ echo $PROXY_IP # To ensure that the variable is set.
# 198.19.249.2
#
# 6. Verify that paths /alpha and /beta are secured with key-auth and basic-auth respectively (we're using httpie here):
#
# $ http -h ${PROXY_IP}/alpha key:alice-password # /alpha allows valid key.
# HTTP/1.1 200 OK
# $ http -h ${PROXY_IP}/alpha key:wrong-key # /alpha doesn't allow invalid key.
# HTTP/1.1 401 Unauthorized
# $ http -h ${PROXY_IP}/alpha -a bob:bob-password # /alpha doesn't allow valid basic-auth credentials.
# HTTP/1.1 401 Unauthorized
# $ http -h ${PROXY_IP}/beta -a bob:bob-password # /beta allows valid basic-auth credentials.
# HTTP/1.1 200 OK
# $ http -h ${PROXY_IP}/beta -a bob:wrong # /beta doesn't allow invalid basic-auth credentials.
# HTTP/1.1 401 Unauthorized
# $ http -h ${PROXY_IP}/beta key:alice-password # /beta doesn't allow valid key.
# HTTP/1.1 401 Unauthorized
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin-deployment
namespace: default
labels:
app: httpbin
spec:
replicas: 1
selector:
matchLabels:
app: httpbin
template:
metadata:
labels:
app: httpbin
spec:
containers:
- name: httpbin
image: kong/httpbin:0.1.0
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
labels:
app: httpbin
name: httpbin-deployment
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: httpbin
type: ClusterIP
---
# KongServiceFacade pointing to the httpbin-deployment,
# secured with key-auth plugin.
apiVersion: incubator.ingress-controller.konghq.com/v1alpha1
kind: KongServiceFacade
metadata:
name: svc-facade-alpha
namespace: default
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: key-auth
spec:
backendRef:
name: httpbin-deployment
port: 80
---
# KongServiceFacade pointing to the same httpbin-deployment,
# secured with basic-auth plugin.
apiVersion: incubator.ingress-controller.konghq.com/v1alpha1
kind: KongServiceFacade
metadata:
name: svc-facade-beta
namespace: default
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: basic-auth
spec:
backendRef:
name: httpbin-deployment
port: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: httpbin-ingress
namespace: default
annotations:
konghq.com/strip-path: "true"
spec:
ingressClassName: kong
rules:
- http:
paths:
- path: /alpha
pathType: Prefix
backend:
# The /alpha path uses the KongServiceFacade secured with key-auth plugin.
resource:
apiGroup: incubator.ingress-controller.konghq.com
kind: KongServiceFacade
name: svc-facade-alpha
- path: /beta
pathType: Prefix
backend:
# The /beta path uses the KongServiceFacade secured with basic-auth plugin.
resource:
apiGroup: incubator.ingress-controller.konghq.com
kind: KongServiceFacade
name: svc-facade-beta
---
# The following resources are used to configure the key-auth and basic-auth plugins
# used by the KongServiceFacade resources.
#
# For key-auth it sets up a KongConsumer `alice` that can be authenticated by
# setting the `key` header to `alice-password`.
#
# For basic-auth it sets up a KongConsumer `bob` that can be authenticated by
# setting the `Authorization` header to `Basic <base64("bob:bob-password")>`.
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: key-auth
namespace: default
plugin: key-auth
config:
key_names: ["key"]
---
apiVersion: v1
kind: Secret
metadata:
name: alice-credentials
namespace: default
annotations:
kubernetes.io/ingress.class: kong
labels:
konghq.com/credential: key-auth
type: Opaque
stringData:
key: "alice-password"
---
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: alice
namespace: default
annotations:
kubernetes.io/ingress.class: kong
username: alice
credentials:
- alice-credentials
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: basic-auth
namespace: default
plugin: basic-auth
---
apiVersion: v1
kind: Secret
metadata:
name: bob-credentials
namespace: default
annotations:
kubernetes.io/ingress.class: kong
labels:
konghq.com/credential: basic-auth
type: Opaque
stringData:
username: "bob"
password: "bob-password"
---
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: bob
namespace: default
annotations:
kubernetes.io/ingress.class: kong
username: bob
credentials:
- bob-credentials