This guide uses Terraform to create a Kong Mesh 3.x global control plane in Konnect, connect a Kubernetes zone to it, and create a mesh with a traffic permission. It then deploys two test applications and verifies identity-based traffic permissions.
Use the konnect-beta provider with version = “v3” to create the global control plane, the mesh, and its MeshIdentity. Use the konnect provider for the zone’s system account, the helm and kubernetes providers to install the zone, and a kubernetes_manifest to apply the traffic permission to the zone.
Prerequisites
Kong Konnect
If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.
- The following Konnect items are required to complete this tutorial:
- Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Set the personal access token as an environment variable:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
kongctl v1.29.0+
This tutorial uses kongctl to manage Konnect resources programmatically. We recommend keeping kongctl up to date with the latest version (1.29.0).
- Install kongctl from developer.konghq.com/kongctl.
-
Verify the installation:
kongctl version
Terraform
This how-to requires you to install Terraform.
Configure Terraform
-
Create a working directory and change to it:
export MESH_TERRAFORM_DIR="$PWD/mesh-terraform" mkdir -p "$MESH_TERRAFORM_DIR" cd "$MESH_TERRAFORM_DIR" -
Set the region and pass your Konnect credentials to Terraform:
export KONNECT_REGION='us' export TF_VAR_konnect_token="$KONNECT_TOKEN" export TF_VAR_region="$KONNECT_REGION" -
Create
providers.tf, which declares the variables and configures every provider this guide uses:cat <<'EOF' > providers.tf terraform { required_providers { konnect-beta = { source = "kong/konnect-beta" version = "0.22.0" } konnect = { source = "kong/konnect" version = "3.26.0" } kubernetes = { source = "hashicorp/kubernetes" version = "3.2.1" } helm = { source = "hashicorp/helm" version = "3.1.2" } } } variable "konnect_token" { type = string sensitive = true } variable "region" { type = string } provider "konnect-beta" { personal_access_token = var.konnect_token server_url = "https://${var.region}.api.konghq.com" } provider "konnect" { personal_access_token = var.konnect_token server_url = "https://${var.region}.api.konghq.com" } provider "kubernetes" { config_path = pathexpand("~/.kube/config") } provider "helm" { kubernetes = { config_path = pathexpand("~/.kube/config") } } EOFMesh resources are only available in the
konnect-betaprovider. Thekonnectprovider manages the zone’s system account. -
Initialize the working directory:
terraform init
Protect Terraform state and don’t commit credentials: the state holds the zone token. Keep this directory for later cleanup.
Create the global control plane
-
Create
control-plane.tf:cat <<'EOF' > control-plane.tf resource "konnect_mesh_control_plane" "demo" { provider = konnect-beta name = "example-cp" description = "Mesh 3 installation example" version = "v3" } output "control_plane_id" { value = konnect_mesh_control_plane.demo.id } EOFThe provider’s control plane resource defaults to
v2, so setversion = "v3"explicitly. -
Review the plan:
terraform plan -
Apply the plan:
terraform apply -
Export the control plane ID from the Terraform output:
export CONTROL_PLANE_ID=$(terraform output -raw control_plane_id)
Give the zone credentials to connect
The zone uses a system account access token with the Connector role on this control plane.
-
Set the token to expire in 30 days. Change the number of days if your organization’s token policy requires a shorter lifetime:
export TF_VAR_zone_token_expires_at=$(jq -nr 'now + 30*24*60*60 | todate') -
Create
zone-credentials.tf:cat <<'EOF' > zone-credentials.tf variable "zone_token_expires_at" { type = string } resource "konnect_system_account" "zone" { name = "mesh-zone-1" description = "Connect zone-1" konnect_managed = false } resource "konnect_system_account_role" "zone_connector" { account_id = konnect_system_account.zone.id role_name = "Connector" entity_type_name = "Mesh Control Planes" entity_id = konnect_mesh_control_plane.demo.id entity_region = var.region } resource "konnect_system_account_access_token" "zone" { account_id = konnect_system_account.zone.id name = "zone-1" expires_at = var.zone_token_expires_at } EOF -
Apply the configuration:
terraform apply
Deploy the zone control plane
-
Create
zone.tf, which stores the zone token in a Secret and installs the zone control plane with Helm:cat <<'EOF' > zone.tf resource "kubernetes_namespace_v1" "kong_mesh_system" { metadata { name = "kong-mesh-system" } } resource "kubernetes_secret_v1" "cp_token" { metadata { name = "cp-token" namespace = kubernetes_namespace_v1.kong_mesh_system.metadata[0].name } data = { token = konnect_system_account_access_token.zone.token } } resource "helm_release" "kong_mesh" { name = "kong-mesh" repository = "https://kong.github.io/kong-mesh-charts" chart = "kong-mesh" version = "3.0.0" namespace = kubernetes_namespace_v1.kong_mesh_system.metadata[0].name timeout = 300 values = [yamlencode({ kuma = { controlPlane = { mode = "zone" zone = "zone-1" kdsGlobalAddress = "grpcs://${var.region}.mesh.sync.konghq.com:443" konnect = { cpId = konnect_mesh_control_plane.demo.id } zoneToken = { secretName = kubernetes_secret_v1.cp_token.metadata[0].name key = "token" } } } })] } EOFThe zone reads its token from the
cp-tokenSecret throughzoneToken. This single-zone test doesn’t need zone proxies; add mesh-scoped zone proxies when connecting zones or usingMeshExternalService. -
Apply the configuration. The
helm_releasewaits for the zone control plane to be ready, which can take a few minutes:terraform apply
Verify the zone connection
Confirm the zone is connected to your global control plane:
kongctl inspect mesh zones \
--control-plane-id "$CONTROL_PLANE_ID" --region "$KONNECT_REGION" \
--pat "$KONNECT_TOKEN"The zone should report an Online status:
NAME STATUS
zone-1 OnlineIf a zone is missing or not Online, check:
- The zone’s control plane logs
- Outbound access to the KDS address
- The control plane ID
- The system account’s
Connectorrole and token
Create a mesh and secure the test traffic
-
Create
mesh.tf, which creates thekonnect-demomesh and a demo identity provider on the global control plane:cat <<'EOF' > mesh.tf resource "konnect_mesh" "demo" { provider = konnect-beta cp_id = konnect_mesh_control_plane.demo.id name = "konnect-demo" type = "Mesh" } resource "konnect_mesh_identity" "demo" { provider = konnect-beta cp_id = konnect_mesh_control_plane.demo.id mesh = konnect_mesh.demo.name name = "demo-identity" type = "MeshIdentity" spec = { selector = { dataplane = {} } spiffe_id = { trust_domain = "konnect-demo.mesh.local" } provider = { type = "Bundled" bundled = { autogenerate = { enabled = true } insecure_allow_self_signed = true mesh_trust_creation = "Enabled" } } } } EOFMeshIdentityissues certificates and publishes their CA inMeshTrust. This example accepts a generated self-signed CA for the demo; review your production PKI requirements before reusing it. -
Apply the configuration:
terraform apply -
Wait for the identity to be ready and for the trust to be generated:
kongctl get mesh meshidentities demo-identity --mesh konnect-demo -o yaml \ --control-plane-id "$CONTROL_PLANE_ID" --region "$KONNECT_REGION" \ --pat "$KONNECT_TOKEN" kongctl get mesh meshtrusts --mesh konnect-demo \ --control-plane-id "$CONTROL_PLANE_ID" --region "$KONNECT_REGION" \ --pat "$KONNECT_TOKEN" -
Confirm that the new mesh has synced to the Kubernetes zone:
kubectl get mesh konnect-demo -
Create
traffic-permission.tf, which applies aMeshTrafficPermissionto the zone to allow theclientServiceAccount to call theserverworkload:cat <<'EOF' > traffic-permission.tf resource "kubernetes_manifest" "client_to_server" { manifest = { apiVersion = "kuma.io/v1alpha1" kind = "MeshTrafficPermission" metadata = { name = "client-to-server" namespace = kubernetes_namespace_v1.kong_mesh_system.metadata[0].name labels = { "kuma.io/mesh" = konnect_mesh.demo.name "kuma.io/origin" = "zone" } } spec = { targetRef = { kind = "Dataplane" labels = { app = "server" } } rules = [ { default = { allow = [ { spiffeID = { type = "Exact" value = "spiffe://konnect-demo.mesh.local/ns/kong-mesh-demo/sa/client" } } ] } } ] } } depends_on = [helm_release.kong_mesh] } EOFkubernetes_manifestreads theMeshTrafficPermissionCRD from the cluster when Terraform plans, so it can only be applied once the zone control plane from Deploy the zone control plane has installed the CRDs. -
Apply the configuration:
terraform apply
Deploy the test applications
Deploy an nginx server and a curl client into a namespace that joins the mesh. The client’s
own ServiceAccount gives it the identity that the traffic permission allows. The client also lists
server as a reachable backend, because a proxy can only call the destinations it declares. For
more information, see MeshService.
-
Create the namespace, the client ServiceAccount, and the server and client workloads:
cat <<'EOF' | kubectl apply -f - apiVersion: v1 kind: Namespace metadata: name: kong-mesh-demo labels: kuma.io/mesh: konnect-demo kuma.io/sidecar-injection: enabled --- apiVersion: v1 kind: ServiceAccount metadata: name: client namespace: kong-mesh-demo --- apiVersion: v1 kind: Service metadata: name: server namespace: kong-mesh-demo spec: selector: app: server ports: - port: 80 targetPort: 80 appProtocol: http --- apiVersion: apps/v1 kind: Deployment metadata: name: server namespace: kong-mesh-demo spec: replicas: 1 selector: matchLabels: app: server template: metadata: labels: app: server spec: containers: - name: server image: nginx:1.27.4 ports: - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: client namespace: kong-mesh-demo spec: replicas: 1 selector: matchLabels: app: client template: metadata: labels: app: client annotations: kuma.io/reachable-backends: | refs: - kind: MeshService labels: kuma.io/display-name: server k8s.kuma.io/namespace: kong-mesh-demo spec: serviceAccountName: client containers: - name: client image: curlimages/curl:8.12.1 command: ["sleep", "86400"] EOF -
Wait for the server and client to roll out:
kubectl -n kong-mesh-demo rollout status deployment/server --timeout=180s kubectl -n kong-mesh-demo rollout status deployment/client --timeout=180s
Validate
-
Check that both workloads have ready mesh sidecars:
kubectl -n kong-mesh-demo get pods -
Check that
serverhas a generatedMeshService:kongctl get mesh meshservices --mesh konnect-demo \ --control-plane-id "$CONTROL_PLANE_ID" --region "$KONNECT_REGION" \ --pat "$KONNECT_TOKEN" -
Confirm the workload identities in the proxy inspection output:
kongctl inspect mesh dataplanes --mesh konnect-demo \ --control-plane-id "$CONTROL_PLANE_ID" --region "$KONNECT_REGION" \ --pat "$KONNECT_TOKEN" -
Send a request from the client to the server:
kubectl -n kong-mesh-demo exec deployment/client -c client -- \ curl --fail --max-time 10 http://server.kong-mesh-demo.svc.cluster.local/You should get the nginx welcome page.
-
For a negative check, change the client’s ServiceAccount to
defaultand wait for the replacement Pod:kubectl -n kong-mesh-demo patch deployment client --type=merge \ -p '{"spec":{"template":{"spec":{"serviceAccountName":"default"}}}}' kubectl -n kong-mesh-demo rollout status deployment/client --timeout=180s -
Repeat the same request:
kubectl -n kong-mesh-demo exec deployment/client -c client -- \ curl --fail --max-time 10 http://server.kong-mesh-demo.svc.cluster.local/The request fails, because the permission doesn’t allow the
/sa/defaultidentity. -
Restore the allowed identity and wait for the replacement Pod:
kubectl -n kong-mesh-demo patch deployment client --type=merge \ -p '{"spec":{"template":{"spec":{"serviceAccountName":"client"}}}}' kubectl -n kong-mesh-demo rollout status deployment/client --timeout=180s -
Confirm the request succeeds again:
kubectl -n kong-mesh-demo exec deployment/client -c client -- \ curl --fail --max-time 10 http://server.kong-mesh-demo.svc.cluster.local/
If the results differ, see the MeshTrafficPermission reference.
Cleanup
Delete the test applications
Delete the test namespace:
kubectl delete namespace kong-mesh-demoDestroy the Terraform resources
Review the destroy plan:
terraform plan -destroyDestroy every resource this guide created with Terraform: the traffic permission, the zone control plane and its namespace, the mesh and its identity, the global control plane, and the zone’s system account:
terraform destroyLeave the Terraform working directory and delete it:
cd "$(dirname "$MESH_TERRAFORM_DIR")"
rm -rf "$MESH_TERRAFORM_DIR"