Prepare the mesh for production

Uses: Kong Mesh
TL;DR
  1. Profile the destinations that each workload calls with the DNS query log of its sidecar.
  2. Declare those destinations in the kuma.io/reachable-backends annotation of each workload.
  3. Set restrictOutbound to true on every zone control plane.

Prerequisites

This page is part of the Kong Mesh scenarios: the Kong Air journey series.

Complete the previous page, Validate resilience with fault injection before completing this page.

Every earlier scenario added a capability to the Kong Air mesh, on a control plane that sets restrictOutbound to false. With that setting, every proxy receives the configuration for every destination in the mesh, which costs control plane CPU and xDS bandwidth as the mesh grows. Declare the destinations of each workload before you restrict outbound traffic, so that traffic keeps flowing during the change.

To learn more about what this guide does, read the following reference pages:

Discover what each workload calls

  1. Raise the log level of the DNS proxy in the passenger-portal sidecar. The annotation becomes an environment variable on the sidecar container, so it takes effect when Kubernetes recreates the Pod:

    kubectl patch deployment passenger-portal -n kong-air-production --type merge -p '
    spec:
      template:
        metadata:
          annotations:
            kuma.io/component-log-level: dnsproxy:debug
    '
  2. Wait for the new Pods to roll out:

    kubectl rollout status deployment/passenger-portal -n kong-air-production --timeout=120s
  3. Send a request from passenger-portal to check-in-api, so the DNS proxy logs a lookup:

    kubectl exec -n kong-air-production deploy/passenger-portal -- wget -q -T 5 -O- http://check-in-api.kong-air-production.svc.cluster.local:8080/

    The request fails with 403 Forbidden, because MeshTrafficPermission allows only flight-control to call check-in-api. The DNS proxy logs the lookup before the request reaches check-in-api, so the response isn’t important.

  4. Send a request from passenger-portal to flight-control:

    kubectl exec -n kong-air-production deploy/passenger-portal -- wget -q -T 5 -O- http://flight-control.kong-air-production.svc.cluster.local:8080/

    This request also fails with 403 Forbidden, and the DNS proxy logs the lookup.

  5. Read the distinct names that the workload resolved successfully. The "rcode": "noerror" filter drops the failed lookups that Kubernetes search domains add for each name:

    kubectl logs -n kong-air-production deploy/passenger-portal -c kuma-sidecar \
      | grep '"rcode": "noerror"' | grep -o '"name": "[^"]*"' | cut -d'"' -f4 | sort -u

    The output is the candidate list for passenger-portal:

    check-in-api.kong-air-production.svc.cluster.local.
    flight-control.kong-air-production.svc.cluster.local.
  6. Remove the log level annotation:

    kubectl patch deployment passenger-portal -n kong-air-production --type json \
      -p '[{"op": "remove", "path": "/spec/template/metadata/annotations/kuma.io~1component-log-level"}]'

Declare reachable backends for Kong Air

  1. Declare that flight-control calls check-in-api on port 8080 and the flight-db external service:

    kubectl patch deployment flight-control -n kong-air-production --type merge -p '
    spec:
      template:
        metadata:
          annotations:
            kuma.io/reachable-backends: |
              refs:
              - kind: MeshService
                labels:
                  kuma.io/display-name: check-in-api
                  k8s.kuma.io/namespace: kong-air-production
                port: 8080
              - kind: MeshExternalService
                labels:
                  kuma.io/display-name: flight-db
    '
  2. Declare that check-in-api calls passenger-portal on port 8080:

    kubectl patch deployment check-in-api -n kong-air-production --type merge -p '
    spec:
      template:
        metadata:
          annotations:
            kuma.io/reachable-backends: |
              refs:
              - kind: MeshService
                labels:
                  kuma.io/display-name: passenger-portal
                  k8s.kuma.io/namespace: kong-air-production
                port: 8080
    '
  3. Declare that passenger-portal calls check-in-api on port 8080, baggage-api in zone2 on port 8080, and the aeropay-api external service:

    kubectl patch deployment passenger-portal -n kong-air-production --type merge -p '
    spec:
      template:
        metadata:
          annotations:
            kuma.io/reachable-backends: |
              refs:
              - kind: MeshService
                labels:
                  kuma.io/display-name: check-in-api
                  k8s.kuma.io/namespace: kong-air-production
                port: 8080
              - kind: MeshService
                labels:
                  kuma.io/display-name: baggage-api
                  k8s.kuma.io/namespace: kong-air-production
                  kuma.io/zone: zone2
                port: 8080
              - kind: MeshExternalService
                labels:
                  kuma.io/display-name: aeropay-api
    '
  4. Declare the same destinations for passenger-portal-v2:

    kubectl patch deployment passenger-portal-v2 -n kong-air-production --type merge -p '
    spec:
      template:
        metadata:
          annotations:
            kuma.io/reachable-backends: |
              refs:
              - kind: MeshService
                labels:
                  kuma.io/display-name: check-in-api
                  k8s.kuma.io/namespace: kong-air-production
                port: 8080
              - kind: MeshService
                labels:
                  kuma.io/display-name: baggage-api
                  k8s.kuma.io/namespace: kong-air-production
                  kuma.io/zone: zone2
                port: 8080
              - kind: MeshExternalService
                labels:
                  kuma.io/display-name: aeropay-api
    '
  5. Wait for the new Pods to roll out. The annotation lives on the Pod template, so the control plane reads it when Kubernetes recreates each Pod:

    kubectl rollout status deployment -n kong-air-production --timeout=120s

