Patch our gateway to allow routes in any namespace:
kubectl patch --type=json gateways.gateway.networking.k8s.io kong -p='[{"op":"replace","path": "/spec/listeners/0/allowedRoutes/namespaces/from","value":"All"}]'
This is required because in the Kong ingress controller tutorial the gateway is created in the default
namespace.
To do this the Gateway API spec requires to explicitly allow routes from different namespaces.
Now add the gateway route in our kuma-demo
namespace which binds to the gateway kong
defined in the default
namespace:
echo "apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: demo-app
namespace: kuma-demo
spec:
parentRefs:
- name: kong
namespace: default
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: demo-app
kind: Service
port: 5000 " | kubectl apply -f -
This route is managed by the Kong ingress controller and not by Kuma.
Now call the gateway:
Which outputs:
HTTP/1.1 403 Forbidden
Content-Type: text/plain; charset=UTF-8
Content-Length: 19
Connection: keep-alive
date: Fri, 09 Feb 2024 15:51:10 GMT
server: envoy
x-envoy-upstream-service-time: 0
X-Kong-Upstream-Latency: 2
X-Kong-Proxy-Latency: 0
Via: kong/3.5.0
X-Kong-Request-Id: 3b9d7d0db8c4cf25759d95682d6e3573
RBAC: access denied%
Notice the forbidden error.
This is because the quickstart has very restrictive permissions as defaults.
Therefore, the gateway doesn’t have permissions to talk to the demo-app service.
To fix this, add a MeshTrafficPermission
:
echo "apiVersion: kuma.io/v1alpha1
kind: MeshTrafficPermission
metadata:
namespace: kuma-demo
name: demo-app
spec:
targetRef:
kind: Dataplane
labels:
app: demo-app
from:
- targetRef:
kind: MeshSubset
tags:
app.kubernetes.io/name: gateway
k8s.kuma.io/namespace: kong
default:
action: Allow" | kubectl apply -f -
Call the gateway again:
curl -i $PROXY_IP/increment -XPOST
Notice that the call succeeds:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 41
Connection: keep-alive
x-powered-by: Express
etag: W/"29-iu9zuSv48n703xjnEeBnBQzQFgA"
date: Fri, 09 Feb 2024 15:57:27 GMT
x-envoy-upstream-service-time: 7
server: envoy
X-Kong-Upstream-Latency: 11
X-Kong-Proxy-Latency: 0
Via: kong/3.5.0
X-Kong-Request-Id: 886cc96df034ea37cfbbb0450a987049
{"counter":149,"zone":"local","err":null}%