Skip to content

Commit 13ea272

Browse files
authored
Add Helm Chart examples (#2292)
Problem: We don't have an easy way to deploy NGF for common use cases Solution: Create an examples directory with common use cases for deploying Helm. As an added bonus we can generate manifests automatically from the examples.
1 parent ff5faa9 commit 13ea272

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2151
-699
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ internal/mode/static/nginx/modules/coverage
5454

5555
# SSH config files
5656
*.ssh
57+
58+
# temporary files used for manifest generation
59+
config/base/deploy.yaml
60+
config/base/deploy.yaml.bak

.goreleaser.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,3 @@ milestones:
6262

6363
snapshot:
6464
name_template: "edge"
65-
66-
release:
67-
extra_files:
68-
- glob: ./deploy/manifests/nginx-gateway.yaml
69-
- glob: ./deploy/manifests/nginx-plus-gateway.yaml
70-
- glob: ./deploy/manifests/nginx-gateway-experimental.yaml
71-
- glob: ./deploy/manifests/nginx-plus-gateway-experimental.yaml

.yamllint.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ rules:
2929
spaces: consistent
3030
indent-sequences: consistent
3131
check-multi-line-strings: true
32-
ignore: |
33-
deploy/manifests/nginx-gateway.yaml
3432
key-duplicates: enable
3533
key-ordering: disable
3634
line-length:
@@ -39,7 +37,6 @@ rules:
3937
allow-non-breakable-inline-mappings: true
4038
ignore: |
4139
.github/
42-
deploy/manifests/nginx-gateway.yaml
4340
tests/suite/manifests/longevity/cronjob.yaml
4441
.goreleaser.yml
4542
new-line-at-end-of-file: enable

Makefile

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# variables that should not be overridden by the user
22
VERSION = edge
33
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
4-
MANIFEST_DIR = $(CURDIR)/deploy/manifests
54
CHART_DIR = $(SELF_DIR)charts/nginx-gateway-fabric
65
NGINX_CONF_DIR = internal/mode/static/nginx/conf
76
NJS_DIR = internal/mode/static/nginx/modules/src
@@ -36,8 +35,6 @@ TARGET ?= local## The target of the build. Possible values: local and container
3635
OUT_DIR ?= build/out## The folder where the binary will be stored
3736
GOARCH ?= amd64## The architecture of the image and/or binary. For example: amd64 or arm64
3837
GOOS ?= linux## The OS of the image and/or binary. For example: linux or darwin
39-
override HELM_TEMPLATE_COMMON_ARGS += --set creator=template --set nameOverride=nginx-gateway## The common options for the Helm template command.
40-
override HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE += --set service.create=false## The options to be passed to the full Helm templating command only.
4138
override NGINX_DOCKER_BUILD_OPTIONS += --build-arg NJS_DIR=$(NJS_DIR) --build-arg NGINX_CONF_DIR=$(NGINX_CONF_DIR) --build-arg BUILD_AGENT=$(BUILD_AGENT)
4239

4340
.DEFAULT_GOAL := help
@@ -124,15 +121,7 @@ uninstall-gateway-crds: ## Uninstall Gateway API CRDs
124121

125122
.PHONY: generate-manifests
126123
generate-manifests: ## Generate manifests using Helm.
127-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) $(HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE) -n nginx-gateway | cat $(strip $(MANIFEST_DIR))/namespace.yaml - > $(strip $(MANIFEST_DIR))/nginx-gateway.yaml
128-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) $(HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE) --set nginx.plus=true --set nginx.image.repository=$(NGINX_PLUS_PREFIX) -n nginx-gateway | cat $(strip $(MANIFEST_DIR))/namespace.yaml - > $(strip $(MANIFEST_DIR))/nginx-plus-gateway.yaml
129-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) $(HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE) --set nginxGateway.gwAPIExperimentalFeatures.enable=true -n nginx-gateway | cat $(strip $(MANIFEST_DIR))/namespace.yaml - > $(strip $(MANIFEST_DIR))/nginx-gateway-experimental.yaml
130-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) $(HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE) --set nginxGateway.gwAPIExperimentalFeatures.enable=true --set nginx.plus=true --set nginx.image.repository=$(NGINX_PLUS_PREFIX) -n nginx-gateway | cat $(strip $(MANIFEST_DIR))/namespace.yaml - > $(strip $(MANIFEST_DIR))/nginx-plus-gateway-experimental.yaml
131-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) --set metrics.enable=false --set nginxGateway.productTelemetry.enable=false -n nginx-gateway -s templates/deployment.yaml > config/tests/static-deployment.yaml
132-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) -n nginx-gateway -s templates/service.yaml > $(strip $(MANIFEST_DIR))/service/loadbalancer.yaml
133-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) --set service.annotations.'service\.beta\.kubernetes\.io\/aws-load-balancer-type'="nlb" -n nginx-gateway -s templates/service.yaml > $(strip $(MANIFEST_DIR))/service/loadbalancer-aws-nlb.yaml
134-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) --set service.type=NodePort --set service.externalTrafficPolicy="" -n nginx-gateway -s templates/service.yaml > $(strip $(MANIFEST_DIR))/service/nodeport.yaml
135-
helm template nginx-gateway $(CHART_DIR) $(HELM_TEMPLATE_COMMON_ARGS) $(HELM_TEMPLATE_EXTRA_ARGS_FOR_ALL_MANIFESTS_FILE) -n nginx-gateway --api-versions security.openshift.io/v1/SecurityContextConstraints -s templates/scc.yaml > $(strip $(MANIFEST_DIR))/scc.yaml
124+
./scripts/generate-manifests.sh
136125

