Migrate a Gateway API configuration to Kong Operator

Migrate your existing Gateway API routes from Kong Ingress Controller to Kong Operator while you keep the Service and address your clients use. During validation, you attach each route to both the old Gateway and the replacement Gateway. After cutover, you detach the routes from the old Gateway.

When you finish this guide, a Kong Operator-managed gateway serves traffic behind your retained Service. You continue to manage that Service yourself. If you use both Ingress and Gateway API resources, start with the migration overview.

Supported route types

The examples in this guide use HTTPRoute. KO also supports other Gateway API route types on on-prem gateways, depending on its version:

Route type

Minimum KO version

HTTPRoute All supported versions
TLSRoute 2.2
GRPCRoute, TCPRoute, UDPRoute 2.3

To migrate other route types, add a listener with the matching protocol to the replacement Gateway. The route controllers are enabled by default. Don’t disable them in the controllers list of the GatewayConfiguration. For more information, see Gateway API controllers.

A GRPCRoute attached to an HTTP listener needs http2 in the KONG_PROXY_LISTEN environment variable of the gateway container.

KO reads TLSRoute resources through the Gateway API v1 version. Before you migrate TLSRoute resources, check that the TLSRoute CRD in your cluster serves v1:

kubectl get crd tlsroutes.gateway.networking.k8s.io -o jsonpath='{.spec.versions[*].name}'

If the output doesn’t include v1, upgrade your Gateway API CRDs.

Before you begin

This guide assumes a DB-less installation deployed with the kong/kong or kong/ingress Helm chart, and uses an HTTP listener on port 80. The replacement gateway must be in the same namespace as the existing proxy Service. If you use HTTPS or other protocols, adapt the listeners and validation requests.

You need the following tools and access:

  • Administrative access to the cluster
  • Bash
  • Helm
  • kubectl
  • jq
  • cert-manager

Before you start, back up your Kubernetes configuration and Helm values, and upgrade to Kong Ingress Controller 3.5. Make sure the cluster has enough capacity to run both installations at the same time.

Set the following values for your installation. To find the existing release name and chart version, run helm list. Keep the current gateway image, and choose a replica count that can serve your traffic. KO only deploys Kong Gateway 3.4.1 or later. If your current image is older, upgrade it before you start.

export NAMESPACE=default
export RELEASE_NAME=kong
export KIC_CHART_VERSION='<installed-chart-version>'
export PROXY_SERVICE=kong-proxy
export GATEWAY_IMAGE='<current-image:tag>'
export GATEWAY_REPLICAS=2
export OLD_GATEWAY='<existing-gateway>'
export OLD_GATEWAY_CLASS='<existing-gateway-class>'

This guide names the new resources kong-migrated. If that name is already in use, choose another name and use it throughout this guide.

The route examples assume that the routes and both Gateways are in $NAMESPACE. If your routes are in other namespaces, set the namespace in the parent reference, and configure the replacement listener to allow routes from those namespaces. If you use GitOps, update the route manifests so that reconciliation doesn’t revert the migration changes.

Preserve the existing Service

To keep the proxy Service and its address when you uninstall KIC, add the helm.sh/resource-policy: keep annotation to your existing Helm values. This way, Helm records the annotation in the release manifest. Use the tab for your installed chart.

Check that the Service has the helm.sh/resource-policy: keep annotation:

kubectl get svc -n "$NAMESPACE" "$PROXY_SERVICE" -o yaml

Add the retained Service to the manifests you maintain. If you use GitOps, make sure that it preserves this Service and the selector you set during cutover.

Install Kong Operator

Update the Kong Helm repository:

helm repo update kong

Install KO alongside your existing installation:

helm upgrade --install kong-operator kong/kong-operator \
  -n kong-system \
  --create-namespace \
  --take-ownership \
  --set env.ENABLE_CONTROLLER_KONNECT=true \
  --set ko-crds.enabled=true \
  --set global.webhooks.conversion.enabled=true \
  --set global.webhooks.options.certManager.enabled=true

Check that the KO pods are running:

kubectl get pods -n kong-system

Complete any Kong Operator upgrades before cutover. Avoid Kong Operator restarts while you change routing resources.

Create the replacement gateway

The replacement gateway uses its own Gateway and GatewayClass. Keep the existing Gateway, GatewayClass, and routing resources in place until cleanup.

Create a GatewayConfiguration, a GatewayClass, and a Gateway that use your current image and replica count. The new Service is internal (ClusterIP), so it doesn’t change client traffic:

cat <<EOF | kubectl apply -f -
kind: GatewayConfiguration
apiVersion: gateway-operator.konghq.com/v2beta1
metadata:
  name: kong-migrated
  namespace: ${NAMESPACE}
