# Gateway API: Modern Kubernetes Traffic Routing replacing Ingress

Kubernetes networking has evolved significantly over the years. Traditional Ingress controllers solved many problems, but they were often limited in flexibility and extensibility.

The **Gateway API** introduces a more powerful and expressive model for managing traffic in Kubernetes clusters.

In this guide, we will build a **modern traffic routing architecture using KGateway and the Gateway API on Kubernetes**.

* * *

**Advantages**:

*   Better than traditional Ingress
    
*   Standard Kubernetes networking API
    
*   Flexible routing rules
    
*   Multi-cluster support
    
*   Advanced traffic management
    

* * *

**We will cover:**

*   Installing Gateway API CRDs
    
*   Deploying the KGateway controller
    
*   Creating a Gateway
    
*   Deploying an application
    
*   Routing traffic using HTTPRoute
    

| Component | Purpose |
| --- | --- |
| Gateway API CRDs | Extend Kubernetes networking |
| KGateway Controller | Implements the Gateway API |
| Gateway | Entry point for external traffic |
| HTTPRoute | Defines traffic routing rules |
| Service | Internal load balancing |
| Pods | Running application |

### Environment Setup

Create an EC2 Instance with `t2-medium` and `30gb gp3` disk, it will be used as a jump host to manage the cluster

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/cf97144e-db1c-4124-9d89-8216e0fb1bb6.png align="center")

```plaintext
sudo apt update
```

*   ### Connect to EC2 by SSH
    
*   ### Clone the [repo](https://github.com/abhinandan-chougule/eks-terraform-code.git)
    

This will create all basic configurations for EKS

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/df4aef7b-32df-4985-b9fd-33f9df77b517.png align="center")

*   **Install AWS CLI**
    

```plaintext
#!/bin/bash

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
aws configure
```

*   ### Create an Access key and secret key if its first time using the AWS console, and Enter into the console when it asks while installing AWS CLI
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/8e82995f-c96a-4c09-b866-c664a4c6c5da.png align="center")

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/eeec8484-6ccf-47c5-9765-e2210315bc76.png align="center")

*   **Install Terraform**
    

```plaintext
#!/bin/bash

#Update system package
sudo apt-get update

#Install GNU software properties and curl packages
sudo apt-get install -y gnupg software-properties-common -y

#Install the HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null

#Verify the key's fingerprint
gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update
sudo apt-get install terraform -y

terraform --version
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/ef576e23-df15-4fd2-a29f-c7b0444bfb42.png align="center")

*   **Install Kubectl**
    

```plaintext
#!/bin/bash

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version --short --client
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/aa89a919-dae4-4d94-8ddb-41168c1f8138.png align="center")

*   `aws configure` **to connect with the AWS account**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/f2349d33-223e-439e-9607-748dfd4de94b.png align="center")

*   `aws sts get-caller-identity` to Verify Account
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/5ccda608-fde0-49e1-8c38-ae48bd14bad2.png align="center")

*   `cd` **to the directory and** `Terraform init`
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/017932b7-7b9d-40c5-8b94-8b7a82426be8.png align="center")

*   `terraform plan`
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/b4465a02-9732-4b56-adb7-7bcaa55a3e3c.png align="center")

*   **Apply the changes to deploy EKS**
    

`terraform apply --auto-approve`

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/43814715-e9b8-491a-9077-4ff5f4dda6fe.png align="center")

*   **Install helm**
    

```plaintext
sudo apt update & sudo apt upgrade -y
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/dc7c67fb-6a54-4429-95cb-4548543ffde3.png align="center")

*   **Verify if the cluster is accessible**
    

```shell
aws eks --region ap-southeast-1 update-kubeconfig --name askabhi-cluster

kubectl get nodes
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/6766fcb2-bf94-4f84-a48a-6a43325453be.png align="center")

*   **Install CRD for kgateway by helm upgrade**
    

> Note: **Prerequisites**
> 
> Before you begin, ensure you have:
> 
> *   A Kubernetes cluster.
>     
> *   `kubectl` installed and configured to communicate with your cluster.
>     
> *   `helm` installed, the package manager for Kubernetes.
>     

**Install the Kubernetes kgateway CRD and Gateway API CRDs (Custom Resource Definitions)**  
Kgateway is an implementation of the Kubernetes Gateway API, which requires specific CRDs to be present in your cluster. The official documentation recommends installing the CRDs separately from the main `kgateway` chart.

```plaintext
helm upgrade -i --create-namespace --namespace kgateway-system kgateway-crds oci://cr.kgateway.dev/kgateway-dev/charts/kgateway-crds --version v2.3.0-main
```

