Route traffic with a Kubernetes Ingress resource

Incompatible with
konnect
Related Documentation
TL;DR

Set the spec.ingressClass field in the ControlPlane resource to match your Ingress resource’s spec.ingressClassName.

Prerequisites

  1. Add the Kong Helm charts:

    helm repo add kong https://charts.konghq.com
    helm repo update
    
  2. Install Kong Operator using Helm:

    helm upgrade --install kong-operator kong/kong-operator -n kong-system \
      --create-namespace \
      --set image.tag=2.1.0 \
      --set env.ENABLE_CONTROLLER_KONNECT=true
    
    helm upgrade --install kong-operator kong/kong-operator -n kong-system \
      --create-namespace \
      --set image.tag=2.1.0
    

    If you want cert-manager to issue and rotate the admission and conversion webhook certificates, install cert-manager to your cluster and enable cert-manager integration by passing the following argument while installing, in the next step:

    --set global.webhooks.options.certManager.enabled=true
    

    If you do not enable this, the chart will generate and inject self-signed certificates automatically. We recommend enabling cert-manager to manage the lifecycle of these certificates.

    Kong Operator needs a certificate authority to sign the certificate for mTLS communication between the control plane and the data plane. This is handled automatically by the Helm chart. If you need to provide a custom CA certificate, refer to the certificateAuthority section in the values.yaml of the Helm chart to learn how to create and reference your own CA certificate.

This tutorial doesn’t require a license, but you can add one using KongLicense. This assumes that your license is available in ./license.json.

echo "
apiVersion: configuration.konghq.com/v1alpha1
kind: KongLicense
metadata:
 name: kong-license
rawLicenseString: '$(cat ./license.json)'
" | kubectl apply -f -

While the Kubernetes Gateway API is the preferred mechanism for configuring inbound routing, Kong Operator also supports the Kubernetes Ingress resource.

Create the kong namespace

Create the kong namespace in your Kubernetes cluster, which is where the demo will run:

kubectl create namespace kong

Create the GatewayConfiguration

Create a GatewayConfiguration resource to customize the deployment options for your data plane and control plane:

echo '
apiVersion: gateway-operator.konghq.com/v2beta1
kind: GatewayConfiguration
metadata:
  name: kong-ingress-config
  namespace: kong
spec:
  dataPlaneOptions:
    deployment:
      replicas: 1
' | kubectl apply -f -

Create the DataPlane

Create a DataPlane resource to define the Kong Gateway deployment:

echo '
apiVersion: gateway-operator.konghq.com/v1beta1
kind: DataPlane
metadata:
  name: kong-ingress-dp
  namespace: kong
spec:
  deployment:
    podTemplateSpec:
      spec:
        containers:
        - name: proxy
          image: kong/kong-gateway:3.13
' | kubectl apply -f -

Create the ControlPlane

Create a ControlPlane resource to define the controller that will manage the DataPlane. To enable Ingress support, you must specify the spec.ingressClass field:

echo '
apiVersion: gateway-operator.konghq.com/v2beta1
kind: ControlPlane
metadata:
  name: kong-ingress-cp
  namespace: kong
spec:
  dataplane:
    type: ref
    ref:
      name: kong-ingress-dp
  ingressClass: kong
' | kubectl apply -f -

Create the echo Service

Run the following command to create a sample echo Service:

kubectl apply -f https://developer.konghq.com/manifests/kic/echo-service.yaml -n kong

Create the Ingress

Create an Ingress resource that points to the echo service and specify the spec.ingressClass configured in the ControlPlane resource in the spec;ingressClassName field:

echo '
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: echo-ingress
  namespace: kong
spec:
  ingressClassName: kong
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: echo
            port:
              number: 1027
' | kubectl apply -f -

Validate

  1. Check that the resources have been created:

    kubectl get controlplane,dataplane,ingress -n kong
    
  2. Get the external IP of the DataPlane service:

    export PROXY_IP=$(kubectl get svc -n kong -l app=kong-ingress-dp,gateway-operator.konghq.com/dataplane-service-type=ingress -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')
    
  3. Send a request to the Ingress:

    curl -i http://$PROXY_IP/
    
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!