Write Helm Chart about Gateway API
- User
Write Helm Chart about Gateway API
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Write Helm Chart about Gateway API
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Okay, let's create a Helm chart for Gateway API resources. This chart will allow you to deploy GatewayClass, Gateway, HTTPRoute, and optionally TCPRoute, TLSRoute, UDPRoute, and ReferenceGrant resources.
Important Prerequisites:
kubectl apply -k https://github.com/kubernetes-sigs/gateway-api/config/crd/.gateway-api/
├── Chart.yaml
├── values.yaml
├── templates/
│ ├── _helpers.tpl
│ ├── gatewayclass.yaml
│ ├── gateway.yaml
│ ├── httproute.yaml
│ ├── tcproute.yaml
│ ├── tlsroute.yaml
│ ├── udproute.yaml
│ └── referencegrant.yaml
├── .helmignore
└── README.md
Chart.yaml# gateway-api/Chart.yaml
apiVersion: v2
name: gateway-api
version: 0.1.0
appVersion: "1.0.0" # This doesn't map to a specific software version, just a chart version.
description: A Helm Chart for deploying Kubernetes Gateway API resources.
type: application
keywords:
- gateway
- gateway-api
- ingress
- networking
home: https://gateway-api.sigs.k8s.io/
sources:
- https://github.com/kubernetes-sigs/gateway-api # Not directly this chart, but the API spec.
kubeVersion: ">=1.22.0-0" # Gateway API requires newer Kubernetes versions
values.yamlThis file will contain all the configurable options for your Gateway API resources.
# gateway-api/values.yaml
# Global settings for all resources
global:
# The namespace where Gateway API resources will be deployed.
# If not set, Release.Namespace will be used.
namespace: ""
# Common labels to apply to all deployed resources
commonLabels: {}
# GatewayClass configuration
gatewayClass:
enabled: true
name: "example-gateway-class"
# IMPORTANT: Replace with the actual controller name managing your Gateway API.
# Examples:
# - "example.com/gateway-controller" (for a custom controller)
# - "ingress-nginx.ingress.kubernetes.io/gateway-controller" (for NGINX Gateway Fabric)
# - "gateway.networking.k8s.io/controller/gke-l7" (for GKE Gateway)
# - "istio.io/gateway-controller" (for Istio)
controllerName: "example.com/gateway-controller"
description: "A default GatewayClass provisioned by Helm."
# parametersRef: # Uncomment and configure if your controller requires specific parameters
# group: "example.com"
# kind: "GatewayParameters"
# name: "my-gateway-params"
# Gateway configuration
gateway:
enabled: true
name: "example-gateway"
# Must match the name of the GatewayClass this Gateway uses
gatewayClassName: "example-gateway-class"
# Addresses for the Gateway (e.g., static IP, hostname)
addresses: []
# - type: IPAddress
# value: "192.0.2.1"
# - type: Hostname
# value: "gateway.example.com"
listeners:
- name: http-listener
port: 80
protocol: HTTP
# hostname: "www.example.com" # Optional: specific hostname for this listener
allowedRoutes: # Define which routes can attach to this listener
namespaces:
from: Same # All HTTPRoutes in the same namespace as the Gateway
# from: All # All HTTPRoutes in all namespaces (use with caution)
# from: Selector # Only HTTPRoutes in namespaces matching the selector
# selector:
# matchLabels:
# app: my-app
kinds:
- kind: HTTPRoute
group: gateway.networking.k8s.io
# - name: https-listener
# port: 443
# protocol: HTTPS
# hostname: "secure.example.com"
# tls:
# mode: Terminate
# certificateRefs:
# - group: ""
# kind: Secret
# name: "example-tls-secret" # Secret must be in the Gateway's namespace
# allowedRoutes:
# namespaces:
# from: Same
# kinds:
# - kind: HTTPRoute
# group: gateway.networking.k8s.io
# HTTPRoute configuration
httpRoute:
enabled: true
name: "example-httproute"
# ParentRefs define which Gateways this route attaches to
parentRefs:
- name: "example-gateway" # Name of the Gateway
# namespace: "default" # Optional: Gateway's namespace if different from this route's namespace
# sectionName: "http-listener" # Optional: Specific listener name on the Gateway
hostnames:
- "www.example.com"
- "app.example.com"
rules:
- matches: # Define traffic matching criteria
- path:
type: PathPrefix
value: "/api"
headers:
- type: Exact
name: X-Version
value: v1
queryParams:
- type: Exact
name: debug
value: "true"
filters: # Optional: Apply filters like URL rewrite, redirect
- type: URLRewrite
urlRewrite:
path:
type: ReplaceFullPath
replaceFullPath: "/new-api"
# - type: RequestRedirect
# requestRedirect:
# scheme: https
# hostname: secure.example.com
# port: 443
# statusCode: 301
backendRefs: # Services to route to
- name: "my-service" # Name of your Kubernetes Service
port: 8080
weight: 100
# namespace: "my-app-namespace" # Optional: Service's namespace if different
# group: "" # core API group for Services
# kind: Service
- matches:
- path:
type: PathPrefix
value: "/"
backendRefs:
- name: "another-service"
port: 80
weight: 100
# TCPRoute configuration (optional)
tcpRoute:
enabled: false
name: "example-tcproute"
parentRefs:
- name: "example-gateway"
# sectionName: "tcp-listener"
rules:
- backendRefs:
- name: "my-tcp-service"
port: 9000
# TLSRoute configuration (optional)
tlsRoute:
enabled: false
name: "example-tlsroute"
parentRefs:
- name: "example-gateway"
# sectionName: "tls-passthrough-listener" # For passthrough TLS
rules:
- backendRefs:
- name: "my-tls-service"
port: 9443
# hostnames: # Only for Terminate TLS
# - "tls.example.com"
# sniHostnames: # Only for Passthrough TLS
# - "tls-passthrough.example.com"
# UDPRoute configuration (optional)
udpRoute:
enabled: false
name: "example-udproute"
parentRefs:
- name: "example-gateway"
# sectionName: "udp-listener"
rules:
- backendRefs:
- name: "my-udp-service"
port: 5000
# ReferenceGrant configuration (optional)
# Used when a Gateway API resource (e.g., HTTPRoute) needs to reference an object
# (e.g., a Service or Secret) in a different namespace.
referenceGrant:
enabled: false
name: "allow-routes-to-secrets-and-services"
# The namespace where this ReferenceGrant will reside.
# This should be the namespace of the *referenced* object.
# For example, if you want HTTPRoutes in 'app-ns' to reference Secrets in 'cert-ns',
# then the ReferenceGrant should be in 'cert-ns'.
namespace: "default" # IMPORTANT: Adjust this if you use cross-namespace references.
from: # Defines which resources are allowed to make references
- group: gateway.networking.k8s.io
kind: HTTPRoute
namespaces:
- my-app-namespace # The namespace(s) where the HTTPRoutes are located
- another-app-namespace
to: # Defines what kind of objects can be referenced
- group: "" # For core Kubernetes resources like Service
kind: Service
# name: "my-specific-service" # Optional: if you want to allow reference only to a specific service
- group: ""
kind: Secret
# name: "my-tls-secret" # Optional: if you want to allow reference only to a specific secret
templates/ Directorytemplates/_helpers.tpl{{/*
Expand the name of the chart.
*/}}
{{- define "gateway-api.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If it is too long, we get errors.
*/}}
{{- define "gateway-api.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart labels
*/}}
{{- define "gateway-api.labels" -}}
helm.sh/chart: {{ include "gateway-api.name" . }}-{{ .Chart.Version | replace "+" "_" }}
{{ include "gateway-api.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.global.commonLabels }}
{{ toYaml . }}
{{- end }}
{{- end -}}
{{/*
Selector labels
*/}}
{{- define "gateway-api.selectorLabels" -}}
app.kubernetes.io/name: {{ include "gateway-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
templates/gatewayclass.yaml{{- if .Values.gatewayClass.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: {{ .Values.gatewayClass.name }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
controllerName: {{ .Values.gatewayClass.controllerName }}
{{- if .Values.gatewayClass.description }}
description: {{ .Values.gatewayClass.description | quote }}
{{- end }}
{{- with .Values.gatewayClass.parametersRef }}
parametersRef:
group: {{ .group }}
kind: {{ .kind }}
name: {{ .name }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- end }}
{{- end }}
templates/gateway.yaml{{- if .Values.gateway.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: {{ .Values.gateway.name }}
namespace: {{ .Values.global.namespace | default .Release.Namespace }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
gatewayClassName: {{ .Values.gateway.gatewayClassName }}
{{- if .Values.gateway.addresses }}
addresses:
{{- toYaml .Values.gateway.addresses | nindent 4 }}
{{- end }}
listeners:
{{- range .Values.gateway.listeners }}
- name: {{ .name }}
port: {{ .port }}
protocol: {{ .protocol }}
{{- if .hostname }}
hostname: {{ .hostname | quote }}
{{- end }}
{{- if .tls }}
tls:
{{- if .tls.mode }}
mode: {{ .tls.mode }}
{{- end }}
{{- if .tls.certificateRefs }}
certificateRefs:
{{- toYaml .tls.certificateRefs | nindent 10 }}
{{- end }}
{{- end }}
{{- if .allowedRoutes }}
allowedRoutes:
{{- if .allowedRoutes.namespaces }}
namespaces:
from: {{ .allowedRoutes.namespaces.from }}
{{- if eq .allowedRoutes.namespaces.from "Selector" }}
selector:
{{- toYaml .allowedRoutes.namespaces.selector | nindent 12 }}
{{- end }}
{{- end }}
{{- if .allowedRoutes.kinds }}
kinds:
{{- toYaml .allowedRoutes.kinds | nindent 10 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
templates/httproute.yaml{{- if .Values.httpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ .Values.httpRoute.name }}
namespace: {{ .Values.global.namespace | default .Release.Namespace }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
parentRefs:
{{- range .Values.httpRoute.parentRefs }}
- name: {{ .name }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- if .sectionName }}
sectionName: {{ .sectionName }}
{{- end }}
{{- if .group }}
group: {{ .group }}
{{- end }}
{{- if .kind }}
kind: {{ .kind }}
{{- end }}
{{- end }}
{{- if .Values.httpRoute.hostnames }}
hostnames:
{{- toYaml .Values.httpRoute.hostnames | nindent 4 }}
{{- end }}
rules:
{{- range .Values.httpRoute.rules }}
- {{- if .matches }}
matches:
{{- toYaml .matches | nindent 8 }}
{{- end }}
{{- if .filters }}
filters:
{{- toYaml .filters | nindent 8 }}
{{- end }}
{{- if .backendRefs }}
backendRefs:
{{- toYaml .backendRefs | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
templates/tcproute.yaml{{- if .Values.tcpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1alpha2 # Check latest stable API version for TCPRoute
kind: TCPRoute
metadata:
name: {{ .Values.tcpRoute.name }}
namespace: {{ .Values.global.namespace | default .Release.Namespace }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
parentRefs:
{{- range .Values.tcpRoute.parentRefs }}
- name: {{ .name }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- if .sectionName }}
sectionName: {{ .sectionName }}
{{- end }}
{{- if .group }}
group: {{ .group }}
{{- end }}
{{- if .kind }}
kind: {{ .kind }}
{{- end }}
{{- end }}
rules:
{{- range .Values.tcpRoute.rules }}
- {{- if .backendRefs }}
backendRefs:
{{- toYaml .backendRefs | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
templates/tlsroute.yaml{{- if .Values.tlsRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1alpha2 # Check latest stable API version for TLSRoute
kind: TLSRoute
metadata:
name: {{ .Values.tlsRoute.name }}
namespace: {{ .Values.global.namespace | default .Release.Namespace }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
parentRefs:
{{- range .Values.tlsRoute.parentRefs }}
- name: {{ .name }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- if .sectionName }}
sectionName: {{ .sectionName }}
{{- end }}
{{- if .group }}
group: {{ .group }}
{{- end }}
{{- if .kind }}
kind: {{ .kind }}
{{- end }}
{{- end }}
{{- if .Values.tlsRoute.hostnames }}
hostnames:
{{- toYaml .Values.tlsRoute.hostnames | nindent 4 }}
{{- end }}
{{- if .Values.tlsRoute.sniHostnames }}
sniHostnames: # For Passthrough TLS
{{- toYaml .Values.tlsRoute.sniHostnames | nindent 4 }}
{{- end }}
rules:
{{- range .Values.tlsRoute.rules }}
- {{- if .backendRefs }}
backendRefs:
{{- toYaml .backendRefs | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
templates/udproute.yaml{{- if .Values.udpRoute.enabled }}
apiVersion: gateway.networking.k8s.io/v1alpha2 # Check latest stable API version for UDPRoute
kind: UDPRoute
metadata:
name: {{ .Values.udpRoute.name }}
namespace: {{ .Values.global.namespace | default .Release.Namespace }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
parentRefs:
{{- range .Values.udpRoute.parentRefs }}
- name: {{ .name }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- if .sectionName }}
sectionName: {{ .sectionName }}
{{- end }}
{{- if .group }}
group: {{ .group }}
{{- end }}
{{- if .kind }}
kind: {{ .kind }}
{{- end }}
{{- end }}
rules:
{{- range .Values.udpRoute.rules }}
- {{- if .backendRefs }}
backendRefs:
{{- toYaml .backendRefs | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
templates/referencegrant.yaml{{- if .Values.referenceGrant.enabled }}
apiVersion: gateway.networking.k8s.io/v1beta1 # ReferenceGrant is often v1beta1, check your CRD version
kind: ReferenceGrant
metadata:
name: {{ .Values.referenceGrant.name }}
# ReferenceGrant must be in the namespace of the *referenced* object (e.g., the Secret or Service)
namespace: {{ .Values.referenceGrant.namespace }}
labels:
{{- include "gateway-api.labels" . | nindent 4 }}
spec:
from:
{{- range .Values.referenceGrant.from }}
- group: {{ .group }}
kind: {{ .kind }}
namespaces:
{{- toYaml .namespaces | nindent 8 }}
{{- end }}
to:
{{- range .Values.referenceGrant.to }}
- group: {{ .group }}
kind: {{ .kind }}
{{- if .name }}
name: {{ .name }}
{{- end }}
{{- end }}
{{- end }}
.helmignore# .helmignore
# Files to ignore when packaging Helm charts
# This file is a .gitignore formatted file
# ignore all dotfiles
.*
# ignore all test files
*.test
*.ts
# ignore all template files
templates/*.tpl
# ignore all __pycache__ folders
__pycache__/
README.md# Helm Chart for Kubernetes Gateway API
This Helm chart allows you to deploy various Kubernetes Gateway API resources, including `GatewayClass`, `Gateway`, `HTTPRoute`, `TCPRoute`, `TLSRoute`, `UDPRoute`, and `ReferenceGrant`.
**Important:** This chart does **not** install a Gateway API controller. You must have a compatible Gateway API controller (e.g., NGINX Gateway Fabric, Istio, GKE Gateway, Envoy Gateway) already running in your cluster, and the Gateway API CRDs installed.
## Prerequisites
1. **Kubernetes Cluster:** Version 1.22+ recommended for Gateway API `v1` resources.
2. **Gateway API CRDs:** Ensure the Gateway API Custom Resource Definitions are installed in your cluster. You can usually install them with:
```bash
kubectl apply -k https://github.com/kubernetes-sigs/gateway-api/config/crd/
```
3. **Gateway API Controller:** A Gateway API compliant controller must be running in your cluster. Configure `values.yaml` with the correct `controllerName`.
## Installation
1. **Clone the Chart (or create the files manually):**
```bash
git clone <your-repo-containing-chart> gateway-api
cd gateway-api
```
(Or just ensure you have the `gateway-api` directory with the files as described above.)
2. **Customize `values.yaml`:**
Open `values.yaml` and configure the Gateway API resources to match your environment and desired setup.
* **`gatewayClass.controllerName`**: **Crucially**, set this to the identifier of your running Gateway API controller.
* **`gateway.name`**, **`gateway.gatewayClassName`**: Match these to your Gateway and GatewayClass.
* **`httpRoute.parentRefs`**: Ensure these point to your deployed Gateway.
* **`httpRoute.rules.backendRefs`**: Point these to your backend Services.
* Enable/disable specific route types (`tcpRoute`, `tlsRoute`, `udpRoute`) as needed.
* Configure `referenceGrant` if you need to reference resources across namespaces.
3. **Install the chart:**
```bash
helm install my-gateway-setup . -n my-app-namespace --create-namespace
```
Replace `my-gateway-setup` with your desired release name and `my-app-namespace` with the namespace where you want to deploy these resources. The `global.namespace` value in `values.yaml` will override `Release.Namespace` if specified.
## Uninstallation
To uninstall the `my-gateway-setup` release:
```bash
helm uninstall my-gateway-setup -n my-app-namespace
Refer to values.yaml for a comprehensive list of configurable parameters. Here are some key configurations:
global.namespace: (string) The namespace for all deployed Gateway API resources.gatewayClass.enabled: (bool) Enable/disable deployment of GatewayClass.gatewayClass.name: (string) The name of the GatewayClass.gatewayClass.controllerName: (string) REQUIRED The controller responsible for this GatewayClass.gateway.enabled: (bool) Enable/disable deployment of Gateway.gateway.name: (string) The name of the Gateway.gateway.gatewayClassName: (string) The name of the GatewayClass this Gateway will use.gateway.listeners: (array) Defines ports, protocols, and allowedRoutes for the Gateway.httpRoute.enabled: (bool) Enable/disable deployment of HTTPRoute.httpRoute.name: (string) The name of the HTTPRoute.httpRoute.parentRefs: (array) References to the Gateways this route attaches to.httpRoute.hostnames: (array) Hostnames this route will match.httpRoute.rules: (array) Define matches, filters, and backendRefs for HTTP traffic.tcpRoute, tlsRoute, udpRoute: Similar enabled, name, parentRefs, and rules structures for other protocols.referenceGrant.enabled: (bool) Enable/disable deployment of ReferenceGrant.referenceGrant.namespace: (string) Crucial: The namespace where the referenced object (e.g., Service, Secret) resides.referenceGrant.from: (array) Defines which resources are allowed to make cross-namespace references.referenceGrant.to: (array) Defines what kinds of objects can be referenced.values.yaml)# Simplified example for a basic HTTP setup
gatewayClass:
enabled: true
name: "my-nginx-class"
controllerName: "ingress-nginx.ingress.kubernetes.io/gateway-controller" # For NGINX Gateway Fabric
gateway:
enabled: true
name: "my-http-gateway"
gatewayClassName: "my-nginx-class"
listeners:
- name: http-80
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: Same
kinds:
- kind: HTTPRoute
httpRoute:
enabled: true
name: "my-app-route"
parentRefs:
- name: "my-http-gateway"
sectionName: "http-80"
hostnames:
- "my-app.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: "/"
backendRefs:
- name: "my-app-service" # Your K8s Service name
port: 80
This comprehensive chart provides a flexible way to manage your Gateway API resources using Helm. Remember to adjust the controllerName and other values to fit your specific Gateway API implementation and application needs.