Question:
Configure a web-portal-httproute within the cka3658 namespace
to facilitate traffic distribution. Route 80% of the traffic to
web-portal-service-v1 and 20% to the new version,
web-portal-service-v2.
Note: Gateway has already been created in the nginx-gateway
namespace.
To test the gateway, execute the following command:
curl http://cluster2-controlplane:30080
I was able to successfully reach both services running the curl command above (see evidence below):
cluster2-controlplane ~ ➜ curl http://cluster2-controlplane:30080
<html>
<head><title>Welcome</title></head>
<body>
<h1>Hello from Web Portal App 1</h1>
</body>
</html>
cluster2-controlplane ~ ➜ curl http://cluster2-controlplane:30080
<html>
<head><title>Welcome</title></head>
<body>
<h1>Hello from Web Portal App 2</h1>
</body>
</html>
cluster2-controlplane ~ ➜ curl http://cluster2-controlplane:30080
but when I was marked, I got one index wrong and I am hoping for some explanation as to why. I cross-checked the provided yaml file with the one I used. I notices in the rules section there was path-based routing configured (even though the question doesn’t seem to explicitly require this). I will also provide my yaml and the one provided by the examiner immediately after the indexes. Thank you very much.
Is the HttpRoute referring to the NGINX gateway?
Is the web-portal-httproute routing 80% traffic to web-portal-service-v1?
Is the web-portal-httproute routing 20% traffic to web-portal-service-v2?
Is the web-portal-httproute distributing traffic?
Examiner’s solution
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: web-portal-httproute
namespace: cka3658
spec:
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: web-portal-service-v1
port: 80
weight: 80
- name: web-portal-service-v2
port: 80
weight: 20
My solution:
cluster2-controlplane ~ ➜ cat httproute.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: web-portal-httproute
namespace: cka3658
spec:
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
hostnames:
- cluster2-controlplane
rules:
- backendRefs:
- name: web-portal-service-v1
port: 80
weight: 80
- name: web-portal-service-v2
port: 80
weight: 20