Turn on restricted outbound

  1. Set KUMA_DEFAULTS_RESTRICT_OUTBOUND to true on the zone1 control plane:

    helm upgrade kong-mesh kong-mesh/kong-mesh \
      --namespace kong-mesh-system --reuse-values \
      --set kuma.controlPlane.envVars.KUMA_DEFAULTS_RESTRICT_OUTBOUND="true"

    The control plane restarts and regenerates every proxy’s configuration. The data plane proxies don’t restart.

  2. Set the same value on the zone2 control plane:

    helm upgrade kong-mesh kong-mesh/kong-mesh --kube-context "$ZONE2_CONTEXT" \
      --namespace kong-mesh-system --reuse-values \
      --set kuma.controlPlane.envVars.KUMA_DEFAULTS_RESTRICT_OUTBOUND="true"
  3. Wait for the new control plane Pods to replace the old ones:

    kubectl rollout status deployment/kong-mesh-control-plane -n kong-mesh-system --timeout=90s
    kubectl --context "$ZONE2_CONTEXT" rollout status deployment/kong-mesh-control-plane -n kong-mesh-system --timeout=90s
  4. Confirm that the zone1 control plane runs with outbound traffic restricted. A control plane with the setting off logs a warning at startup that names KUMA_DEFAULTS_RESTRICT_OUTBOUND:

    kubectl logs -n kong-mesh-system deploy/kong-mesh-control-plane | grep 'KUMA_DEFAULTS_RESTRICT_OUTBOUND is disabled'

    The command prints nothing.

Validate

  1. Check the destinations that each Kong Air proxy declares:

    kubectl get dataplanes.kuma.io -n kong-air-production \
      -o custom-columns='APP:.metadata.labels.app,VERSION:.metadata.labels.version,REACHABLE BACKENDS:.spec.networking.transparentProxying.reachableBackends.refs[*].labels.kuma\.io/display-name'

    Each proxy lists the destinations from its annotation, so each annotation parsed:

    APP                VERSION   REACHABLE BACKENDS
    check-in-api       v1        passenger-portal
    flight-control     v1        check-in-api,flight-db
    passenger-portal   v1        check-in-api,baggage-api,aeropay-api
    passenger-portal   v2        check-in-api,baggage-api,aeropay-api

    A proxy that shows <none> has no declaration, so it reaches no destination in the mesh.

  2. Confirm that passenger-portal still reaches check-in-api, a destination that it declared:

    kubectl exec -n kong-air-production deploy/passenger-portal -- wget -q -T 5 -O- http://check-in-api.kong-air-production.svc.cluster.local:8080/

    The request fails with 403 Forbidden:

    wget: server returned error: HTTP/1.1 403 Forbidden

    The inbound listener of check-in-api returned the 403, so the request reached it. MeshTrafficPermission still allows only flight-control to call check-in-api.

  3. Confirm that passenger-portal still reaches baggage-api in zone2, a destination that it declared and that MeshTrafficPermission allows:

    kubectl exec -n kong-air-production deploy/passenger-portal -- wget -q -T 5 -O- http://baggage-api.kong-air-production.svc.zone2.mesh.local:8080/

    The response is the name of the baggage-api Pod that served the request.

  4. Confirm that passenger-portal can’t reach flight-control, a destination that it didn’t declare:

    kubectl exec -n kong-air-production deploy/passenger-portal -- wget -q -T 5 -O- http://flight-control.kong-air-production.svc.cluster.local:8080/

    The request gets no HTTP response, not even a 403:

    wget: error getting response: Resource temporarily unavailable

    The passenger-portal proxy has no cluster for flight-control, so the request fails at the caller.

  5. Confirm that flight-control still reaches check-in-api, a destination that it declared and that MeshTrafficPermission allows:

    kubectl exec -n kong-air-production deploy/flight-control -- wget -q -T 5 -O- http://check-in-api.kong-air-production.svc.cluster.local:8080/

    The response is the name of the check-in-api Pod that served the request.

