I am looking to create a kubernetes gateway with an internal ip. I see I would need a gatewayclass to be one of gke-l7-rilb gke-l7-rilb-mc. I see on
https://cloud.google.com/kubernetes-engine/docs/how-to/gatewayclass-capabilities#spec-rules-backendrefs that backendRef.name is not checked for either of those gateway classes. So how do I specify the backend service when using these gateway classes?
1 Like
Hi,
You could specify the backend services using the Gateway Classes using the following steps:
(1) Create a GatewayClass
apiVersion: networking.x-k8s.io/v1alpha1
kind: GatewayClass
metadata:
name: my-internal-gateway-class
spec:
controller: networking.gke.io/gateway
parametersRef:
group: networking.gke.io
kind: GKEGateway
name: my-internal-gateway-params
(2) Define Gateway Parameters
apiVersion: networking.gke.io/v1
kind: GKEGateway
metadata:
name: my-internal-gateway-params
spec:
locationType: Regional
internal: true
(3) Deploy a Gateway Using the GatewayClass
apiVersion: networking.x-k8s.io/v1alpha1
kind: Gateway
metadata:
name: my-internal-gateway
spec:
gatewayClassName: my-internal-gateway-class
listeners:
- protocol: HTTP
port: 80
routes:
kind: HTTPRoute
selector:
matchLabels:
app: my-app
group: networking.x-k8s.io
(4) Specify Backend Services Using HTTPRoute
apiVersion: networking.x-k8s.io/v1alpha1
kind: HTTPRoute
metadata:
name: my-http-route
labels:
app: my-app
spec:
gateways:
allow: All
hostnames:
- "example.com"
rules:
- matches:
- path:
type: Prefix
value: /
backendRefs:
- name: my-backend-service
port: 80
I hope that helps
Kind regards
Mahmoud
The doc is a little tricky. The one green check in the middle means itβs supported across all gateway classes.
Hi @g3289ds ,
You can try using HTTPRoute resource that references a Service using the backendRef field to create a Kubernetes Gateway with an internal IP using the gke-l7-rilb or gke-l7-rilb-mc GatewayClass and specify the backend service.
Even though the backendRef.name field is not checked for gke-l7-rilb and gke-l7-rilb-mc GatewayClasses, you can still use the backendRef field to reference a Service.
Below is my example of a HTTPRoute resource that references a Service with the name my-service in the same namespace:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: my-httproute
spec:
parentRefs:
- name: internal-http
sectionName: http
rules:
- matches:
- path: /my-path
backendRefs:
- name: my-service
For this, the parentRefs field references the Gateway resource named internal-http and the sectionName field specifies the http section of the Gateway resource. The rules field specifies the traffic routing rules. The matches field specifies the traffic matching conditions and the backendRefs field references the Service named my-service in the same namespace.
Just an important reminder:
Make sure that the Gateway resource named internal-http is already created and deployed as shown in the documentation.
If I wanted multiple hostnames and backends I would I need to create separate HTTPRoute rules for each hostname and associated rules? I know I can put multiple rules in the same file with β but I am wondering if I need to have multiple rules for this.