137126
generate-api-docs: ## Generate API docs
138127
go run github.com/ahmetb/gen-crd-api-reference-docs -config site/config/api/config.json -template-dir site/config/api -out-file site/content/reference/api.md -api-dir "github.com/nginxinc/nginx-gateway-fabric/apis"

charts/nginx-gateway-fabric/templates/_helpers.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ Create chart name and version as used by the chart label.
5858
Common labels
5959
*/}}
6060
{{- define "nginx-gateway.labels" -}}
61+
helm.sh/chart: {{ include "nginx-gateway.chart" . }}
6162
{{ include "nginx-gateway.selectorLabels" . }}
6263
{{- if .Chart.AppVersion }}
6364
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
6465
{{- end }}
65-
{{- if eq (default "helm" .Values.creator) "helm" }}
6666
app.kubernetes.io/managed-by: {{ .Release.Service }}
67-
helm.sh/chart: {{ include "nginx-gateway.chart" . }}
68-
{{- end -}}
6967
{{- end }}
7068

7169
{{/*

charts/nginx-gateway-fabric/templates/rbac.yaml renamed to charts/nginx-gateway-fabric/templates/clusterrole.yaml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
apiVersion: v1
2-
kind: ServiceAccount
3-
metadata:
4-
name: {{ include "nginx-gateway.serviceAccountName" . }}
5-
namespace: {{ .Release.Namespace }}
6-
labels:
7-
{{- include "nginx-gateway.labels" . | nindent 4 }}
8-
annotations:
9-
{{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
10-
{{- if or .Values.serviceAccount.imagePullSecret .Values.serviceAccount.imagePullSecrets }}
11-
imagePullSecrets:
12-
{{- if .Values.serviceAccount.imagePullSecret }}
13-
- name: {{ .Values.serviceAccount.imagePullSecret }}
14-
{{- end }}
15-
{{- if .Values.serviceAccount.imagePullSecrets }}
16-
{{- range .Values.serviceAccount.imagePullSecrets }}
17-
- name: {{ . }}
18-
{{- end }}
19-
{{- end }}
20-
{{- end }}
21-
---
221
apiVersion: rbac.authorization.k8s.io/v1
232
kind: ClusterRole
243
metadata:
@@ -161,18 +140,3 @@ rules:
161140
verbs:
162141
- use
163142
{{- end }}
164-
---
165-
apiVersion: rbac.authorization.k8s.io/v1
166-
kind: ClusterRoleBinding
167-
metadata:
168-
name: {{ include "nginx-gateway.fullname" . }}
169-
labels:
170-
{{- include "nginx-gateway.labels" . | nindent 4 }}
171-
roleRef:
172-
apiGroup: rbac.authorization.k8s.io
173-
kind: ClusterRole
174-
name: {{ include "nginx-gateway.fullname" . }}
175-
subjects:
176-
- kind: ServiceAccount
177-
name: {{ include "nginx-gateway.serviceAccountName" . }}
178-
namespace: {{ .Release.Namespace }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
name: {{ include "nginx-gateway.fullname" . }}
5+
labels:
6+
{{- include "nginx-gateway.labels" . | nindent 4 }}
7+
roleRef:
8+
apiGroup: rbac.authorization.k8s.io
9+
kind: ClusterRole
10+
name: {{ include "nginx-gateway.fullname" . }}
11+
subjects:
12+
- kind: ServiceAccount
13+
name: {{ include "nginx-gateway.serviceAccountName" . }}
14+
namespace: {{ .Release.Namespace }}

charts/nginx-gateway-fabric/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ spec:
8888
valueFrom:
8989
fieldRef:
9090
fieldPath: metadata.name
91-
image: {{ .Values.nginxGateway.image.repository }}:{{ .Values.nginxGateway.image.tag | default .Chart.AppVersion }}
91+
image: {{ .Values.nginxGateway.image.repository }}:{{ default .Chart.AppVersion .Values.nginxGateway.image.tag }}
9292
imagePullPolicy: {{ .Values.nginxGateway.image.pullPolicy }}
9393
name: nginx-gateway
9494
{{- if .Values.nginxGateway.lifecycle }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ include "nginx-gateway.serviceAccountName" . }}
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "nginx-gateway.labels" . | nindent 4 }}
8+
annotations:
9+
{{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
10+
{{- if or .Values.serviceAccount.imagePullSecret .Values.serviceAccount.imagePullSecrets }}
11+
imagePullSecrets:
12+
{{- if .Values.serviceAccount.imagePullSecret }}
13+
- name: {{ .Values.serviceAccount.imagePullSecret }}
14+
{{- end }}
15+
{{- if .Values.serviceAccount.imagePullSecrets }}
16+
{{- range .Values.serviceAccount.imagePullSecrets }}
17+
- name: {{ . }}
18+
{{- end }}
19+
{{- end }}
20+
{{- end }}

config/base/kustomization.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- deploy.yaml
5+
- namespace.yaml
File renamed without changes.

deploy/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Deployment manifests
2+
3+
This directory contains the Kubernetes manifests for deploying NGINX Gateway Fabric in a Kubernetes cluster. They are generated from the Helm Chart [examples](../examples/helm/).
4+
5+
They are a single file deployment manifest that can be applied to a Kubernetes cluster using `kubectl apply -f <file>`. You should have the Gateway API CRDs and the NGINX Gateway Fabric CRDs deployed before applying these manifests.
6+
The NGINX Gateway Fabric CRDs can be found in this directory as a single file deployment manifest [crds.yaml](./crds.yaml).
7+
8+
To deploy the manifests using a different registry or tag, you can modify the `kustomization.yaml` file with the desired values and
9+
use the following command to apply the manifests:
10+
11+
```shell
12+
kubectl kustomize | kubectl apply -f -
13+
```
14+
15+
For more information on how to deploy NGINX Gateway Fabric and the Gateway API CRDs see the [installation guide](https://docs.nginx.com/nginx-gateway-fabric/installation/installing-ngf/manifests/).

0 commit comments

Comments
 (0)