Skip to content

Gateway API

Now we want to make our guestbook available with SSL and by a fancy hostname instead of an random IP of the Load-Balancer-Service. But this time we use the Gateway API instead of ingress.

1. Create a Gateway

Create a gateway resource in the mongo namespace with the following specs:

name: example-gateway
gatewayClassName: example-gateway-class
port: 80
hostname: [hostname]
It should allow rules from the same namespace.


HINT

1. Lookup the examples from the Kubernetes Documentation
2. Take 12 - Gateway API/1-gateway-resource.yaml as a reference



2. Apply changes to the Application

As this is a fairly simple setup with just one application backend, we do not need to add any other rules to the Ingress Resource. All functionality is currently handled by the example application Deployment.

For production ready applications we would consider splitting the features of the app into several Deployments. Then we could route to them by defining more rules on the Ingress Resource.

Another option is to define several hostnames within the resource.

But for now we just want to connect the example-app Deployment.

Therefore, delete the example-svc-lb Load Balancer Service. As a replacement, create the Cluster IP Service we mentioned earlier:

name: example-service-cip
type: ClusterIP
port: 80
targetPort: 8080
selector: app = example-app
HINT

1. Use the imperative command:

Solution

$ kubectl expose deploy example-app --port 80 --target-port 8080 --name example-service-cip --dry-run=client -o yaml > clusterIP-service.yaml


1. Check the generated yaml and make sure everything is fine, before deploying it
2. Take 12 - Gateway API/2-clusterIP-service as a reference

3. Create HttpRoute

Now that we created the gateway, we need to create a HttpRoute resource for setting the rules and bind it to the gateway.

name: example-route
backend: example-service-cip
servicePort: 80
HINT


1. Check the generated yaml and make sure everything is fine, before deploying it
2. Take 12 - Gateway API/3-http-route-resource as a reference