Skip to content

Commit 5547fe5

Browse files
authored
Add Helm Chart to install NKG (#840)
Add a Helm chart to install NKG
1 parent fcf9764 commit 5547fe5

23 files changed

+1117
-15
lines changed

.github/workflows/ci.yml

+96
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
- name: Check if generated files are up to date
5656
run: make generate && git diff --exit-code
5757

58+
- name: Check if njs-modules yaml is up to date
59+
run: make generate-njs-yaml && git diff --exit-code
60+
5861
unit-tests:
5962
name: Unit Tests
6063
runs-on: ubuntu-22.04
@@ -149,6 +152,71 @@ jobs:
149152
path: ${{ github.workspace }}/dist
150153
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
151154

155+
helm-tests:
156+
name: Helm Tests
157+
runs-on: ubuntu-22.04
158+
needs: [vars, binary]
159+
if: ${{ github.ref_type != 'tag' }}
160+
steps:
161+
- name: Checkout Repository
162+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
163+
164+
- name: Fetch Cached Artifacts
165+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
166+
with:
167+
path: ${{ github.workspace }}/dist
168+
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
169+
170+
- name: Docker Buildx
171+
uses: docker/setup-buildx-action@16c0bc4a6e6ada2cfd8afd41d22d95379cf7c32a # v2.8.0
172+
173+
- name: Docker meta
174+
id: meta
175+
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
176+
with:
177+
images: |
178+
name=ghcr.io/nginxinc/nginx-kubernetes-gateway
179+
tags: |
180+
type=semver,pattern={{version}}
181+
type=edge
182+
type=ref,event=pr
183+
type=ref,event=branch,suffix=-rc,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
184+
185+
- name: Build Docker Image
186+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
187+
with:
188+
file: build/Dockerfile
189+
tags: ${{ steps.meta.outputs.tags }}
190+
context: "."
191+
target: goreleaser
192+
load: true
193+
cache-from: type=gha
194+
cache-to: type=gha,mode=max
195+
pull: true
196+
197+
- name: Deploy Kubernetes
198+
id: k8s
199+
run: |
200+
kube_config=${{ github.workspace }}/deploy/helm-chart/kube-${{ github.run_id }}-helm
201+
make create-kind-cluster KIND_KUBE_CONFIG=${kube_config}
202+
echo "KUBECONFIG=${kube_config}" >> "$GITHUB_ENV"
203+
kind load docker-image ${{ steps.meta.outputs.tags }}
204+
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
205+
kubectl wait --for=condition=complete job/gateway-api-admission-patch job/gateway-api-admission -n gateway-system
206+
207+
- name: Install Chart
208+
run: >
209+
helm install
210+
helm-$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
211+
.
212+
--wait
213+
--create-namespace
214+
--set controller.image.repository=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
215+
--set controller.image.tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
216+
--set service.type=NodePort
217+
-n nginx-gateway
218+
working-directory: ${{ github.workspace }}/deploy/helm-chart
219+
152220
build:
153221
name: Build Image
154222
runs-on: ubuntu-22.04
@@ -235,3 +303,31 @@ jobs:
235303
name: "trivy-results-nginx-kubernetes-gateway.sarif"
236304
path: "trivy-results-nginx-kubernetes-gateway.sarif"
237305
if: always()
306+
307+
publish-helm:
308+
name: Package and Publish Helm Chart
309+
runs-on: ubuntu-22.04
310+
needs: [vars, helm-tests]
311+
if: ${{ github.event_name == 'push' && ! startsWith(github.ref, 'refs/heads/release-') }}
312+
steps:
313+
- name: Checkout Repository
314+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
315+
with:
316+
path: nkg
317+
318+
- name: Login to GitHub Container Registry
319+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
320+
with:
321+
registry: ghcr.io
322+
username: ${{ github.repository_owner }}
323+
password: ${{ secrets.GITHUB_TOKEN }}
324+
325+
- name: Package
326+
id: package
327+
run: |
328+
output=$(helm package ${{ ! startsWith(github.ref, 'refs/tags/') && '--app-version edge --version 0.0.0-edge' || '' }} nkg/deploy/helm-chart)
329+
echo "path=$(basename -- $(echo $output | cut -d: -f2))" >> $GITHUB_OUTPUT
330+
331+
- name: Push to GitHub Container Registry
332+
run: |
333+
helm push ${{ steps.package.outputs.path }} oci://ghcr.io/nginxinc/charts

.github/workflows/lint.yml

+9
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,12 @@ jobs:
8888
with:
8989
config: ${{ github.workspace }}/.markdownlint-cli2.yaml
9090
globs: '**/*.md'
91+
92+
chart-lint:
93+
name: Chart Lint
94+
runs-on: ubuntu-22.04
95+
steps:
96+
- name: Checkout Repository
97+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
98+
- name: Lint chart
99+
run: make lint-helm

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
args: [--allow-multiple-documents]
11+
exclude: (^deploy/helm-chart/templates)
1112
- id: check-added-large-files
1213
- id: check-merge-conflict
1314
- id: check-case-conflict

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
VERSION = edge
33
GIT_COMMIT = $(shell git rev-parse HEAD || echo "unknown")
44
DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
5+
MANIFEST_DIR = $(shell pwd)/deploy/manifests
6+
NJS_DIR = $(shell pwd)/internal/mode/static/nginx/modules/src
7+
CHART_DIR = $(shell pwd)/deploy/helm-chart
58

69
# variables that can be overridden by the user
710
PREFIX ?= nginx-kubernetes-gateway## The name of the image. For example, nginx-kubernetes-gateway
811
TAG ?= $(VERSION:v%=%)## The tag of the image. For example, 0.3.0
912
TARGET ?= local## The target of the build. Possible values: local and container
10-
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind## The folder where the kind kubeconfig is stored
13+
KIND_KUBE_CONFIG=$${HOME}/.kube/kind/config## The location of the kind kubeconfig
1114
OUT_DIR ?= $(shell pwd)/build/out## The folder where the binary will be stored
1215
ARCH ?= amd64## The architecture of the image and/or binary. For example: amd64 or arm64
1316
override DOCKER_BUILD_OPTIONS += --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg DATE=$(DATE)## The options for the docker build command. For example, --pull
@@ -56,7 +59,7 @@ deps: ## Add missing and remove unused modules, verify deps and download them to
5659
create-kind-cluster: ## Create a kind cluster
5760
$(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node' <conformance/tests/Dockerfile | awk -F'[ ]' '{print $$2}'))
5861
kind create cluster --image $(KIND_IMAGE)
59-
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
62+
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG)
6063

6164
.PHONY: delete-kind-cluster
6265
delete-kind-cluster: ## Delete kind cluster
@@ -92,5 +95,13 @@ njs-unit-test: ## Run unit tests for the njs httpmatches module
9295
node:18 \
9396
/bin/bash -c "npm install && npm test && npm run clean"
9497

98+
.PHONY: generate-njs-yaml
99+
generate-njs-yaml: ## Generate the njs-modules ConfigMap
100+
kubectl create configmap njs-modules --from-file=$(NJS_DIR)/httpmatches.js --dry-run=client --output=yaml > $(strip $(MANIFEST_DIR))/njs-modules.yaml
101+
102+
.PHONY: lint-helm
103+
lint-helm: ## Run the helm chart linter
104+
helm lint $(CHART_DIR)
105+
95106
.PHONY: dev-all
96107
dev-all: deps fmt njs-fmt vet lint unit-test njs-unit-test ## Run all the development checks

conformance/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster
5151
./scripts/install-gateway.sh $(GW_API_VERSION)
5252
kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system
5353
kubectl apply -f ../deploy/manifests/namespace.yaml
54-
kubectl create configmap njs-modules --from-file=../internal/mode/static/nginx/modules/src/httpmatches.js -n nginx-gateway
54+
cd .. && make generate-njs-yaml && cd -
55+
kubectl apply -f ../deploy/manifests/njs-modules.yaml -n nginx-gateway
5556
kubectl apply -f ../deploy/manifests/nginx-conf.yaml
5657
kubectl apply -f ../deploy/manifests/rbac.yaml
5758
kubectl apply -f ../deploy/manifests/gatewayclass.yaml

deploy/helm-chart/.helmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Patterns to ignore when building packages.
2+
*.png

deploy/helm-chart/Chart.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v2
2+
name: nginx-kubernetes-gateway
3+
description: NGINX Kubernetes Gateway
4+
type: application
5+
version: 0.1.0
6+
appVersion: "0.4.0"
7+
home: https://github.com/nginxinc/nginx-kubernetes-gateway
8+
icon: https://raw.githubusercontent.com/nginxinc/nginx-kubernetes-gateway/tree/main/deploy/helm-chart/chart-icon.png
9+
sources:
10+
- https://github.com/nginxinc/nginx-kubernetes-gateway/tree/main/deploy/helm-chart
11+
keywords:
12+
- kubernetes
13+
- gateway
14+
- nginx
15+
maintainers:
16+
- name: nginxinc
17+

deploy/helm-chart/README.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# NGINX Kubernetes Gateway Helm Chart
2+
3+
## Introduction
4+
5+
This chart deploys the NGINX Kubernetes Gateway in your Kubernetes cluster.
6+
7+
## Prerequisites
8+
9+
- [Helm 3.0+](https://helm.sh/docs/intro/install/)
10+
- [kubectl](https://kubernetes.io/docs/tasks/tools/)
11+
12+
> Note: NGINX Kubernetes Gateway can only run in the `nginx-gateway` namespace. This limitation will be addressed in
13+
the future releases.
14+
15+
### Installing the Gateway API resources
16+
17+
> Note: The Gateway API resources from the standard channel (the CRDs and the validating webhook) must be installed
18+
before deploying NGINX Kubernetes Gateway. If they are already installed in your cluster, please ensure they are the
19+
correct version as supported by the NGINX Kubernetes Gateway -
20+
[see the Technical Specifications](../../README.md#technical-specifications).
21+
22+
To install the Gateway resources from [the Gateway API repo](https://github.com/kubernetes-sigs/gateway-api), run:
23+
24+
```shell
25+
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
26+
```
27+
28+
## Installing the Chart
29+
30+
### Installing the Chart from the OCI Registry
31+
32+
To install the chart with the release name `my-release` (`my-release` is the name that you choose) into the
33+
nginx-gateway namespace (with optional `--create-namespace` flag - you can omit if the namespace already exists):
34+
35+
```shell
36+
helm install my-release oci://ghcr.io/nginxinc/charts/nginx-kubernetes-gateway --version 0.0.0-edge --create-namespace --wait -n nginx-gateway
37+
```
38+
39+
### Installing the Chart via Sources
40+
41+
#### Pulling the Chart
42+
43+
```shell
44+
helm pull oci://ghcr.io/nginxinc/charts/nginx-kubernetes-gateway --untar --version 0.0.0-edge
45+
cd nginx-gateway
46+
```
47+
48+
#### Installing the Chart
49+
50+
To install the chart with the release name `my-release` (`my-release` is the name that you choose) into the
51+
nginx-gateway namespace (with optional `--create-namespace` flag - you can omit if the namespace already exists):
52+
53+
```shell
54+
helm install my-release . --create-namespace --wait -n nginx-gateway
55+
```
56+
57+
## Upgrading the Chart
58+
### Upgrading the Gateway Resources
59+
Before you upgrade a release, ensure the Gateway API resources are the correct version as supported by the NGINX
60+
Kubernetes Gateway - [see the Technical Specifications](../../README.md#technical-specifications).:
61+
62+
To upgrade the Gateway resources from [the Gateway API repo](https://github.com/kubernetes-sigs/gateway-api), run:
63+
64+
```shell
65+
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
66+
```
67+
68+
### Upgrading the Chart from the OCI Registry
69+
To upgrade the release `my-release`, run:
70+
71+
```shell
72+
helm upgrade my-release oci://ghcr.io/nginxinc/charts/nginx-kubernetes-gateway --version 0.0.0-edge -n nginx-gateway
73+
```
74+
75+
### Upgrading the Chart from the Sources
76+
77+
Pull the chart sources as described in [Pulling the Chart](#pulling-the-chart), if not already present. Then, to upgrade
78+
the release `my-release`, run:
79+
80+
```shell
81+
helm upgrade my-release . -n nginx-gateway
82+
```
83+
84+
## Uninstalling the Chart
85+
86+
To uninstall/delete the release `my-release`:
87+
88+
```shell
89+
helm uninstall my-release -n nginx-gateway
90+
```
91+
92+
The command removes all the Kubernetes components associated with the release and deletes the release.
93+
94+
### Uninstalling the Gateway Resources
95+
96+
>**Warning: This command will delete all the corresponding custom resources in your cluster across all namespaces!
97+
Please ensure there are no custom resources that you want to keep and there are no other Gateway API implementations
98+
running in the cluster!**
99+
100+
To delete the Gateway resources using [the Gateway API repo](https://github.com/kubernetes-sigs/gateway-api), run:
101+
102+
```shell
103+
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
104+
```
105+
106+
## Configuration
107+
108+
The following tables lists the configurable parameters of the NGINX Kubernetes Gateway chart and their default values.
109+
110+
|Parameter | Description | Default Value |
111+
| --- | --- | --- |
112+
|`nginxGateway.image.repository` | The repository for the NGINX Kubernetes Gateway image. | ghcr.io/nginxinc/nginx-kubernetes-gateway |
113+
|`nginxGateway.image.tag` | The tag for the NGINX Kubernetes Gateway image. | edge |
114+
|`nginxGateway.image.pullPolicy` | The `imagePullPolicy` for the NGINX Kubernetes Gateway image. | Always |
115+
|`nginxGateway.gatewayClassName` | The name of the GatewayClass for the NGINX Kubernetes Gateway deployment. | nginx |
116+
|`nginxGateway.gatewayControllerName` | The name of the Gateway controller. The controller name must be of the form: DOMAIN/PATH. The controller's domain is k8s-gateway.nginx.org. | k8s-gateway.nginx.org/nginx-gateway-controller |
117+
|`nginx.image.repository` | The repository for the NGINX image. | nginx |
118+
|`nginx.image.tag` | The tag for the NGINX image. | 1.25 |
119+
|`nginx.image.pullPolicy` | The `imagePullPolicy` for the NGINX image. | Always |
120+
|`initContainer.image.repository` | The repository for the `initContainer` image. | busybox |
121+
|`initContainer.image.tag` | The tag for the `initContainer` image. | 1.36 |
122+
|`serviceAccount.annotations` | The `annotations` for the ServiceAccount used by the NGINX Kubernetes Gateway deployment. | {} |
123+
|`serviceAccount.name` | Name of the ServiceAccount used by the NGINX Kubernetes Gateway deployment. | Autogenerated |
124+
|`service.create` | Creates a service to expose the NGINX Kubernetes Gateway pods. | true |
125+
|`service.type` | The type of service to create for the NGINX Kubernetes Gateway. | Loadbalancer |
126+
|`service.externalTrafficPolicy` | The `externalTrafficPolicy` of the service. The value `Local` preserves the client source IP. | Local |
127+
|`service.annotations` | The `annotations` of the NGINX Kubernetes Gateway service. | {} |
128+
|`service.ports` | A list of ports to expose through the NGINX Kubernetes Gateway service. Update it to match the listener ports from your Gateway resource. Follows the conventional Kubernetes yaml syntax for service ports. | [ port: 80, targetPort: 80, protocol: TCP, name: http; port: 443, targetPort: 443, protocol: TCP, name: https ] |

deploy/helm-chart/chart-icon.png

7.97 KB
Loading

0 commit comments

Comments
 (0)