spec:
  dataPlaneOptions:
    deployment:
      replicas: ${GATEWAY_REPLICAS}
      podTemplateSpec:
        spec:
          containers:
          - name: proxy
            image: ${GATEWAY_IMAGE}
    network:
      services:
        ingress:
          type: ClusterIP
  controlPlaneOptions:
    cache:
      initSyncDuration: 30s
    controllers:
    - name: GWAPI_GATEWAY
      state: enabled
    - name: GWAPI_HTTPROUTE
      state: enabled
    - name: KONG_PLUGIN
      state: enabled
    - name: KONG_CONSUMER
      state: enabled
---
kind: GatewayClass
apiVersion: gateway.networking.k8s.io/v1
metadata:
  name: kong-migrated
spec:
  controllerName: konghq.com/gateway-operator
  parametersRef:
    group: gateway-operator.konghq.com
    kind: GatewayConfiguration
    name: kong-migrated
    namespace: ${NAMESPACE}
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1
metadata:
  name: kong-migrated
  namespace: ${NAMESPACE}
spec:
  gatewayClassName: kong-migrated
  listeners:
  - name: http
    protocol: HTTP
    port: 80
EOF

Wait for the Gateway to report Programmed:

kubectl wait -n "${NAMESPACE}" --for=condition=Programmed --timeout=300s gateway/kong-migrated

When the Gateway is programmed, you can attach routes to it.

Attach routes to both Gateways

A route attaches to a Gateway through its spec.parentRefs list. Add the replacement Gateway as another parent so that both installations serve the same route during validation.

For example, add kong-migrated to the parent references of an HTTPRoute named example-route:

kubectl patch httproute example-route -n "${NAMESPACE}" --type json \
  -p '[{"op":"add","path":"/spec/parentRefs/-","value":{"kind":"Gateway","name":"kong-migrated"}}]'

For other route types, replace httproute with the route kind, for example grpcroute or tlsroute.

The patch keeps the existing parent references. The route must already have a parentRefs list. Before you apply or retry the patch, check that kong-migrated isn’t already in the list. If the old parent reference uses sectionName or port, add the matching listener restriction to the new reference too.

Repeat the patch for every route attached to the old Gateway that you want to migrate. Before you validate the replacement, check that each route references both Gateways. Keep the old parent references until cleanup.

Validate the replacement

The new data plane doesn’t have an external address, so use a port-forward to reach it.

Find the data plane Service:

INGRESS_SVC=$(kubectl get svc -n "${NAMESPACE}" -l gateway-operator.konghq.com/managed-by=dataplane \
  -o jsonpath='{.items[?(@.spec.ports[0].port==80)].metadata.name}')

Check that INGRESS_SVC contains exactly one Service, and that it belongs to kong-migrated. If you have other Kong Operator-managed data planes, set INGRESS_SVC to the correct Service name.

Start the port-forward:

kubectl port-forward -n "${NAMESPACE}" "svc/$INGRESS_SVC" 18000:80

In another terminal, send requests for every hostname and path your configuration serves, and check that plugin behavior matches. For example:

curl -i -H "Host: example.com" http://127.0.0.1:18000/

Check the response body, status code, and any headers that your plugins add. Compare each response with the same request sent to your existing gateway. Don’t continue until every route matches.

Switch traffic

Before you change the existing Service selector, save it as a rollback patch.

Turn on pipefail so that the save command fails if kubectl fails:

set -o pipefail

Save the selector:

kubectl get svc -n "${NAMESPACE}" "${PROXY_SERVICE}" -o json \
  | jq -e '[{"op":"replace","path":"/spec/selector","value":.spec.selector}]' \
  > rollback-proxy-service.json

Check that the command succeeded and that rollback-proxy-service.json contains the original selector.

Point the Service at the replacement pods:

kubectl patch svc -n ${NAMESPACE} ${PROXY_SERVICE} --type json -p \
  '[{"op":"replace","path":"/spec/selector","value":{"gateway.networking.k8s.io/gateway-name":"kong-migrated"}}]'

Use the JSON replace operation. A merge patch combines the old and new selectors. The gateway-name label keeps the selector tied to the Gateway, even if KO recreates the DataPlane resource.

Check that the Service endpoints point to the replacement pods:

kubectl get endpointslice -n ${NAMESPACE} -l kubernetes.io/service-name=${PROXY_SERVICE} \
  -o jsonpath='{range .items[*].endpoints[*]}{.targetRef.name}{"\n"}{end}'

Repeat your application checks through the original client address. Leave the old pods running so that existing connections can drain. If you use an AWS NLB with IP targets, wait for the new targets to become healthy and for the old targets to drain before cleanup.

Roll back

If validation fails, restore the saved selector:

kubectl patch svc -n "${NAMESPACE}" "${PROXY_SERVICE}" --type json \
  --patch-file rollback-proxy-service.json

