VK Cloud logo

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.

Preparatory steps

  1. Create a Kubernetes cluster of the latest version, if not done so already.
  2. Install and configure kubectl, if not done so already.
  3. Connect to the cluster via kubectl.
  4. Install the Kgateway add-on, if not done so already.

1. Create a test application

  1. Create the httpbin.yaml manifest for the httpbin test application:

    apiVersion: v1kind: Namespacemetadata:  name: httpbin---apiVersion: v1kind: Servicemetadata:  name: httpbin  namespace: httpbinspec:  ports:    - port: 8000      targetPort: 8080  selector:    app: httpbin---apiVersion: apps/v1kind: Deploymentmetadata:  name: httpbin  namespace: httpbinspec:  replicas: 1  selector:    matchLabels:      app: httpbin  template:    metadata:      labels:        app: httpbin    spec:      containers:        - name: httpbin          image: docker.io/mccutchen/go-httpbin:v2.6.0          ports:            - containerPort: 8080
  2. 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.

2. Create a Gateway object

  1. Create the my-gateway.yaml manifest for the Gateway API resource of the Gateway type:

    apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata:  name: http  namespace: httpbinspec:  gatewayClassName: kgateway  listeners:    - name: http      protocol: HTTP      port: 8080
  2. 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.

3. Create an HTTPRoute object

  1. Create the my-route.yaml manifest for the Gateway API resource of the HTTPRoute type, which specifies the HTTP traffic routing rule for Kgateway:

    apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata:  name: httpbin  namespace: httpbinspec:  parentRefs:    - name: http  rules:    - backendRefs:        - name: httpbin          port: 8000
  2. 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.

4. Test Kgateway

  1. 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 httpbin

    In the table that displays, find the EXTERNAL-IP value for the load balancer:

    NAME     TYPE             ...     EXTERNAL-IP        PORT(S)            ...http     LoadBalancer     ...     100.70.151.108     8080:30000/TCP     ...
  2. Send a test request to the external IP address of the load balancer:

    curl http://100.70.151.108:8080/get

    A successful response to the request means that Kgateway correctly handles Gateway API resources and routes traffic to the httpbin service.

Delete unused resources

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:

  1. Delete the httpbin namespace and the resources associated with it, including the load balancer and Floating IP address:

    kubectl delete namespace httpbin
  2. Stop the cluster you created to use it later or delete it permanently.