Deploy Envoy Gateway and HTTPRoute

The information herein demonstrates how to deploy an application using an Envoy Gateway and expose it with an HTTPRoute.

  1. Deploy a sample application:

    kubectl apply -n gateway-test -f - <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: echo-server
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: echo-server
      template:
        metadata:
          labels:
            app: echo-server
        spec:
          containers:
          - name: echo
            image: hashicorp/http-echo:0.2.3
            args:
            - "-text=hello from envoy gateway"
            ports:
            - containerPort: 5678
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: echo-server
    spec:
      selector:
        app: echo-server
      ports:
      - port: 80
        targetPort: 5678
        protocol: TCP
    EOF
    
  2. Create the Envoy Gateway using gatewayClassName: mke-gateway-ingress. The EnvoyProxy you previously created is in the same namespace and is referenced under infrastructure.parametersRef:

    kubectl apply -n gateway-test -f - <<'EOF'
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: test-gateway
    spec:
      gatewayClassName: mke-gateway-ingress
      infrastructure:
        parametersRef:
          group: gateway.envoyproxy.io
          kind: EnvoyProxy
          name: envoy-gateway-proxy
      listeners:
      - name: http
        protocol: HTTP
        port: 80
        allowedRoutes:
          namespaces:
            from: Same
    EOF
    
  3. Create the HTTPRoute. The code example details one backend, the echo-server service:

    Important

    backendRefs.name must be identical to the Kubernetes Service name.

    kubectl apply -n gateway-test -f - <<'EOF'
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: echo-route
    spec:
      parentRefs:
      - name: test-gateway
        namespace: gateway-test
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /
        backendRefs:
        - name: echo-server
          port: 80
    EOF
    
  4. Retrieve the NodePorts:

    export GATEWAY_HTTP_NODEPORT=$(kubectl get svc -n envoy-gateway-system -l gateway.envoyproxy.io/owning-gateway-name=test-gateway -o jsonpath='{.items[0].spec.ports[?(@.name=="http-80")].nodePort}')
    echo "HTTP NodePort: $GATEWAY_HTTP_NODEPORT"
    
  5. Select a node IP that the clients can reach (ExternalIP or InternalIP), or use port-forward for local testing:

    GATEWAY_SVC=$(kubectl get svc -n envoy-gateway-system -l gateway.envoyproxy.io/owning-gateway-name=test-gateway -o jsonpath='{.items[0].metadata.name}')
    kubectl port-forward -n envoy-gateway-system svc/$GATEWAY_SVC 8080:80