Then check traffic through the original address.

Keep the old installation and routing configuration until you accept the cutover. After cleanup starts, restoring the selector might not be enough to roll back.

Retire the old installation

Before you start cleanup, wait until:

  • Application checks pass through the existing address.
  • Old connections have drained.
  • Load balancer target changes have converged.

You can run cleanup later, in a maintenance window. Repeat your application checks after each operation.

Cleanup ends the simple rollback path. Verify traffic after each operation, and wait for routing to settle before you continue. Avoid Kong Operator restarts during cleanup.

  1. Remove the old Gateway parent reference from each migrated route. For example, edit example-route:

    kubectl edit httproute example-route -n "${NAMESPACE}"

    In spec.parentRefs, remove only the entries that reference the old Gateway. Keep kong-migrated and any unrelated parents. Repeat for the remaining routes, and verify application traffic before you continue.

  2. Check that no routes still depend on the old Gateway, including any routes added during migration. Then delete the old Gateway:

    kubectl delete gateway -n "${NAMESPACE}" ${OLD_GATEWAY}

    Verify application traffic before you continue.

  3. If no other Gateways use the old GatewayClass, delete it:

    kubectl delete gatewayclass ${OLD_GATEWAY_CLASS}

    Verify application traffic before you continue.

  4. Uninstall the Helm release:

    helm uninstall -n ${NAMESPACE} ${RELEASE_NAME}

    Helm reports the proxy Service as kept.

The migration is complete. Keep the retained Service in your managed manifests. KO publishes the address of its own internal Service in resource status. If your tooling reads that field, account for the different address.

Troubleshooting

Symptom

Cause

Resolution

The Service has no endpoints after the cutover. The selector was applied with --type merge, which combined the old and new selectors. Apply the selector again with --type json and a replace operation.
A second Gateway that uses the same GatewayClass never becomes programmed, and its ingress Service stays <pending>. The shared GatewayConfiguration pins a specific load balancer address, and you can’t assign one address to two Services. If you pin addresses, give each Gateway its own GatewayConfiguration.
Requests return 404 for a few seconds during cleanup. Several Gateway API objects changed while KO was restarting, so the control plane pushed a configuration that was missing routes. Verify traffic after each step, and increase cache.initSyncDuration.
Patching an HTTPRoute fails with context deadline exceeded when calling gwapi.validations.kong.konghq.com. KO’s validating webhook wasn’t ready yet. Retry the patch.

Optional: Transfer address management

After the migration, you can move the client address from your retained Service to the KO-managed Service. This operation is optional, separate from the migration, and depends on your load balancer platform.

After the migration, the client address lives on a Service that no chart or Kong Operator manages. KO publishes its own ClusterIP in the status of your Ingress and Gateway resources, and not your client address.

If you move the address to the KO-managed Service, KO manages the whole setup. Whether this is worth doing depends on your platform:

Proxy Service type

Recommendation

ClusterIP or NodePort Not applicable. Your clients resolve the Service by name, and the new Service has a different name. Keep the Service you have.
Self-managed load balancer, such as MetalLB Optional. Reassignment is a local operation and completes in less than a second.
AWS Don’t attempt. A load balancer’s lifecycle is bound to the Service that created it, and AWS has no reassignment operation. Deleting the Service deletes the load balancer, and the replacement load balancer has a different hostname. To pin elastic IPs, you must first release them from the old load balancer.
Azure Don’t attempt. You can’t attach a static public IP to two Services at once. The move is a release followed by a reassignment, and reconciliation takes from tens of seconds to minutes.
Other cloud providers Before you try this, check that your provider supports moving the address between Services. If you aren’t sure, keep the Service you have.

If you keep the existing Service, the migration outcome stays the same. Continue to manage its manifest yourself, and account for the different status address in any tooling that reads it.

If your platform supports the move, request the address on the new Service first, and let the request stay pending. Then release the address from the old Service. In this order, the load balancer assigns the address to the new Service as soon as the old Service releases it.

  1. Request the address on the KO-managed Service. Replace the annotation with the equivalent annotation for your load balancer:

    kubectl patch gatewayconfiguration -n "${NAMESPACE}" kong-migrated --type merge -p \
      '{"spec":{"dataPlaneOptions":{"network":{"services":{"ingress":{
         "type":"LoadBalancer",
         "annotations":{"metallb.universe.tf/loadBalancerIPs":"192.0.2.10"}}}}}}}'
  2. Wait until the new Service has the LoadBalancer type and a pending address.

  3. Release the address from the old Service:

    kubectl patch svc -n ${NAMESPACE} ${PROXY_SERVICE} --type json \
      -p '[{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'
  4. Check that the new Service has the address, and verify traffic. Then delete the old Service.

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!