Skip to content

Commit

Permalink
Add timeouts support to vs/vsr
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean-Coakley authored Jul 4, 2019
1 parent df3ed2a commit 722c673
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 52 deletions.
30 changes: 18 additions & 12 deletions docs/virtualserver-and-virtualserverroute.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The VirtualServer and VirtualServerRoute resources are new load balancing config

This document is the reference documentation for the resources. To see additional examples of using the resources for specific use cases, go to the [examples-of-custom-resources](../examples-of-custom-resources) folder.

**Feature Status**: The VirtualServer and VirtualServerRoute resources are available as a preview feature: it is suitable for experimenting and testing; however, it must be used with caution in production environments. Additionally, while the feature is in preview, we might introduce some backward-incompatible changes to the resources specification in the next releases.
**Feature Status**: The VirtualServer and VirtualServerRoute resources are available as a preview feature: it is suitable for experimenting and testing; however, it must be used with caution in production environments. Additionally, while the feature is in preview, we might introduce some backward-incompatible changes to the resources specification in the next releases.

## Contents
- [VirtualServer and VirtualServerRoute Resources](#VirtualServer-and-VirtualServerRoute-Resources)
Expand All @@ -25,7 +25,7 @@ This document is the reference documentation for the resources. To see additiona
- [Validation](#Validation)
- [Customization via ConfigMap](#Customization-via-ConfigMap)

## Prerequisites
## Prerequisites

The VirtualServer and VirtualServerRoute resources are disabled by default. Make sure to follow Step 1.4 of the [installation](installation.md) doc during the installation process to enable the resources.

Expand Down Expand Up @@ -124,15 +124,15 @@ VirtualServerRoute:
apiVersion: k8s.nginx.org/v1alpha1
kind: VirtualServerRoute
metadata:
name: coffee
name: coffee
namespace: coffee-ns
spec:
host: cafe.example.com
upstreams:
- name: latte
service: latte-svc
port: 80
- name: espresso
- name: espresso
service: espresso-svc
port: 80
subroutes:
Expand Down Expand Up @@ -179,7 +179,10 @@ port: 80
lb-method: round_robin
fail-timeout: 10s
max-fails: 1
```
connect-timeout: 30s
read-timeout: 30s
send-timeout: 30s
```

| Field | Description | Type | Required |
| ----- | ----------- | ---- | -------- |
Expand All @@ -189,6 +192,9 @@ max-fails: 1
| `lb-method` | The load [balancing method](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-balancer/#choosing-a-load-balancing-method). To use the round-robin method, specify `round_robin`. The default is specified in the `lb-method` ConfigMap key. | `string` | No |
| `fail-timeout` | The time during which the specified number of unsuccessful attempts to communicate with an upstream server should happen to consider the server unavailable. See the [fail_timeout](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#fail_timeout) parameter of the server directive. The default is set in the `fail-timeout` ConfigMap key. | `string` | No |
| `max-fails` | The number of unsuccessful attempts to communicate with an upstream server that should happen in the duration set by the `fail-timeout` to consider the server unavailable. See the [max_fails](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_fails) parameter of the server directive. The default is set in the `max-fails` ConfgMap key. | `int` | No |
`connect-timeout` | The timeout for establishing a connection with an upstream server. See the [proxy_connect_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout) directive. The default is specified in the `proxy-connect-timeout` ConfigMap key. | `string` | No
`read-timeout` | The timeout for reading a response from an upstream server. See the [proxy_read_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout) directive. The default is specified in the `proxy-read-timeout` ConfigMap key. | `string` | No
`send-timeout` | The timeout for transmitting a request to an upstream server. See the [proxy_send_timeout](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout) directive. The default is `60s`. | `string` | No

### Split

Expand All @@ -210,12 +216,12 @@ splits:

### Rules

The rules defines a set of content-based routing rules in a route or subroute.
The rules defines a set of content-based routing rules in a route or subroute.

In the example below, NGINX routes requests with the path `/coffee` to different upstreams based on the value of the cookie `user`:
* `user=john` -> `coffee-future`
* `user=bob` -> `coffee-deprecated`
* If the cookie is not set or not equal to either `john` or `bob`, NGINX routes to `coffee-stable`
* If the cookie is not set or not equal to either `john` or `bob`, NGINX routes to `coffee-stable`

```yaml
path: /coffee
Expand All @@ -233,16 +239,16 @@ rules:
```

In the next example, NGINX routes requests based on the value of the built-in [`$request_method` variable](http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_method), which represents the HTTP method of a request:
* all POST requests -> `coffee-post`
* all non-POST requests -> `coffee`
* all POST requests -> `coffee-post`
* all non-POST requests -> `coffee`

```yaml
path: /coffee
rules:
conditions:
- variable: $request_method
matches:
- values:
- values:
- POST
upstream: coffee-post
defaultUpstream: coffee
Expand Down Expand Up @@ -311,9 +317,9 @@ In the kubectl get and similar commands, you can also use the short name `vs` in

Working with VirtualServerRoute resources is analogous. In the kubectl commands, use `virtualserverroute` or the short name `vsr`.

### Validation
### Validation

The Ingress Controller validates VirtualServer and VirtualServerRoute resources. If a resource is invalid, the Ingress Controller will reject it.
The Ingress Controller validates VirtualServer and VirtualServerRoute resources. If a resource is invalid, the Ingress Controller will reject it.

You can check if the Ingress Controller successfully applied the configuration for a VirtualServer. For our example `cafe` VirtualServer, we can run:
```
Expand Down
2 changes: 2 additions & 0 deletions internal/configs/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ConfigParams struct {
ServerTokens string
ProxyConnectTimeout string
ProxyReadTimeout string
ProxySendTimeout string
ClientMaxBodySize string
HTTP2 bool
RedirectToHTTPS bool
Expand Down Expand Up @@ -91,6 +92,7 @@ func NewDefaultConfigParams() *ConfigParams {
ServerTokens: "on",
ProxyConnectTimeout: "60s",
ProxyReadTimeout: "60s",
ProxySendTimeout: "60s",
ClientMaxBodySize: "1m",
SSLRedirect: true,
MainServerNamesHashMaxSize: "512",
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Location struct {
Snippets []string
ProxyConnectTimeout string
ProxyReadTimeout string
ProxySendTimeout string
ClientMaxBodySize string
ProxyMaxTempFileSize string
ProxyBuffering bool
Expand Down
7 changes: 4 additions & 3 deletions internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ server {
listen 80{{ if $s.ProxyProtocol }} proxy_protocol{{ end }};

server_name {{ $s.ServerName }};

{{ with $ssl := $s.SSL }}
listen 443 ssl{{ if $ssl.HTTP2 }} http2{{ end }}{{ if $s.ProxyProtocol }} proxy_protocol{{ end }};

Expand All @@ -45,11 +45,11 @@ server {
{{ if $ssl.Ciphers }}
ssl_ciphers {{ $ssl.Ciphers }};
{{ end }}

{{ if $ssl.RedirectToHTTPS }}
if ($scheme = http) {
return 301 https://$host$request_uri;
}
}
{{ end }}
{{ end }}

Expand Down Expand Up @@ -90,6 +90,7 @@ server {

proxy_connect_timeout {{ $l.ProxyConnectTimeout }};
proxy_read_timeout {{ $l.ProxyReadTimeout }};
proxy_send_timeout {{ $l.ProxySendTimeout }};
client_max_body_size {{ $l.ClientMaxBodySize }};

{{ if $l.ProxyMaxTempFileSize }}
Expand Down
3 changes: 2 additions & 1 deletion internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ server {

proxy_connect_timeout {{ $l.ProxyConnectTimeout }};
proxy_read_timeout {{ $l.ProxyReadTimeout }};
proxy_send_timeout {{ $l.ProxySendTimeout }};
client_max_body_size {{ $l.ClientMaxBodySize }};

{{ if $l.ProxyMaxTempFileSize }}
Expand All @@ -116,7 +117,7 @@ server {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_pass {{ $l.ProxyPass }};
}
{{ end }}
Expand Down
5 changes: 5 additions & 0 deletions internal/configs/version2/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var virtualServerCfg = VirtualServerConfig{
Snippets: []string{"# location snippet"},
ProxyConnectTimeout: "30s",
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ProxyBuffering: true,
ProxyBuffers: "8 4k",
Expand All @@ -128,27 +129,31 @@ var virtualServerCfg = VirtualServerConfig{
Path: "@loc0",
ProxyConnectTimeout: "30s",
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ProxyPass: "http://coffee-v1",
},
{
Path: "@loc1",
ProxyConnectTimeout: "30s",
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ProxyPass: "http://coffee-v2",
},
{
Path: "@match_loc_0",
ProxyConnectTimeout: "30s",
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ProxyPass: "http://coffee-v2",
},
{
Path: "@match_loc_default",
ProxyConnectTimeout: "30s",
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ProxyPass: "http://coffee-v1",
},
Expand Down
Loading

0 comments on commit 722c673

Please sign in to comment.