*(Note: The* `--version` *tag may need to be updated to the* [***latest release***](https://github.com/kgateway-dev/kgateway/releases)*.)*

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/a9189b5b-c7ad-4c78-aeb1-807bc3535b19.png align="center")

**Install the Kgateway Controller**  
Once the CRDs are in place, install the main `kgateway` controller.

```plaintext
helm upgrade -i --namespace kgateway-system kgateway oci://cr.kgateway.dev/kgateway-dev/charts/kgateway --version v2.3.0-main
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/418571f4-906d-456d-85f4-38a15a8f3c06.png align="center")

**Verify the Installation**  
After the installation is complete, verify that the `kgateway` pods are running in the `kgateway-system` namespace.

```plaintext
kubectl get pods -n kgateway-system
```

You should see pods with a `Running` status. You can also verify that the `GatewayClass` resource named `kgateway` has been created.

<mark class="bg-yellow-200 dark:bg-yellow-500/30">We need to decide which controller needs to be used</mark>

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/2ca96657-0d01-4a47-9a96-37114c4ff091.png align="center")

```plaintext
kubectl get gatewayclass kgateway
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/47f88b85-c0b1-4631-9e1d-efbf82375efa.png align="center")

*   **Install the Gateway API CRDs**
    

First, apply the standard CRDs from the official Kubernetes sigs [**GitHub repository**](https://github.com/kubernetes-sigs/gateway-api) to your cluster. The standard channel is recommended for most users as it includes stable (GA or beta) resources:

```plaintext
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.0/standard-install.yaml
```

**To verify the installation, you can run:**

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/d1662e17-b27f-41b9-87b0-87383025820d.png align="center")

**Verify**

```plaintext
kubectl get crds | grep gateway
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/db142be7-db8a-4853-ab2d-d1b060871a79.png align="center")

Install the httpbin Application

The `httpbin` sample application for [**kgateway**](https://kgateway.dev/docs/envoy/2.0.x/install/sample-app/) (formerly part of Gloo) can be deployed in Kubernetes using the following command to test routing rules:

```plaintext
kubectl apply -f https://raw.githubusercontent.com/kgateway-dev/kgateway/refs/heads/main/examples/httpbin.yaml
```

**Purpose**: This YAML deploys a `httpbin` service in a namespace (typically `httpbin`), which is used to verify that the Gateway proxy is correctly routing external traffic to backend services.

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/0a75e158-3590-4016-8363-3c3946691d30.png align="center")

**Verify what the namespaces we have are**

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/9021be64-d995-4e05-b128-fc6761a7bc06.png align="center")

**Check the route for the gateway**

```plaintext
kubectl get gateway
```

**Traffic is going to which service**

```plaintext
kubectl apply -f- <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: kgateway-system
spec:
  gatewayClassName: kgateway
  listeners:
  - name: http
    protocol: HTTP
    port: 80
    # Optional: restricts which namespaces can attach routes to this listener
    allowedRoutes:
      namespaces:
        from: All # Other options: Same, Selector
EOF
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/4814f531-4c9d-4aba-b9f3-13f4c56447da.png align="center")

**Check gateway Created**

```plaintext
kubectl get gateway
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/7be32513-dda2-4b7c-b796-38da755a55e1.png align="center")

The address shown in the above snap is Cloud Load Balancer `a243521ba1b904868a7d7b8707db3b7c-2045018130.ap-southeast-1.elb.amazonaws.com`

*   **Copy this and go to GoDaddy and add a CNAME**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/5d9a3fe5-848d-47aa-a45b-7b937dedc235.png align="center")

*   Go back to the server and do `nslookup` for the Cloud Load Balancer and get the IP.
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/102f0d99-208c-4291-aa85-8304cfbe5080.png align="center")

> Note- we should see the IP's like below else wait

*   **Add an** `A` **record with the IP you see**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/a920703b-e952-441c-a5df-9c44d5ea16fd.png align="center")

**Route the traffic to the Domain**

```yaml
kubectl apply -f- <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: httpbin
  namespace: httpbin
spec:
  parentRefs:
  - name: kgateway-system
    namespace: default
  hostnames:
  - "mytestproject.shop"
  rules:
  - backendRefs:
    - name: httpbin
      port: 8000
EOF
```

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/f7c7b8ed-fe90-4274-b850-f57324729e3c.png align="center")

*   **What did we do? We pointed out the following** `service/httpbin` **to route through the domain**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/f670d96f-ca76-41ba-8e73-258dd1082608.png align="center")

*   Now you can try to access the Domain
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/6711f183-824d-4009-a9d8-2b60a21d2086.png align="center")

* * *

**Conclusion**:

Kubernetes networking continues to evolve, and the Gateway API represents the next step forward in traffic management.

By combining **Gateway API and KGateway**, we can build scalable and flexible networking architectures that are easier to manage than traditional ingress-based setups.

This architecture enables modern DevOps teams to implement advanced routing patterns while keeping Kubernetes networking standardized and maintainable.
