Use Gateway API to Expose a Workload in SAP BTP, Kyma Runtime
Use Gateway API to expose a workload.
Overview
You will learn
- How to install Gateway API CRDs in SAP BTP, Kyma runtime
- How to create and expose a sample workload using Gateway API
Prerequisites
Steps
Intro
Learn how to expose a workload in SAP BTP, Kyma runtime using Gateway API. Gateway API allows you to expose workloads using Kubernetes resources like Gateway and HTTPRoute, with Istio integration for managing ingress traffic.
Exposing an unsecured workload to the outside world is a potential security vulnerability, so be careful. If you want to use this example in a production environment, make sure to secure your workload.
A Gateway API bundle is a collection of Custom Resource Definitions (CRDs) tied to a specific version of Kubernetes Gateway API. Each release of Gateway API provides two channels, standard and regular, which offer different stability levels. The standard release channel includes all resources that have reached General Availability (GA) or beta status, such as GatewayClass, Gateway, HTTPRoute, and ReferenceGrant. These channels are unrelated to Kymaβs fast and regular channels. The Istio module provided by SAP BTP, Kyma runtime supports the Gateway API CRDs installed from the standard channel.
If youβve already installed Gateway API CRDs from the experimental channel, you must delete them before installing Gateway API CRDs from the standard channel.
To install Gateway API CustomResourceDefinitions (CRDs) from the standard channel, run the following command:
Shell/Bashkubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \ { kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.1.0" | kubectl apply -f -; }
Export the name of the namespace in which you want to deploy a sample HTTPBin Service:
Shell/Bashexport NAMESPACE={service-namespace}Create a namespace with Istio injection enabled and deploy the HTTPBin Service:
Shell/Bashkubectl create ns $NAMESPACE kubectl label namespace $NAMESPACE istio-injection=enabled --overwrite kubectl create -n $NAMESPACE -f https://raw.githubusercontent.com/istio/istio/master/samples/httpbin/httpbin.yaml
Create a Kubernetes Gateway to deploy Istio Ingress Gateway:
Shell/Bashcat <<EOF | kubectl apply -f - apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: httpbin-gateway namespace: ${NAMESPACE} spec: gatewayClassName: istio listeners: - name: http hostname: "httpbin.kyma.example.com" port: 80 protocol: HTTP allowedRoutes: namespaces: from: Same EOFThis command deploys the Istio Ingress service in your namespace with the corresponding Kubernetes Service of type LoadBalanced and an assigned external IP address.
Create an HTTPRoute to configure access to your workload:
Shell/Bashcat <<EOF | kubectl apply -f - apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin namespace: ${NAMESPACE} spec: parentRefs: - name: httpbin-gateway hostnames: ["httpbin.kyma.example.com"] rules: - matches: - path: type: PathPrefix value: /headers backendRefs: - name: httpbin namespace: ${NAMESPACE} port: 8000 EOF
To access your exposed workload, follow the steps:
Discover Istio Ingress Gatewayβs IP and port:
Shell/Bashexport INGRESS_HOST=$(kubectl get gtw httpbin-gateway -n $NAMESPACE -o jsonpath='{.status.addresses[0].value}') export INGRESS_PORT=$(kubectl get gtw httpbin-gateway -n $NAMESPACE -o jsonpath='{.spec.listeners[?(@.name=="http")].port}')Call the service:
Shell/Bashcurl -s -I -HHost:httpbin.kyma.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"If successful, you get the code
200 OKin response.This task assumes thereβs no DNS setup for the httpbin.kyma.example.com host, so the call contains the host header.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.