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.
I'll create a Helm chart for deploying Gateway API resources. This example will include a Gateway and HTTPRoute configuration.
gateway-api-chart/
├── Chart.yaml
├── values.yaml
├── templates/
│ ├── gateway.yaml
│ ├── httproute.yaml
│ ├── gatewayclass.yaml
│ └── _helpers.tpl
└── README.md
apiVersion: v2
name: gateway-api-chart
description: A Helm chart for deploying Gateway API resources
type: application
version: 0.1.0
appVersion: "1.0"
keywords:
- gateway-api
- ingress
- traffic-management
home: https://gateway-api.sigs.k8s.io/
sources:
- https://github.com/kubernetes-sigs/gateway-api
maintainers:
- name: Your Name
email: your.email@example.com
# Gateway Class Configuration
gatewayClass:
enabled: true
name: example-gateway-class
controllerName: example.io/gateway-controller
description: "Example Gateway Class"
# Gateway Configuration
gateway:
enabled: true
name: example-gateway
namespace: default
className: example-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
hostname: "*.example.com"
allowedRoutes:
namespaces:
from: Same
- name: https
protocol: HTTPS
port: 443
hostname: "*.example.com"
tls:
mode: Terminate
certificateRefs:
- name: example-com-tls
namespace: default
allowedRoutes:
namespaces:
from: Same
# Additional gateway settings
addresses: []
# - type: IPAddress
# value: 192.168.1.100
# HTTP Route Configuration
httpRoutes:
- name: example-app-route
namespace: default
hostnames:
- app.example.com
parentRefs:
- name: example-gateway
namespace: default
sectionName: https
rules:
- matches:
- path:
type: PathPrefix
value: /api
backendRefs:
- name: api-service
port: 8080
weight: 100
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: web-service
port: 80
weight: 100
- name: another-app-route
namespace: default
hostnames:
- another.example.com
parentRefs:
- name: example-gateway
namespace: default
rules:
- backendRefs:
- name: another-service
port: 8080
# Common labels to apply to all resources
commonLabels:
app.kubernetes.io/managed-by: helm
app.kubernetes.io/part-of: gateway-api
# Common annotations to apply to all resources
commonAnnotations: {}
{{/*
Expand the name of the chart.
*/}}
{{- define "gateway-api-chart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
*/}}
{{- define "gateway-api-chart.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 name and version as used by the chart label.
*/}}
{{- define "gateway-api-chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "gateway-api-chart.labels" -}}
helm.sh/chart: {{ include "gateway-api-chart.chart" . }}
{{ include "gateway-api-chart.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.commonLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "gateway-api-chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "gateway-api-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- if .Values.gatewayClass.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: {{ .Values.gatewayClass.name }}
labels:
{{- include "gateway-api-chart.labels" . | nindent 4 }}
{{- with .Values.commonAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
controllerName: {{ .Values.gatewayClass.controllerName }}
{{- if .Values.gatewayClass.description }}
description: {{ .Values.gatewayClass.description }}
{{- end }}
{{- end }}
{{- if .Values.gateway.enabled }}
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: {{ .Values.gateway.name }}
namespace: {{ .Values.gateway.namespace }}
labels:
{{- include "gateway-api-chart.labels" . | nindent 4 }}
{{- with .Values.commonAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
gatewayClassName: {{ .Values.gateway.className }}
{{- if .Values.gateway.addresses }}
addresses:
{{- toYaml .Values.gateway.addresses | nindent 4 }}
{{- end }}
listeners:
{{- range .Values.gateway.listeners }}
- name: {{ .name }}
protocol: {{ .protocol }}
port: {{ .port }}
{{- if .hostname }}
hostname: {{ .hostname }}
{{- end }}
{{- if .tls }}
tls:
{{- toYaml .tls | nindent 6 }}
{{- end }}
{{- if .allowedRoutes }}
allowedRoutes:
{{- toYaml .allowedRoutes | nindent 6 }}
{{- end }}
{{- end }}
{{- end }}
{{- range .Values.httpRoutes }}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ .name }}
namespace: {{ .namespace }}
labels:
{{- include "gateway-api-chart.labels" $ | nindent 4 }}
{{- with $.Values.commonAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .hostnames }}
hostnames:
{{- range .hostnames }}
- {{ . | quote }}
{{- end }}
{{- end }}
parentRefs:
{{- range .parentRefs }}
- name: {{ .name }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- if .sectionName }}
sectionName: {{ .sectionName }}
{{- end }}
{{- end }}
rules:
{{- range .rules }}
- {{- if .matches }}
matches:
{{- range .matches }}
- {{- if .path }}
path:
type: {{ .path.type }}
value: {{ .path.value }}
{{- end }}
{{- if .headers }}
headers:
{{- toYaml .headers | nindent 8 }}
{{- end }}
{{- if .queryParams }}
queryParams:
{{- toYaml .queryParams | nindent 8 }}
{{- end }}
{{- if .method }}
method: {{ .method }}
{{- end }}
{{- end }}
{{- end }}
{{- if .filters }}
filters:
{{- toYaml .filters | nindent 6 }}
{{- end }}
{{- if .backendRefs }}
backendRefs:
{{- range .backendRefs }}
- name: {{ .name }}
port: {{ .port }}
{{- if .weight }}
weight: {{ .weight }}
{{- end }}
{{- if .namespace }}
namespace: {{ .namespace }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
# Gateway API Helm Chart
This Helm chart deploys Gateway API resources including GatewayClass, Gateway, and HTTPRoute configurations.
## Prerequisites
- Kubernetes 1.23+
- Helm 3.0+
- Gateway API CRDs installed in your cluster
- A Gateway API controller implementation (e.g., Contour, NGINX, HAProxy)
## Installing Gateway API CRDs
```bash
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml
helm install my-gateway ./gateway-api-chart
The following table lists the configurable parameters and their default values.
| Parameter | Description | Default |
|---|---|---|
gatewayClass.enabled | Enable GatewayClass creation | true |
gatewayClass.name | Name of the GatewayClass | example-gateway-class |
gatewayClass.controllerName | Controller name for the GatewayClass | example.io/gateway-controller |
gateway.enabled | Enable Gateway creation | true |
gateway.name | Name of the Gateway | example-gateway |
gateway.listeners | List of Gateway listeners | See values.yaml |
httpRoutes | List of HTTPRoute configurations | See values.yaml |
gateway:
enabled: true
name: my-gateway
listeners:
- name: http
protocol: HTTP
port: 80
httpRoutes:
- name: my-app
hostnames:
- myapp.example.com
rules:
- backendRefs:
- name: my-service
port: 8080
gateway:
listeners:
- name: https
protocol: HTTPS
port: 443
tls:
mode: Terminate
certificateRefs:
- name: my-tls-secret
httpRoutes:
- name: api-routes
rules:
- matches:
- path:
type: PathPrefix
value: /api/v1
backendRefs:
- name: api-v1-service
port: 8080
- matches:
- path:
type: PathPrefix
value: /api/v2
backendRefs:
- name: api-v2-service
port: 8080
helm uninstall my-gateway
This Helm chart provides a flexible way to deploy Gateway API resources. Key features include:
1. **Modular design**: Each resource type (GatewayClass, Gateway, HTTPRoute) has its own template
2. **Flexible configuration**: Values can be easily customized through values.yaml
3. **Multiple routes support**: Can define multiple HTTPRoutes with different routing rules
4. **TLS support**: Includes configuration for HTTPS listeners with TLS termination
5. **Path-based routing**: Supports various matching criteria including paths, headers, and query parameters
6. **Helper templates**: Includes standard Helm helpers for labels and naming
To use this chart, ensure you have the Gateway API CRDs installed in your cluster and a compatible Gateway controller (like Contour, NGINX Gateway Fabric, or HAProxy).