Cleanup

Stop the Grafana port-forward that runs in the background since Observe mesh traffic in practice:

kill $GRAFANA_PORT_FORWARD_PID
  1. Delete the zone2 cluster:

    minikube delete -p mesh-zone-2
  2. Delete zone1 cluster:

    minikube delete -p mesh-zone
  3. Delete the kong-air-cp global control plane. This also deletes kong-air-mesh and every resource on the global control plane:

    curl --fail-with-body -sS -X DELETE \
      "https://$KONNECT_REGION.api.konghq.com/v1/mesh/control-planes/$CONTROL_PLANE_ID" \
      -H "Authorization: Bearer $KONNECT_TOKEN"
  4. Delete the mesh-zone1 and mesh-zone2 system accounts that the zones used to connect:

    curl --fail-with-body -sS -X DELETE \
      "https://global.api.konghq.com/v3/system-accounts/$ACCOUNT_ID" \
      -H "Authorization: Bearer $KONNECT_TOKEN"
    curl --fail-with-body -sS -X DELETE \
      "https://global.api.konghq.com/v3/system-accounts/$ZONE2_ACCOUNT_ID" \
      -H "Authorization: Bearer $KONNECT_TOKEN"

Change to the parent directory, and delete the kong-air-scenarios directory and the files that the series created in it:

cd ..
rm -rf kong-air-scenarios

FAQs

reachableBackends lists the destinations that a proxy’s workload calls, and the control plane sends the proxy configuration only for those destinations. Without it, the configuration grows with the number of services multiplied by the number of proxies. That costs control plane CPU and xDS bandwidth, and it slows down how fast a change reaches every proxy.

With restrictOutbound set to true, the Kong Mesh 3.0 default, a proxy without reachableBackends gets no outbound configuration and reaches no destination in the mesh. The setting also closes outbound passthrough on every proxy that no MeshPassthrough policy selects. Don’t run a production mesh with restrictOutbound set to false.

A ref selects backends by kind and labels. kind accepts MeshService, MeshMultiZoneService, and MeshExternalService. The control plane computes kuma.io/display-name from the resource name, and k8s.kuma.io/namespace from its namespace. port is optional and narrows the ref to one port, so set it on a service that exposes more than one port. Every ref needs labels, and the control plane rejects a ref without them. To select every backend of a kind, set labels: {}. A ref that matches no resource adds no destination. For more information, see reachableBackends.

On Universal, you declare outbound destinations on the Dataplane resource. See Differences from Kubernetes.

A resolved name shows that the workload tried to reach a destination, not that a connection happened. The query log records no port, so you decide whether a ref needs one. It also records nothing for a workload that connects to a literal IP address, because that workload makes no DNS query. The profiling window must cover the workload’s normal behavior, including destinations that it calls only on a schedule or during a failure. Each log line carries name, type, rcode, source, answers, and duration.

The DNS proxy in kuma-dp exports metrics that keep tracking lookups after the profiling window ends. kuma_dp_dns_queries_total counts queries by type and source. kuma_dp_dns_response_codes_total counts responses by code. kuma_dp_dns_entries_total reports the size of the proxy’s DNS map. Each metric carries mesh, kuma_io_zone, kuma_workload, and k8s_kuma_io_namespace labels, so you can see which workload sent the queries.

The DNS proxy metrics don’t carry a hostname label, because a hostname label makes their cardinality grow with every name a workload resolves. The metrics show that a workload resolves more names than you expected, and the query log shows which names. Scrape the metrics through MeshMetric, as in Deploy an OpenTelemetry collector.

The source field in the DNS query log reports whether the proxy answered from its own DNS map or forwarded the query to the cluster resolver. The field doesn’t show whether the destination is in the mesh. On Kubernetes, a workload addresses a MeshService through the Kubernetes Service ClusterIP. So the proxy’s map holds few names, and a lookup of a Kubernetes Service name reads source: upstream. A lookup with source: upstream can still point to a destination inside the mesh.

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!