Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pathType field in the Ingress resource #1080

Merged
merged 8 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deployments/helm-chart/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rules:
- patch
- list
- apiGroups:
- extensions
- networking.k8s.io
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
resources:
- ingresses
verbs:
Expand Down
6 changes: 3 additions & 3 deletions deployments/rbac/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: nginx-ingress
rules:
- apiGroups:
- ""
- "networking.k8s.io"
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
resources:
- services
- endpoints
Expand Down Expand Up @@ -46,15 +46,15 @@ rules:
- patch
- list
- apiGroups:
- extensions
- "networking.k8s.io"
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
resources:
- ingresses
verbs:
- list
- watch
- get
- apiGroups:
- "extensions"
- "networking.k8s.io"
resources:
- ingresses/status
verbs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Customization and fine-tuning is also available through the [ConfigMap](/nginx-i

Here is an example of using annotations to customize the configuration for a particular Ingress resource:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-with-annotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-with-snippets
Expand Down
30 changes: 27 additions & 3 deletions docs-web/configuration/ingress-resources/basic-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand All @@ -15,7 +15,7 @@ spec:
- host: cafe.example.com
http:
paths:
- path: /tea
- path: "/tea"
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
backend:
serviceName: tea-svc
servicePort: 80
Expand All @@ -32,14 +32,38 @@ Here is a breakdown of what this Ingress resource definition means:
* In the `hosts` field, we apply the certificate and key to our `cafe.example.com` host.
* In the `spec.rules` field, we define a host with domain name `cafe.example.com`.
* In the `paths` field, we define two path‑based rules:
* The rule with the path `/tea` instructs NGINX to distribute the requests with the `/tea` URI among the pods of the *tea* service, which is deployed with the name `tea‑svc` in the cluster.
* The rule with the path `/tea` instructs NGINX to distribute the requests with the `/tea` URI among the pods of the *tea* service, which is deployed with the name `tea‑svc` in the cluster.
* The rule with the path `/coffee` instructs NGINX to distribute the requests with the `/coffee` URI among the pods of the *coffee* service, which is deployed with the name `coffee‑svc` in the cluster.
* Both rules instruct NGINX to distribute the requests to `port 80` of the corresponding service (the `servicePort` field).

> For complete instructions on deploying the Ingress and Secret resources in the cluster, see the [complete-example](https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/complete-example) in our GitHub repo.

> To learn more about the Ingress resource, see the [Ingress resource documentation](https://kubernetes.io/docs/concepts/services-networking/ingress/) in the Kubernetes docs.

## New Features Available in Kubernetes 1.18 and Above

Starting from Kubernetes 1.18, you can use the following new features:

* The host field supports wildcard domain names, such as *.example.com.
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
* The path supports different matching rules with the new field PathType, which takes the following values: Prefix for prefix-based matching, Exact for exact matching and ImplementationSpecific, which is the default type and is the same as Prefix. For example:
```yaml
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
- path: /tea
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
pathType: Prefix
backend:
serviceName: tea-svc
servicePort: 80
- path: /tea/green
pathType: Exact
backend:
serviceName: tea-svc
servicePort: 80
- path: /coffee
pathType: ImplementationSpecific # default
backend:
serviceName: coffee-svc
servicePort: 80
```

## Restrictions

The NGINX Ingress Controller imposes the following restrictions on Ingress resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/appprotect/cafe-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/complete-example/cafe-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-annotations/README.md
Original file line number Diff line number Diff line change
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: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/externalname-services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
In the following Ingress resource we use my-service:

```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nginx.org/grpc-services: "service1[,service2,...]"

In the following example we load balance three applications, one of which is using gRPC:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: grpc-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/health-checks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Ingress controller provides the following annotations for configuring active

In the following example we enable active health checks in the cafe-ingress Ingress:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
8 changes: 4 additions & 4 deletions examples/jwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Ingress controller provides the following 4 annotations for configuring JWT

In the following example we enable JWT validation for the cafe-ingress Ingress for all paths using the same key `cafe-jwk`:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down Expand Up @@ -51,7 +51,7 @@ In the following example we enable JWT validation for the [mergeable Ingresses](

* Master:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-master
Expand All @@ -69,7 +69,7 @@ In the following example we enable JWT validation for the [mergeable Ingresses](

* Tea minion:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-tea-minion
Expand All @@ -93,7 +93,7 @@ In the following example we enable JWT validation for the [mergeable Ingresses](

* Coffee minion:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-coffee-minion
Expand Down
2 changes: 1 addition & 1 deletion examples/mergeable-ingress-types/cafe-master.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-master
Expand Down
2 changes: 1 addition & 1 deletion examples/mergeable-ingress-types/coffee-minion.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-coffee-minion
Expand Down
2 changes: 1 addition & 1 deletion examples/mergeable-ingress-types/tea-minion.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-tea-minion
Expand Down
2 changes: 1 addition & 1 deletion examples/rewrites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nginx.org/rewrites: "serviceName=service1 rewrite=rewrite1[;serviceName=service2

In the following example we load balance two applications that require URI rewriting:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/session-persistence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The syntax of the *cookieName*, *expires*, *domain*, *httponly*, *secure* and *p

In the following example we enable session persistence for two services -- the *tea-svc* service and the *coffee-svc* service:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-with-session-persistence
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress-with-session-persistence
Expand Down
2 changes: 1 addition & 1 deletion examples/ssl-services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nginx.org/ssl-services: "service1[,service2,...]"

In the following example we load balance three applications, one of which requires HTTPS:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nginx.org/websocket-services: "service1[,service2,...]"

In the following example we load balance three applications, one of which is using WebSocket:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: cafe-ingress
Expand Down
4 changes: 2 additions & 2 deletions examples/wildcard-tls-certificate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In the example below we configure TLS termination for two Ingress resources for
`foo-ingress` from the namespace `foo-namespace`:

```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: foo-ingress
Expand All @@ -45,7 +45,7 @@ spec:
`bar-ingress` from the namespace `bar-namespace`:

```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: bar-ingress
Expand Down
8 changes: 4 additions & 4 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/golang/glog"
api_v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networking "k8s.io/api/networking/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/nginxinc/kubernetes-ingress/internal/configs/version1"
Expand Down Expand Up @@ -879,14 +879,14 @@ func getFileNameForTransportServerFromKey(key string) string {
}

// HasIngress checks if the Ingress resource is present in NGINX configuration.
func (cnf *Configurator) HasIngress(ing *extensions.Ingress) bool {
func (cnf *Configurator) HasIngress(ing *networking.Ingress) bool {
name := objectMetaToFileName(&ing.ObjectMeta)
_, exists := cnf.ingresses[name]
return exists
}

// HasMinion checks if the minion Ingress resource of the master is present in NGINX configuration.
func (cnf *Configurator) HasMinion(master *extensions.Ingress, minion *extensions.Ingress) bool {
func (cnf *Configurator) HasMinion(master *networking.Ingress, minion *networking.Ingress) bool {
masterName := objectMetaToFileName(&master.ObjectMeta)

if _, exists := cnf.minions[masterName]; !exists {
Expand Down Expand Up @@ -990,7 +990,7 @@ func (cnf *Configurator) updateApResources(ingEx *IngressEx) map[string]string {
policyContent := generateApResourceFileContent(ingEx.AppProtectPolicy)
cnf.nginxManager.CreateAppProtectResourceFile(policyFileName, policyContent)
apRes[appProtectPolicyKey] = policyFileName

}

if ingEx.AppProtectLogConf != nil {
Expand Down
Loading