Skip to content

Commit 22bb66b

Browse files
author
Travis Raines
authored
Add ingress class docs (Kong#811)
Add documentation for the Ingress class annotation, which the controller uses to filter out which Kubernetes resources it needs to translate into Kong configuration. This includes an overview document describing the annotation's use and providing an example configuration demonstrating it, updates to existing reference documentation that account for the new behavior, and updates to existing guides to incorporate the annotation where needed.
1 parent 12f565e commit 22bb66b

24 files changed

+333
-10
lines changed

docs/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Custom Resources](#custom-resources)
88
- [Deployment methods](#deployment-methods)
99
- [High-availability and scaling](#high-availability-and-scaling)
10+
- [Resource classes](#resource-classes)
1011
- [Security](#security)
1112
- [Guides and Tutorials](#guides-and-tutorials)
1213
- [Configuration reference](#configuration-reference)
@@ -48,6 +49,12 @@ and infrastructure.
4849
Please refer to [this document](concepts/ha-and-scaling.md) to understand
4950
failures scenarios, recovery methods, as well as scaling considerations.
5051

52+
### Ingress classes
53+
54+
[Ingress classes](concepts/ingress-classes.md) filter which resources the
55+
controller loads. They ensure that Kong Ingress Controller instances do not
56+
load configuration intended for other instances or other ingress controllers.
57+
5158
### Security
5259

5360
Please refer to [this document](concepts/security.md) to understand the

docs/concepts/custom-resources.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Once this resource is created, the resource needs to be associated with an
6464
`Ingress`, `Service`, or `KongConsumer` resource in Kubernetes.
6565
For more details, please read the reference documentation on `KongPlugin`.
6666

67-
The below diagram shows how the `KongPlugin` resource can be linked to an
67+
The below diagram shows how you can link `KongPlugin` resource to an
6868
`Ingress`, `Service`, or `KongConsumer`:
6969

7070
| | |
@@ -73,6 +73,8 @@ The below diagram shows how the `KongPlugin` resource can be linked to an
7373

7474
## KongClusterPlugin
7575

76+
_This resource requires the [`kubernetes.io/ingress.class` annotation](../README.md#resource-classes)._
77+
7678
KongClusterPlugin resource is exactly same as KongPlugin, except that it is a
7779
Kubernetes cluster-level resources instead of being a namespaced resource.
7880
This can help when the configuration of the plugin needs to be centralized
@@ -87,12 +89,20 @@ KongClusterPlugin with the same name.
8789

8890
## KongConsumer
8991

92+
_This resource requires the `kubernetes.io/ingress.class` annotation. Its value
93+
must match the value of the controller's `--ingress-class` argument, which is
94+
"kong" by default._
95+
9096
This custom resource configures `Consumers` in Kong.
9197
Every `KongConsumer` resource in Kubernetes directly translates to a
9298
[Consumer][kong-consumer] object in Kong.
9399

94100
## TCPIngress
95101

102+
_This resource requires the `kubernetes.io/ingress.class` annotation. Its value
103+
must match the value of the controller's `--ingress-class` argument, which is
104+
"kong" by default._
105+
96106
This Custom Resource is used for exposing non-HTTP
97107
and non-GRPC services running inside Kubernetes to
98108
the outside world via Kong. This proves to be useful when

docs/concepts/ingress-classes.md

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Kong Ingress Controller and ingress class
2+
3+
4+
## Table of Contents
5+
6+
- [**Introduction**](#introduction)
7+
- [**Configuring the controller class**](#configuring-the-controller-ingress-class)
8+
- [**Loading resources by class**](#loading-resouces-by-class)
9+
- [**When to use a custom class**](#when-to-use-a-custom-class)
10+
- [**Legacy behavior**](#legacy-behavior)
11+
- [**Examples**](#examples)
12+
13+
## Introduction
14+
15+
The Kong Ingress Controller uses ingress classes to filter Kubernetes Ingress
16+
objects and other resources before converting them into Kong configuration.
17+
This allows it to coexist with other ingress controllers and/or other
18+
deployments of the Kong Ingress Controller in the same cluster: a Kong Ingress
19+
Controller will only process configuration marked for its use.
20+
21+
## Configuring the controller ingress class
22+
23+
The `--ingress-class` flag (or `CONTROLLER_INGRESS_CLASS` environment variable)
24+
specify the ingress class expected by the Kong Ingress Controller. By default,
25+
it expects the `kong` class.
26+
27+
## Loading resources by class
28+
29+
The Kong Ingress Controller translates a variety of Kubernetes resources into
30+
Kong configuration. Broadly speaking, we can separate these resources into two
31+
categories:
32+
33+
- Resources that the controller translates directly into Kong configuration.
34+
- Resources referenced by some other resource, where the other resource is
35+
directly translated into Kong configuration.
36+
37+
For example, an Ingress is translated directly into a Kong route, and a
38+
KongConsumer is translated directly into a [Kong consumer](https://docs.konghq.com/latest/admin-api/#consumer-object). A Secret containing
39+
an authentication plugin credential is _not_ translated directly: it is only
40+
translated into Kong configuration if a KongConsumer resource references it.
41+
42+
Because they create Kong configuration indenpendent of any other resources,
43+
directly-translated resources require an ingress class, and their class must
44+
match the class configured for the controller. Referenced resources do not
45+
require a class, but must be referenced by a directly-translated resource
46+
that matches the controller.
47+
48+
### Adding class information to resources
49+
50+
Most resources use a [kubernetes.io/ingress-class annotation][class-annotation]
51+
to indicate their class. There are several exceptions:
52+
53+
- v1 Ingress resources have a dedicated `class` field.
54+
- Knative Services [use the class specifed][knative-class] by the
55+
`ingress.class` key of the Knative installation's `config-network` ConfigMap.
56+
You can optionally [override this on a per-Service basis][knative-override]
57+
by adding a `networking.knative.dev/ingress.class` annotation to the Service.
58+
59+
### Enabling support for classless resources
60+
61+
Specifying a class is optional for some resources. Although specifying a class
62+
is recommended, you can instruct the controller to process resources without a
63+
class annotation using flags:
64+
65+
- `--process-classless-ingress-v1beta1` instructs the controller to translate
66+
v1beta1 Ingress resources with no class annotation.
67+
- `--process-classless-kong-consumer` instructs the controller to translate
68+
KongConsumer resources with no class annotation.
69+
70+
These flags are primarily intended for compatibility with older configuration
71+
(Kong Ingress Controller before 0.10 had less strict class
72+
requirements, and it was common to omit class annotations). If you are creating
73+
new configuration and do not have older configuration without class
74+
annotations, recommended best practice is to add class information to Ingress
75+
and KongConsumer resources and not set the above flags. Doing so avoids
76+
accidentally creating duplicate configuration in other ingress controller
77+
instances.
78+
79+
These flags do not _ignore_ `ingress.class` annotations: they allow resources
80+
with no such annotation, but will not allow resource that have a non-matching
81+
`ingress.class` annotation.
82+
83+
## When to use a custom class
84+
85+
Using the default `kong` class is fine for simpler deployments, where only one
86+
Kong Ingress Controller instance is running in a cluster. Changing the class is
87+
typical when:
88+
89+
- You install multiple Kong environments in one Kubernetes cluster to handle
90+
different types of ingress traffic, e.g. when using separate Kong instances
91+
to handle traffic on internal and external load balancers, or deploying
92+
different types of non-production environments in a single test cluster.
93+
- You install multiple controller instances alongside a single Kong cluster to
94+
separate configuration into different Kong workspaces (using the
95+
`--kong-workspace` flag) or to restrict which Kubernetes namespaces any one
96+
controller instance has access to.
97+
98+
## Legacy behavior
99+
100+
This overview covers behavior in Kong Ingress Controller version 0.10.0 onward.
101+
Earlier versions had a special case for the default class and a bug affecting
102+
custom classes:
103+
104+
- When using the default `kong` class, the controller would always process
105+
classless resources in addition to `kong`-class resources. When using a
106+
non-default controller class, the controller would only process resources
107+
with that class, not classless resources. Although this was by design, it was
108+
a source of user confusion.
109+
- When using a custom controller class, some resources that should not have
110+
required a class (because they were referenced by other resources)
111+
effectively did require a class: while these resources were loaded initially,
112+
the controller would not track updates to them unless they had a class
113+
annotation.
114+
115+
In versions 0.10.0+ you must instruct the controller to load classless
116+
resources, which is allowed (but not recommended) for either the default or
117+
custom classes. Resources referenced by another resource are always loaded and
118+
updated correctly regardless of which class you set on the controller; you do
119+
not need to add class annotations to these resources when using a custom class.
120+
121+
## Examples
122+
123+
Typical configurations will include a mix of resources that have class
124+
information and resources that are referenced by them. For example, consider
125+
the following configuration for authenticating a request, using a KongConsumer,
126+
credential Secret, Ingress, and KongPlugin (a Service is implied, but not
127+
shown):
128+
129+
```yaml
130+
kind: KongConsumer
131+
metadata:
132+
name: dyadya-styopa
133+
annotations:
134+
kubernetes.io/ingress.class: "kong"
135+
username: styopa
136+
credentials:
137+
- styopa-key
138+
139+
---
140+
141+
kind: Secret
142+
apiVersion: v1
143+
stringData:
144+
key: bylkogdatomoryakom
145+
kongCredType: key-auth
146+
metadata:
147+
name: styopa-key
148+
149+
---
150+
151+
kind: Ingress
152+
apiVersion: extensions/v1beta1
153+
metadata:
154+
name: ktonezhnaet
155+
annotations:
156+
kubernetes.io/ingress.class: "kong"
157+
konghq.com/plugins: "key-auth-example"
158+
spec:
159+
rules:
160+
- http:
161+
paths:
162+
- path: /vsemznakom
163+
backend:
164+
serviceName: httpbin
165+
servicePort: 80
166+
167+
---
168+
169+
apiVersion: configuration.konghq.com/v1
170+
kind: KongPlugin
171+
metadata:
172+
name: key-auth-example
173+
plugin: key-auth
174+
```
175+
176+
The KongConsumer and Ingress resources both have class annotations, as they are
177+
resources that the controller uses as a basis for building Kong configuration.
178+
The Secret and KongPlugin _do not_ have class annotations, as they are
179+
referenced by other resources that do.
180+
181+
[class-annotation]: ../references/annotations.md#kubernetesioingressclass
182+
[knative-class]: ../guides/using-kong-with-knative.md#ingress-class
183+
[knative-override]: https://knative.tips/networking/ingress-override/

docs/deployment/admission-webhook.md

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ $ echo "apiVersion: configuration.konghq.com/v1
142142
kind: KongConsumer
143143
metadata:
144144
name: harry
145+
annotations:
146+
kubernetes.io/ingress.class: kong
145147
username: harry" | kubectl apply -f -
146148
kongconsumer.configuration.konghq.com/harry created
147149
```
@@ -153,6 +155,8 @@ $ echo "apiVersion: configuration.konghq.com/v1
153155
kind: KongConsumer
154156
metadata:
155157
name: harry2
158+
annotations:
159+
kubernetes.io/ingress.class: kong
156160
username: harry" | kubectl apply -f -
157161
Error from server: error when creating "STDIN": admission webhook "validations.kong.konghq.com" denied the request: consumer already exists
158162
```

docs/guides/cert-manager.md

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ apiVersion: extensions/v1beta1
124124
kind: Ingress
125125
metadata:
126126
name: demo-yolo42-com
127+
annotations:
128+
kubernetes.io/ingress.class: kong
127129
spec:
128130
rules:
129131
- host: demo.yolo42.com
@@ -190,6 +192,7 @@ metadata:
190192
annotations:
191193
kubernetes.io/tls-acme: "true"
192194
cert-manager.io/cluster-issuer: letsencrypt-prod
195+
kubernetes.io/ingress.class: kong
193196
spec:
194197
tls:
195198
- secretName: demo-yolo42-com

docs/guides/configure-acl-plugin.md

+18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ metadata:
5454
name: demo-get
5555
annotations:
5656
konghq.com/strip-path: "false"
57+
kubernetes.io/ingress.class: kong
5758
spec:
5859
rules:
5960
- http:
@@ -71,6 +72,7 @@ metadata:
7172
name: demo-post
7273
annotations:
7374
konghq.com/strip-path: "false"
75+
kubernetes.io/ingress.class: kong
7476
spec:
7577
rules:
7678
- http:
@@ -161,6 +163,7 @@ metadata:
161163
annotations:
162164
plugins.konghq.com: app-jwt
163165
konghq.com/strip-path: "false"
166+
kubernetes.io/ingress.class: kong
164167
spec:
165168
rules:
166169
- http:
@@ -179,6 +182,7 @@ metadata:
179182
annotations:
180183
plugins.konghq.com: app-jwt
181184
konghq.com/strip-path: "false"
185+
kubernetes.io/ingress.class: kong
182186
spec:
183187
rules:
184188
- http:
@@ -234,6 +238,8 @@ apiVersion: configuration.konghq.com/v1
234238
kind: KongConsumer
235239
metadata:
236240
name: admin
241+
annotations:
242+
kubernetes.io/ingress.class: kong
237243
username: admin
238244
" | kubectl apply -f -
239245

@@ -242,6 +248,8 @@ apiVersion: configuration.konghq.com/v1
242248
kind: KongConsumer
243249
metadata:
244250
name: plain-user
251+
annotations:
252+
kubernetes.io/ingress.class: kong
245253
username: plain-user
246254
" | kubectl apply -f -
247255
```
@@ -299,6 +307,8 @@ apiVersion: configuration.konghq.com/v1
299307
kind: KongConsumer
300308
metadata:
301309
name: admin
310+
annotations:
311+
kubernetes.io/ingress.class: kong
302312
username: admin
303313
credentials:
304314
- app-admin-jwt
@@ -309,6 +319,8 @@ apiVersion: configuration.konghq.com/v1
309319
kind: KongConsumer
310320
metadata:
311321
name: plain-user
322+
annotations:
323+
kubernetes.io/ingress.class: kong
312324
username: plain-user
313325
credentials:
314326
- app-user-jwt
@@ -536,6 +548,8 @@ apiVersion: configuration.konghq.com/v1
536548
kind: KongConsumer
537549
metadata:
538550
name: admin
551+
annotations:
552+
kubernetes.io/ingress.class: kong
539553
username: admin
540554
credentials:
541555
- app-admin-jwt
@@ -547,6 +561,8 @@ apiVersion: configuration.konghq.com/v1
547561
kind: KongConsumer
548562
metadata:
549563
name: plain-user
564+
annotations:
565+
kubernetes.io/ingress.class: kong
550566
username: plain-user
551567
credentials:
552568
- app-user-jwt
@@ -567,6 +583,7 @@ metadata:
567583
annotations:
568584
plugins.konghq.com: app-jwt,plain-user-acl
569585
konghq.com/strip-path: "false"
586+
kubernetes.io/ingress.class: kong
570587
spec:
571588
rules:
572589
- http:
@@ -585,6 +602,7 @@ metadata:
585602
annotations:
586603
plugins.konghq.com: app-jwt,admin-acl
587604
konghq.com/strip-path: "false"
605+
kubernetes.io/ingress.class: kong
588606
spec:
589607
rules:
590608
- http:

docs/guides/configuring-fallback-service.md

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ metadata:
5656
name: demo
5757
annotations:
5858
konghq.com/strip-path: "true"
59+
kubernetes.io/ingress.class: kong
5960
spec:
6061
rules:
6162
- http:
@@ -104,6 +105,8 @@ apiVersion: extensions/v1beta1
104105
kind: Ingress
105106
metadata:
106107
name: fallback
108+
annotations:
109+
kubernetes.io/ingress.class: kong
107110
spec:
108111
backend:
109112
serviceName: fallback-svc

0 commit comments

Comments
 (0)