Skip to content

Commit

Permalink
Update docs and examples to use networking.k8s.io/v1 (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Aug 16, 2021
1 parent 12b8f88 commit 6a57a9a
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 225 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Handling Host and Listener Collisions
description:
description:
weight: 1700
doctypes: [""]
toc: true
Expand All @@ -26,7 +26,7 @@ A host collision occurs when multiple Ingress, VirtualServer, and TransportServe
Consider the following two resources:
* `cafe-ingress` Ingress:
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Advanced Configuration with Snippets
description:
description:
weight: 1800
doctypes: [""]
toc: true
Expand All @@ -15,7 +15,7 @@ Snippets are also available through the [ConfigMap](/nginx-ingress-controller/co

The example below shows how to use snippets to customize the NGINX configuration template using annotations.
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress-with-snippets
Expand All @@ -32,13 +32,19 @@ spec:
http:
paths:
- path: /tea
pathType: Prefix
backend:
serviceName: tea-svc
servicePort: 80
service:
name: tea-svc
port:
number: 80
- path: /coffee
pathType: Prefix
backend:
serviceName: coffee-svc
servicePort: 80
service:
name: coffee-svc
port:
number: 80
```
Generated NGINX configuration:
Expand All @@ -63,7 +69,7 @@ server {

location /tea {
proxy_http_version 1.1;

add_header my-test-header test-value;
...
proxy_pass http://default-cafe-ingress-with-snippets-cafe.example.com-tea-svc-80;
Expand Down
34 changes: 22 additions & 12 deletions docs/content/configuration/ingress-resources/basic-configuration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Basic Configuration

description:
description:
weight: 1600
doctypes: [""]
toc: true
Expand All @@ -10,7 +10,7 @@ toc: true

The example below shows a basic Ingress resource definition. It load balances requests for two services -- coffee and tea -- comprising a hypothetical *cafe* app hosted at `cafe.example.com`:
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
Expand All @@ -24,13 +24,19 @@ spec:
http:
paths:
- path: /tea
pathType: Prefix
backend:
serviceName: tea-svc
servicePort: 80
service:
name: tea-svc
port:
number: 80
- path: /coffee
pathType: Prefix
backend:
serviceName: coffee-svc
servicePort: 80
service:
name: coffee-svc
port:
number: 80
```
Here is a breakdown of what this Ingress resource definition means:
Expand Down Expand Up @@ -63,17 +69,21 @@ Starting from Kubernetes 1.18, you can use the following new features:
- path: /tea/green
pathType: Exact
backend:
serviceName: tea-svc
servicePort: 80
service:
name: tea-svc
port:
number: 80
- path: /coffee
pathType: ImplementationSpecific # default
pathType: ImplementationSpecific
backend:
serviceName: coffee-svc
servicePort: 80
service:
name: coffee-svc
port:
number: 80
```
* The `ingressClassName` field is now supported:
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
26 changes: 13 additions & 13 deletions docs/content/configuration/ingress-resources/custom-annotations.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Custom Annotations

description:
description:
weight: 1900
doctypes: [""]
aliases:
Expand All @@ -16,15 +16,15 @@ Custom annotations enable you to quickly extend the Ingress resource to support

NGINX Ingress Controller supports a number of annotations for the Ingress resource that fine tune NGINX configuration (for example, connection timeouts) or enable additional features (for example, JWT validation). The complete list of annotations is available [here](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations).

The annotations are provided only for the most common features and use cases, meaning that not every NGINX feature or a customization option is available through the annotations. Additionally, even if an annotation is available, it might not give you the satisfactory level of control of a particular NGINX feature.
The annotations are provided only for the most common features and use cases, meaning that not every NGINX feature or a customization option is available through the annotations. Additionally, even if an annotation is available, it might not give you the satisfactory level of control of a particular NGINX feature.

Custom annotations allow you to add an annotation for an NGINX feature that is not available as a regular annotation. In contrast with regular annotations, to add a custom annotation, you don't need to modify the Ingress Controller source code -- just modify the template. Additionally, with a custom annotation, you get full control of how the feature is implemented in NGINX configuration.

## Usage

The Ingress Controller generates NGINX configuration for Ingress resources by executing a configuration template. See [NGINX template](https://github.com/nginxinc/kubernetes-ingress/blob/v1.12.0/internal/configs/version1/nginx.ingress.tmpl) or [NGINX Plus template](https://github.com/nginxinc/kubernetes-ingress/blob/v1.12.0/internal/configs/version1/nginx-plus.ingress.tmpl).
The Ingress Controller generates NGINX configuration for Ingress resources by executing a configuration template. See [NGINX template](https://github.com/nginxinc/kubernetes-ingress/blob/v1.12.0/internal/configs/version1/nginx.ingress.tmpl) or [NGINX Plus template](https://github.com/nginxinc/kubernetes-ingress/blob/v1.12.0/internal/configs/version1/nginx-plus.ingress.tmpl).

To support custom annotations, the template has access to the information about the Ingress resource - its *name*, *namespace* and *annotations*. It is possible to check if a particular annotation present in the Ingress resource and conditionally insert NGINX configuration directives at multiple NGINX contexts - `http`, `server`, `location` or `upstream`. Additionally, you can get the value that is set to the annotation.
To support custom annotations, the template has access to the information about the Ingress resource - its *name*, *namespace* and *annotations*. It is possible to check if a particular annotation present in the Ingress resource and conditionally insert NGINX configuration directives at multiple NGINX contexts - `http`, `server`, `location` or `upstream`. Additionally, you can get the value that is set to the annotation.

Consider the following excerpt from the template, which was extended to support two custom annotations:

Expand All @@ -43,7 +43,7 @@ Consider the following excerpt from the template, which was extended to support

Consider the following Ingress resource and note how we set two annotations:
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
Expand All @@ -69,7 +69,7 @@ Assuming that the Ingress Controller is using that customized template, it will
# Print the value assigned to the annotation: 512
```

**Notes**:
**Notes**:
* You can customize the template to insert you custom annotations via [custom templates](/nginx-ingress-controller/configuration/global-configuration/custom-templates).
* The Ingress Controller uses go templates to generate NGINX config. You can read more information about go templates [here](https://golang.org/pkg/text/template/).

Expand All @@ -92,20 +92,20 @@ If you'd like to use custom annotations with Mergeable Ingress resources, please
. . .
} {{end}}
```
**Note**: `$location.MinionIngress` is a pointer. When a regular Ingress resource is processed in the template, the value of the pointer is `nil`. Thus, it is important that you check that `$location.MinionIngress` is not `nil` as in the example above using the `with` action.
**Note**: `$location.MinionIngress` is a pointer. When a regular Ingress resource is processed in the template, the value of the pointer is `nil`. Thus, it is important that you check that `$location.MinionIngress` is not `nil` as in the example above using the `with` action.

* Minions do not inherent custom annotations of the master.

### Helper Functions

Helper functions can be used in the Ingress template to parse the values of custom annotations.

{{% table %}}
|Function | Input Arguments | Return Arguments | Description |
| ---| ---| ---| --- |
|``split`` | ``s, sep string`` | ``[]string`` | Splits the string ``s`` into a slice of strings separated by the ``sep``. |
|``trim`` | ``s string`` | ``string`` | Trims the trailing and leading whitespace from the string ``s``. |
{{% /table %}}
{{% table %}}
|Function | Input Arguments | Return Arguments | Description |
| ---| ---| ---| --- |
|``split`` | ``s, sep string`` | ``[]string`` | Splits the string ``s`` into a slice of strings separated by the ``sep``. |
|``trim`` | ``s string`` | ``string`` | Trims the trailing and leading whitespace from the string ``s``. |
{{% /table %}}

Consider the following custom annotation `custom.nginx.org/allowed-ips`, which expects a comma-separated list of IP addresses:
```
Expand Down
16 changes: 11 additions & 5 deletions examples/appprotect/cafe-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
Expand All @@ -19,10 +19,16 @@ spec:
http:
paths:
- path: /tea
pathType: Prefix
backend:
serviceName: tea-svc
servicePort: 80
service:
name: tea-svc
port:
number: 80
- path: /coffee
pathType: Prefix
backend:
serviceName: coffee-svc
servicePort: 80
service:
name: coffee-svc
port:
number: 80
16 changes: 11 additions & 5 deletions examples/complete-example/cafe-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
Expand All @@ -13,10 +13,16 @@ spec:
http:
paths:
- path: /tea
pathType: Prefix
backend:
serviceName: tea-svc
servicePort: 80
service:
name: tea-svc
port:
number: 80
- path: /coffee
pathType: Prefix
backend:
serviceName: coffee-svc
servicePort: 80
service:
name: coffee-svc
port:
number: 80
28 changes: 17 additions & 11 deletions examples/custom-annotations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Let's create a set of custom annotations to support [rate-limiting](https://ngin
* `custom.nginx.org/rate-limiting-rate` - configures the rate of rate-limiting, with the default of `1r/s`.
* `custom.nginx.org/rate-limiting-burst` - configures the maximum bursts size of requests with the default of `3`.

## Prerequisites
## Prerequisites

* Read the [custom annotations doc](https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/custom-annotations/) before going through this example first.
* Read about [custom templates](../custom-templates).

## Step 1 - Customize the Template

Customize the template for Ingress resources to include the logic to handle and apply the annotations.
Customize the template for Ingress resources to include the logic to handle and apply the annotations.

1. Create a ConfigMap file with the customized template (`nginx-config.yaml`):
```yaml
Expand All @@ -26,7 +26,7 @@ Customize the template for Ingress resources to include the logic to handle and
data:
ingress-template: |
. . .
# handling custom.nginx.org/rate-limiting` and custom.nginx.org/rate-limiting-rate
# handling custom.nginx.org/rate-limiting` and custom.nginx.org/rate-limiting-rate
{{if index $.Ingress.Annotations "custom.nginx.org/rate-limiting"}}
{{$rate := index $.Ingress.Annotations "custom.nginx.org/rate-limiting-rate"}}
Expand All @@ -37,7 +37,7 @@ Customize the template for Ingress resources to include the logic to handle and
{{range $server := .Servers}}
server {
. . .
{{range $location := $server.Locations}}
Expand All @@ -51,7 +51,7 @@ Customize the template for Ingress resources to include the logic to handle and
{{$burst := index $.Ingress.Annotations "custom.nginx.org/rate-limiting-burst"}}
limit_req zone={{$.Ingress.Namespace}}-{{$.Ingress.Name}} burst={{if $burst}}{{$burst}}{{else}}3{{end}} nodelay;
{{end}}
. . .
```
Expand Down Expand Up @@ -81,7 +81,7 @@ Customize the template for Ingress resources to include the logic to handle and

1. Create a file with the following Ingress resource (`cafe-ingress.yaml`) and use the custom annotations to enable rate-limiting:
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
Expand All @@ -96,13 +96,19 @@ Customize the template for Ingress resources to include the logic to handle and
http:
paths:
- path: /tea
pathType: Prefix
backend:
serviceName: tea-svc
servicePort: 80
service:
name: tea-svc
port:
number: 80
- path: /coffee
pathType: Prefix
backend:
serviceName: coffee-svc
servicePort: 80
service:
name: coffee-svc
port:
number: 80
```

1. Apply the Ingress resource:
Expand Down Expand Up @@ -156,4 +162,4 @@ server {
. . .
}
```
**Note**: the unimportant parts are replaced with `. . .`.
**Note**: the unimportant parts are replaced with `. . .`.
15 changes: 9 additions & 6 deletions examples/externalname-services/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Support for Type ExternalName Services
The Ingress Controller supports routing requests to services of the type [ExternalName](https://kubernetes.io/docs/concepts/services-networking/service/#externalname).
An ExternalName service is defined by an external DNS name that is resolved into the IP addresses, typically external to the cluster. This enables to use the Ingress Controller to route requests to the destinations outside of the cluster.

An ExternalName service is defined by an external DNS name that is resolved into the IP addresses, typically external to the cluster. This enables to use the Ingress Controller to route requests to the destinations outside of the cluster.

**Note:** This feature is only available in NGINX Plus.

Expand Down Expand Up @@ -40,7 +40,7 @@ spec:
In the following Ingress resource we use my-service:
```yaml
apiVersion: networking.k8s.io/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
Expand All @@ -52,10 +52,13 @@ spec:
http:
paths:
- path: /
pathType: Prefix
backend:
serviceName: my-service
servicePort: 80
service:
name: my-service
port:
number: 80

```

As a result, NGINX Plus will route requests for “example.com” to the IP addresses behind the DNS name my.service.example.com.
As a result, NGINX Plus will route requests for “example.com” to the IP addresses behind the DNS name my.service.example.com.
Loading

0 comments on commit 6a57a9a

Please sign in to comment.