Using Kgateway
Use the Kgateway addon to configure traffic routing in a Kubernetes cluster via the Gateway API and send requests to the test application.
- Create a Kubernetes cluster of the latest version, if not done so already.
- Install and configure
kubectl, if not done so already. - Connect to the cluster via
kubectl. - Install the Kgateway add-on, if not done so already.
-
Create the
httpbin.yamlmanifest for thehttpbintest application:apiVersion: v1kind: Namespacemetadata:name: httpbin---apiVersion: v1kind: Servicemetadata:name: httpbinnamespace: httpbinspec:ports:- port: 8000targetPort: 8080selector:app: httpbin---apiVersion: apps/v1kind: Deploymentmetadata:name: httpbinnamespace: httpbinspec:replicas: 1selector:matchLabels:app: httpbintemplate:metadata:labels:app: httpbinspec:containers:- name: httpbinimage: docker.io/mccutchen/go-httpbin:v2.6.0ports:- containerPort: 8080 -
Apply the manifest in the cluster:
kubectl apply -f httpbin.yaml
As a result of applying the manifest, the httpbin test application is launched as a Deployment, and a service for internal access to this application is created. Further, Kgateway will accept external HTTP traffic, route it, and redirect it to this service.
-
Create the
my-gateway.yamlmanifest for the Gateway API resource of theGatewaytype:apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata:name: httpnamespace: httpbinspec:gatewayClassName: kgatewaylisteners:- name: httpprotocol: HTTPport: 8080 -
Apply the manifest in the cluster:
kubectl apply -f my-gateway.yaml
As a result of applying the manifest, Kgateway creates a LoadBalancer type service. VK Cloud then automatically creates a standard load balancer and assigns it with a public Floating IP address for receiving traffic.
-
Create the
my-route.yamlmanifest for the Gateway API resource of theHTTPRoutetype, which specifies the HTTP traffic routing rule for Kgateway:apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata:name: httpbinnamespace: httpbinspec:parentRefs:- name: httprules:- backendRefs:- name: httpbinport: 8000 -
Apply the manifest in the cluster:
kubectl apply -f my-route.yaml
As a result of applying the manifest, HTTP requests will be sent to the httpbin service.
-
Wait a few minutes for the load balancer to receive an external IP address, and run the command to get it:
kubectl get svc -n httpbinIn the table that displays, find the
EXTERNAL-IPvalue for the load balancer:NAME TYPE ... EXTERNAL-IP PORT(S) ...http LoadBalancer ... 100.70.151.108 8080:30000/TCP ... -
Send a test request to the external IP address of the load balancer:
curl http://100.70.151.108:8080/getA successful response to the request means that Kgateway correctly handles Gateway API resources and routes traffic to the
httpbinservice.
A running cluster consumes computing resources and is charged accordingly. If you no longer need the Kubernetes resources you created to test the Kgateway add-on, delete them: