New to kongctl? This document provides an extensive reference to declarative management with kongctl. For a shorter getting started experience, see
the Get started with kongctl guide to quickly learn basic usage and resource management.
kongctl’s declarative management feature enables you to manage Konnect resources using simple YAML configuration files and a stateless CLI tool.
This approach provides version control, automation, and predictable deployments through a plan-based workflow.
Declarative configuration with kongctl means you describe the desired state of your Konnect resources in
static YAML files, and kongctl calculates and executes the changes needed to reach the desired state.
The following are key principles of declarative configuration with kongctl:
Configuration input: Express your desired state in a YAML format that can be split and saved into multiple files and directories for modularity.
Plan-based workflow: Generate plan artifacts that represent the changes needed, review them, and apply them later.
Stateless operation: kongctl queries the live Konnect state instead of maintaining a separate state file.
Namespace ownership: Use namespaces to group resources between teams and environments.
kongctl declarative configuration uses YAML files to describe your desired state. These files define resources and their properties using a simple, structured format.
The following is an example of the basic structure:
Resources in Konnect and kongctl have multiple identifiers:
ref: kongctl specific identifier that’s unique across all resources in a set of input configuration files. Used to identify and reference resources within your configuration.
id: Konnect assigned UUID. Not all Konnect resources support id fields and it isn’t typically stored in declarative configuration files.
name: Konnect resources often have a name field, which is usually unique across an organization, but may not be depending on the resource type.
application_auth_strategies: - ref: oauth-strategy # Identifies resource in configuration only name: "OAuth 2.0 Strategy" # Konnect 'name' field value # 'id' fields are assigned by Konnect but not stored in configuration
A plan is a JSON object that defines the steps needed to move resources from their current state to the desired state and are central to the
kongctl approach to declarative configuration. Planning happens either implicitly or explicitly when using the
declarative configuration commands.
Implicit planning (generate plan and execute immediately):
kongctl apply -f config.yaml
Copied!
Explicit planning (generate plan and pass to a later execution operation):
# Phase 1: Generate plankongctl plan -f config.yaml --output-file plan.json# Phase 2: Review and apply laterkongctl apply --plan plan.json
Copied!
You can use plan artifacts for the following use cases:
Audit trail: Plans provide an audit record of proposed changes independent of the input or current state.
Review process: Share and review plans before execution.
Deferred execution: Generate plans in CI, attach to pull requests, and apply after approval.
Compliance: Document exactly what changes were planned along with the execution logs.
Generate a plan artifact storing a set of proposed changes:
# Generate apply plan (no deletions)kongctl plan -f config.yaml --mode apply# Generate sync plan (includes deletions)kongctl plan -f config.yaml --mode sync --output-file plan.json
# Generate a plan and print summary of prposed changeskongctl diff -f config.yaml# Print a summary of proposed changes from plan artifact inputkongctl diff --plan plan.json
Bring existing Konnect resources under declarative management by adding proper labels:
# Adopt a portal by namekongctl adopt portal my-portal --namespace team-alpha# Adopt a control plane by IDkongctl adopt control-plane <cp-id> --namespace platform# Adopt an APIkongctl adopt api my-api --namespace production
Copied!
Before adopting a resource, add it to your declarative configuration files either manually or with the help of the dump command
so that kongctl will manage the resource going forward.
In the input configuration, you can provide some kongctl specific metadata values that affect the behavior of the
declarative system. You can provide this kongctl section on individual resources or at the configuration file level.
These values are stored on resources via the Konnect resource labels,
so only resources that support labels are supported. In general, only parent resources support labels and child
resources inherit the values from their parents.
The namespace field allows you to define ownership and isolation of resources. You may choose to assign any
namespace you choose, but common patterns would be teams (finance, engineering) or environments (prod, dev).
Child resources automatically inherit the namespace from their parent.
When a resource is marked protected: true, the kongctl declarative planner will not allow planning of
updates or deletes to those resources. To update or delete these resources, change the
resource from protected: true to protected: false. Once you update this, then you are allowed to make subsequent changes.
The following flags allow further control over namespaces when running the declarative commands:
# Require all resources to declare a namespacekongctl plan -f config.yaml --require-any-namespace# Restrict to specific namespaceskongctl plan -f config.yaml --require-namespace=team-a,team-b
Unlike other declarative solutions, kongctl doesn’t maintain any local state storage to complete it’s planning and execution. Instead, it does the following:
You provide the desired state (YAML files).
kongctl queries the current state from Konnect.
kongctl calculates the difference.
kongctl applies the changes.
This means:
No state file to manage or lock
Always reflects the live Konnect state
Can run from anywhere with the same configuration
Multiple people can use the same configuration files
Caution: Be careful with concurrent operations on the same resources. Use namespace isolation to avoid conflicts.
Use !file to load entire file contents. This is useful for resources that have large content stored in files
like OpenAPI specifications or Dev Portal pages and documentation.
The external resources feature allows you to reference Konnect resources
managed outside of kongctl. Some Konnect resources reference others, so this
can be useful for cross-team references, or references to resources created by different management techniques or
technologies.
The following are key characteristics of external resources:
Cannot declare kongctl metadata: External resources don’t support kongctl.namespace or kongctl.protected
Not included in sync planning: External namespaces don’t affect deletion calculations
Used for references: Child resources can reference external parents
The resource requires a ref field, which is how it is further referenced by dependent resources.
The resource is denoted as external by marking it with an _external key. Below the _external key,
you define a selector which will query the organization for resources matching given fields.
The following example shows how you can use external resources to manage an API that is published to a Dev Portal that is owned by the platform team:
# External portal managed by platform teamportals: - ref: platform-portal _external: selector: matchLabels: team: platform# Your API published to the external portalapi_publications: - ref: my-api-pub api: my-api portal_id: !ref platform-portal#id