Skip to content

Commit 28b5053

Browse files
committed
Add configurable delayed termination instructions (nginx#1171)
* Add configurable delayed termination instructions
1 parent 80b1af4 commit 28b5053

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

deploy/helm-chart/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# NGINX Gateway Fabric Helm Chart
22

3+
- [NGINX Gateway Fabric Helm Chart](#nginx-gateway-fabric-helm-chart)
4+
- [Introduction](#introduction)
5+
- [Prerequisites](#prerequisites)
6+
- [Installing the Gateway API resources](#installing-the-gateway-api-resources)
7+
- [Installing the Chart](#installing-the-chart)
8+
- [Installing the Chart from the OCI Registry](#installing-the-chart-from-the-oci-registry)
9+
- [Installing the Chart via Sources](#installing-the-chart-via-sources)
10+
- [Pulling the Chart](#pulling-the-chart)
11+
- [Installing the Chart](#installing-the-chart-1)
12+
- [Upgrading the Chart](#upgrading-the-chart)
13+
- [Upgrading the Gateway Resources](#upgrading-the-gateway-resources)
14+
- [Upgrading the CRDs](#upgrading-the-crds)
15+
- [Upgrading the Chart from the OCI Registry](#upgrading-the-chart-from-the-oci-registry)
16+
- [Upgrading the Chart from the Sources](#upgrading-the-chart-from-the-sources)
17+
- [Configure Delayed Termination for Zero Downtime Upgrades](#configure-delayed-termination-for-zero-downtime-upgrades)
18+
- [Uninstalling the Chart](#uninstalling-the-chart)
19+
- [Uninstalling the Gateway Resources](#uninstalling-the-gateway-resources)
20+
- [Configuration](#configuration)
21+
322
## Introduction
423

524
This chart deploys the NGINX Gateway Fabric in your Kubernetes cluster.
@@ -59,6 +78,10 @@ helm install my-release . --create-namespace --wait -n nginx-gateway
5978

6079
## Upgrading the Chart
6180

81+
> **Note**
82+
> See [below](#configure-delayed-termination-for-zero-downtime-upgrades) for instructions on how to configure delayed
83+
> termination if required for zero downtime upgrades in your environment.
84+
6285
### Upgrading the Gateway Resources
6386

6487
Before you upgrade a release, ensure the Gateway API resources are the correct version as supported by the NGINX
@@ -105,6 +128,55 @@ the release `my-release`, run:
105128
helm upgrade my-release . -n nginx-gateway
106129
```
107130

131+
### Configure Delayed Termination for Zero Downtime Upgrades
132+
133+
To achieve zero downtime upgrades (meaning clients will not see any interruption in traffic while a rolling upgrade is
134+
being performed on NGF), you may need to configure delayed termination on the NGF Pod, depending on your environment.
135+
136+
> **Note**
137+
> When proxying Websocket or any long-lived connections, NGINX will not terminate until that connection is closed
138+
> by either the client or the backend. This means that unless all those connections are closed by clients/backends
139+
> before or during an upgrade, NGINX will not terminate, which means Kubernetes will kill NGINX. As a result, the
140+
> clients will see the connections abruptly closed and thus experience downtime.
141+
142+
1. Add `lifecycle` to both the nginx and the nginx-gateway container definition. To do so, update your `values.yaml`
143+
file to include the following (update the `sleep` values to what is required in your environment):
144+
145+
```yaml
146+
nginxGateway:
147+
<...>
148+
lifecycle:
149+
preStop:
150+
exec:
151+
command:
152+
- /usr/bin/gateway
153+
- sleep
154+
- --duration=40s # This flag is optional, the default is 30s
155+
156+
nginx:
157+
<...>
158+
lifecycle:
159+
preStop:
160+
exec:
161+
command:
162+
- /bin/sleep
163+
- "40"
164+
```
165+
166+
2. Ensure the `terminationGracePeriodSeconds` matches or exceeds the `sleep` value from the `preStopHook` (the default
167+
is 30). This is to ensure Kubernetes does not terminate the Pod before the `preStopHook` is complete. To do so,
168+
update your `values.yaml` file to include the following (update the value to what is required in your environment):
169+
170+
```yaml
171+
terminationGracePeriodSeconds: 50
172+
```
173+
174+
> **Note**
175+
> More information on container lifecycle hooks can be found
176+
> [here](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks) and a detailed
177+
> description of Pod termination behavior can be found in
178+
> [Termination of Pods](https://kubernetes.io/docs/concepts/workloads/Pods/Pod-lifecycle/#Pod-termination).
179+
108180
## Uninstalling the Chart
109181

110182
To uninstall/delete the release `my-release`:

docs/installation.md

+75
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
This guide walks you through how to install NGINX Gateway Fabric on a generic Kubernetes cluster.
44

5+
- [Installation](#installation)
6+
- [Prerequisites](#prerequisites)
7+
- [Deploy NGINX Gateway Fabric using Helm](#deploy-nginx-gateway-fabric-using-helm)
8+
- [Deploy NGINX Gateway Fabric from Manifests](#deploy-nginx-gateway-fabric-from-manifests)
9+
- [Expose NGINX Gateway Fabric](#expose-nginx-gateway-fabric)
10+
- [Create a NodePort Service](#create-a-nodeport-service)
11+
- [Create a LoadBalancer Service](#create-a-loadbalancer-service)
12+
- [Upgrading NGINX Gateway Fabric](#upgrading-nginx-gateway-fabric)
13+
- [Upgrade NGINX Gateway Fabric from Manifests](#upgrade-nginx-gateway-fabric-from-manifests)
14+
- [Upgrade NGINX Gateway Fabric using Helm](#upgrade-nginx-gateway-fabric-using-helm)
15+
- [Configure Delayed Termination for Zero Downtime Upgrades](#configure-delayed-termination-for-zero-downtime-upgrades)
16+
- [Configure Delayed Termination Using Manifests](#configure-delayed-termination-using-manifests)
17+
- [Configure Delayed Termination Using Helm](#configure-delayed-termination-using-helm)
18+
- [Uninstalling NGINX Gateway Fabric](#uninstalling-nginx-gateway-fabric)
19+
- [Uninstall NGINX Gateway Fabric from Manifests](#uninstall-nginx-gateway-fabric-from-manifests)
20+
- [Uninstall NGINX Gateway Fabric using Helm](#uninstall-nginx-gateway-fabric-using-helm)
21+
522
## Prerequisites
623

724
- [kubectl](https://kubernetes.io/docs/tasks/tools/)
@@ -131,6 +148,10 @@ Create a Service with type `LoadBalancer` using the appropriate manifest for you
131148

132149
## Upgrading NGINX Gateway Fabric
133150

151+
> **Note**
152+
> See [below](#configure-delayed-termination-for-zero-downtime-upgrades) for instructions on how to configure delayed
153+
> termination if required for zero downtime upgrades in your environment.
154+
134155
### Upgrade NGINX Gateway Fabric from Manifests
135156

136157
1. Upgrade the Gateway Resources
@@ -168,6 +189,60 @@ Create a Service with type `LoadBalancer` using the appropriate manifest for you
168189
To upgrade NGINX Gateway Fabric when the deployment method is Helm, please follow the instructions
169190
[here](/deploy/helm-chart/README.md#upgrading-the-chart).
170191

192+
### Configure Delayed Termination for Zero Downtime Upgrades
193+
194+
To achieve zero downtime upgrades (meaning clients will not see any interruption in traffic while a rolling upgrade is
195+
being performed on NGF), you may need to configure delayed termination on the NGF Pod, depending on your environment.
196+
197+
> **Note**
198+
> When proxying Websocket or any long-lived connections, NGINX will not terminate until that connection is closed
199+
> by either the client or the backend. This means that unless all those connections are closed by clients/backends
200+
> before or during an upgrade, NGINX will not terminate, which means Kubernetes will kill NGINX. As a result, the
201+
> clients will see the connections abruptly closed and thus experience downtime.
202+
203+
#### Configure Delayed Termination Using Manifests
204+
205+
Edit the `deploy/manifests/nginx-gateway.yaml` to include the following:
206+
207+
1. Add `lifecycle` prestop hooks to both the nginx and the nginx-gateway container definitions:
208+
209+
```yaml
210+
<...>
211+
name: nginx-gateway
212+
<...>
213+
lifecycle:
214+
preStop:
215+
exec:
216+
command:
217+
- /usr/bin/gateway
218+
- sleep
219+
- --duration=40s # This flag is optional, the default is 30s
220+
<...>
221+
name: nginx
222+
<...>
223+
lifecycle:
224+
preStop:
225+
exec:
226+
command:
227+
- /bin/sleep
228+
- "40"
229+
<...>
230+
```
231+
232+
2. Ensure the `terminationGracePeriodSeconds` matches or exceeds the `sleep` value from the `preStopHook` (the default
233+
is 30). This is to ensure Kubernetes does not terminate the Pod before the `preStopHook` is complete.
234+
235+
> **Note**
236+
> More information on container lifecycle hooks can be found
237+
> [here](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks) and a detailed
238+
> description of Pod termination behavior can be found in
239+
> [Termination of Pods](https://kubernetes.io/docs/concepts/workloads/Pods/Pod-lifecycle/#Pod-termination).
240+
241+
#### Configure Delayed Termination Using Helm
242+
243+
To configure delayed termination on the NGF Pod when the deployment method is Helm, please follow the instructions
244+
[here](/deploy/helm-chart/README.md#configure-delayed-termination-for-zero-downtime-upgrades).
245+
171246
## Uninstalling NGINX Gateway Fabric
172247

173248
### Uninstall NGINX Gateway Fabric from Manifests

0 commit comments

Comments
 (0)