name: kongctl-declarative description: Set up, initialize, and manage kongctl declarative configuration for Kong Konnect. Use when the user wants to configure a repository with Konnect declarative resources, create kongctl manifests (control planes, portals, APIs), use kongctl scaffold or kongctl explain to discover schemas and bootstrap resource YAML, integrate decK gateway state through _deck, generate Konnect API and Kong Gateway config from OpenAPI specs, run plan/diff/apply/sync/delete/adopt workflows, or scaffold CI/CD pipelines for Konnect APIOps. license: Apache-2.0 metadata: product: kongctl category: declarative
kongctl declarative workflows
Goal
Generate and maintain kongctl declarative configuration in the repository,
and teach users how to manage Konnect resources declaratively.
Choose the execution approach from user intent:
- User-run mode: provide commands and explain what each command does.
- Agent-run mode: execute commands directly and report outcomes.
Preconditions
- Confirm CLI is installed and runnable:
kongctl version - For Kong Gateway configuration, confirm decK is installed:
deck version - Local schema helpers do not require Konnect authentication:
kongctl explain <resource-path>inspects resource and field schemas.kongctl scaffold <resource-path>prints commented starter YAML.
- Authenticate with one of:
kongctl login— preferred for interactive use (browser-based OAuth)export KONGCTL_DEFAULT_KONNECT_PAT=<token>— for non-interactive or CI
- PAT tokens are sensitive credentials. Never echo, log, or commit them.
Prefer
kongctl loginfor interactive sessions. - Verify authentication works:
kongctl get organization -o jsonThis works with all token types (PAT, SPAT, browser login). If it returns organization info, auth is confirmed. Do not guess or try other commands to check auth. - Verify command syntax when unsure:
kongctl explain --helpkongctl scaffold --helpkongctl plan --helpkongctl dump declarative --helpkongctl adopt --help
Config and Environment Overrides
kongctlflags can be defaulted via profile config or environment.- Environment variable pattern:
KONGCTL_<PROFILE>_<PATH>. - Example:
KONGCTL_DEFAULT_OUTPUT=yamlchanges default output format. - Pass explicit
-o yaml,-o json, or-o texton command lines to avoid unexpected output behavior.
Skill References
Load only the reference file needed for the active task:
references/commands.md- Use for schema helpers, command selection, plan based vs inline execution, and safety flags.
references/resources.md- Use for schema-first authoring, resource skeletons,
_defaults,!file, and!refpatterns.
- Use for schema-first authoring, resource skeletons,
references/troubleshooting.md- Use for common failures and fast remediation steps.
references/cicd-github-actions.md- Use for GitHub Actions workflow patterns for declarative CI/CD.
references/apiops-openapi.md- Use for OpenAPI source-of-truth patterns for APIs and API versions.
references/deck-gateway.md- Use when configuring Kong Gateway services, routes, plugins, consumers,
or OpenAPI-to-Gateway APIOps with decK and
_deck.
- Use when configuring Kong Gateway services, routes, plugins, consumers,
or OpenAPI-to-Gateway APIOps with decK and
This skill is designed to be portable across repositories. Do not assume a
local docs/ directory exists.
Before hand-writing unfamiliar resources or fields, discover structure with:
kongctl explain <resource-path> -o text --extended
kongctl scaffold <resource-path>
Use kongctl dump declarative --resources=<resource-type> when live Konnect
state is the best source of truth, such as when adopting existing resources.
Operating Rules
- Declarative execution is always plan-based in kongctl:
- Explicit path:
plan->diff --plan->apply/sync --plan - Inline path:
apply -f,sync -f, ordelete -f(plan+execute happens in single shot)
- Explicit path:
- Prefer instructional guidance when the user asks how to do a task: provide a concise command sequence and decision notes.
- Execute commands directly when the user asks the agent to run them.
- Before any mutating run, state the intended effect in plain language.
- Choose path from user intent:
- Preview/review/audit/CI request: use explicit plan artifacts.
- "Do it now" execution request: use inline commands.
- Treat
syncas destructive because it can delete missing resources. - Treat
deleteas destructive because it deletes input configuration resources. - Use
applyfor create/update workflows when the user asks to execute. - Use
-o textfor interactive mutating commands.-o jsonand-o yamlrequire--auto-approveor--dry-runonapply,sync, anddelete. - Use
kongctl explainbefore guessing at resource, child-resource, or field structure. Use--extendedfor field summaries in text output, or-o json/-o yamlfor machine-readable schema. - Use
kongctl scaffoldto bootstrap YAML for new resource types and child resources. It writes YAML to stdout and does not support-o/--output. - For programmatic YAML generation, prefer
kongctl explain <path> -o jsonas the source of truth. It returns JSON Schema with kongctl metadata. - For resources with JSON Schema
oneOf, choose exactly one branch. Use discriminatorconstfields such astypeorstrategy_typeto select the branch, and do not merge branch-specificconfigorconfigsblocks. - In scaffold output,
# oneOf option: ...marks mutually exclusive alternatives. One branch is active and the other branches are commented. - Use resource and field paths such as
api,api.versions,api.publications.portal_id, andportal.pageswithexplain. - Use resource and child-resource paths such as
api,api.versions, andcontrol_plane.data_plane_certificateswithscaffold. - Use
adoptonly to bring unmanaged resources into namespace management. adoptonly adds theKONGCTL-namespacelabel to the target resource.- Prefer
!reffor cross-resource IDs and!filefor large spec or doc content. - For
apisandapis.versions, treat OpenAPI files as source of truth: derive fields from!fileextraction and avoid stale duplicated literals. - Use existing OpenAPI file paths from the user repository. Do not require a
konnect/resources/specslayout. - Use decK for Kong Gateway runtime entities such as services, routes, plugins, consumers, consumer groups, upstreams, and targets.
- Use kongctl resources for Konnect SaaS resources such as control planes, portals, API catalog entries, publications, and API implementations.
- When a user wants an API Gateway configured from OpenAPI, generate decK
state with
deck file openapi2kong, then wire it to kongctl throughcontrol_planes[]._deck. - Use
control_planes[].gateway_servicesas external selectors for services created by decK, then reference them fromapis[].implementations. - Only place kongctl declarative resource files in the resources directory.
Do not put OpenAPI specs, documentation, or other non-resource YAML there.
--recursiveloads all YAML files in the directory tree and will fail on files that are not valid kongctl declarative resources. - When non-resource YAML files coexist in a directory, use multiple
-fflags pointing to individual resource files instead of--recursive:kongctl diff -f resources/apis.yaml -f resources/portals.yaml --mode apply !filepaths resolve relative to the YAML file they appear in, not the project root. Calculate the relative path from the config file to the target file (e.g.../../openapi.yamlfromkonnect/resources/apis.yaml).--base-dirsets the allowed boundary for!fileresolution but does not change the resolution base. Keep!filetargets within the boundary.- Put
kongctlmetadata only on parent resources. - Use
_defaults.kongctl.namespacefor consistent file-level ownership. - Do not require
docs/declarative*.mdto complete tasks.
Workflow
- Locate the Konnect declarative configuration directory and existing files.
- For unfamiliar resource shapes, run
kongctl explainorkongctl scaffoldbefore writing YAML. - Generate or update YAML manifests and related files.
- Choose collaboration mode based on intent:
- User-run mode (teach + provide commands)
- Agent-run mode (execute commands directly)
- Load the relevant
references/*.mdfile for the task. - If execution is needed, pick execution style:
- Explicit plan artifact workflow (generate plan, then pass it to apply or sync)
- Inline command workflow
- Validate and/or execute
diff,apply,sync,delete, oradoptper user ask. - Report created files, commands run, and resulting plan or execution summary.
Execution Style Selection
Use this quick decision rule:
- Use explicit plan artifacts when the user asks to preview, review, export a plan file, or run a CI/CD style workflow.
- Use inline commands when the user asks to execute immediately and does not ask for a saved plan file.
- For destructive requests (
sync,delete), prefer--dry-runfirst unless the user explicitly requests direct execution.
Collaboration Mode Selection
Use this quick decision rule:
- Use User-run mode when the user asks "how do I do this" or asks for commands.
- Use Agent-run mode when the user asks to set up, create, or apply.
- If intent is ambiguous, provide a safe preview command first and state that you can execute the mutating command on request.
- Do not ask clarifying questions when sensible defaults can be inferred from context (e.g. derive namespace from project name, include standard resources like control plane + portal + API). Proceed with defaults and let the user adjust afterward.
Konnect Configuration Directory Discovery
Prefer a user-provided path. If none is provided, discover likely roots:
rg -n --glob '*.y*ml' '^(_defaults|apis|portals|control_planes):' .
rg -n --glob '*.y*ml' \
'^(application_auth_strategies|event_gateways|organization):' .
If creating new structure, prefer:
konnect/resources/
control-planes.yaml
portals.yaml
apis.yaml
For APIOps API modeling, load references/apiops-openapi.md.
For Kong Gateway/deck integration, load references/deck-gateway.md.
Pattern: Bootstrap control plane, portal, and APIs
Use for prompts like:
- Generate declarative configs for a new control plane, portal, and API set.
Steps:
- Create or update resource files under the selected resources path.
- Add
_defaults.kongctl.namespaceand stablerefvalues. - Use
!filetags to load OpenAPI metadata and version content. - Link API publications to portal using
!ref <portal-ref>#id. - Validate and execute based on requested style.
- In User-run mode, explain each command's purpose before listing it.
Starter manifest pattern:
When starting from scratch, prefer generating starter shapes first:
kongctl scaffold control_plane
kongctl scaffold portal
kongctl scaffold api
Then adapt the generated YAML to the repository layout and user intent. The static pattern below is a compact fallback and example of the expected result.
_defaults:
kongctl:
namespace: platform-dev
protected: false
control_planes:
- ref: cp-main
name: "my-control-plane"
cluster_type: "CLUSTER_TYPE_CONTROL_PLANE"
portals:
- ref: dev-portal
name: "my-dev-portal"
display_name: "My Dev Portal"
default_api_visibility: "private"
default_page_visibility: "private"
apis:
- ref: payments-api
name: !file <existing-openapi-path>#info.title
description: !file <existing-openapi-path>#info.description
versions:
- ref: payments-v1
version: !file <existing-openapi-path>#info.version
spec: !file <existing-openapi-path>
publications:
- ref: payments-publication
portal_id: !ref dev-portal#id
visibility: public
When OpenAPI !file paths point outside the resources directory, set
--base-dir to the absolute project root so paths resolve correctly.
Relative --base-dir values resolve from the config file directory, not
cwd, so always use an absolute path:
kongctl diff -f konnect/resources --recursive \
--base-dir "$(pwd)" --mode apply -o text
Use --recursive when the -f target is a directory.
Use references/commands.md for validation and execution command patterns.
Pattern: Generate API config from an OpenAPI spec
Use for prompts like:
- Generate an API declarative config from
@path-to/openapi-spec.yamland write it to@path-to-existing/konnect/resources. - Generate gateway services, routes, and plugins from an OpenAPI spec and connect them to a Konnect API implementation.
Steps:
- Choose target files under the existing resources tree, such as:
<resources>/apis/<api-name>.yaml
- If no local API manifest convention exists, run
kongctl scaffold apiand adapt the generated shape. - If the user wants Gateway runtime config, load
references/deck-gateway.mdand create or update a decK state file. - Reference existing OpenAPI spec paths in the repository. Do not require copying specs under the declarative resources directory.
- Preserve existing repo conventions when a layout already exists.
- Reference spec fields with
!fileextraction. - If spec files are outside the resources directory, add
--base-dirto allplan/diff/apply/synccommands so!filepaths resolve. - Validate and execute based on requested style.
- In User-run mode, include where files were written and why.
Load references/apiops-openapi.md for the canonical API YAML template and
references/commands.md for validation and execution commands.
Load references/deck-gateway.md when the OpenAPI spec should also produce
Gateway services, routes, plugins, or an API implementation backed by decK.
Pattern: Adopt existing resources into declarative management
Use for prompts like:
- Adopt portal
My Dev Portaland start managing it declaratively. - I have resources in Konnect that I created in the UI. How do I bring them under kongctl?
- Dump my existing control plane into declarative config.
This pattern applies to any parent resource type (portal, api, control_plane, etc.), not just portals.
Background
Resources created outside kongctl (e.g. via the Konnect UI) do not have a
KONGCTL-namespace label. The declarative engine uses this label to track
which resources it manages and which namespace they belong to. To bring an
existing resource under declarative management:
- Adopt adds the
KONGCTL-namespacelabel to the live resource. - Dump exports the live resource state as declarative YAML.
- Integrate the dumped config into the repository's declarative files.
- Verify with
diffto confirm zero drift.
Adopt must come before dump so the resource is labeled as managed before generating config.
Steps
- Identify the target resource name (or ID) and choose a namespace.
- Adopt the resource into the namespace:
This only adds thekongctl adopt <resource-type> <name-or-id> \ --namespace <namespace> -o jsonKONGCTL-namespacelabel — it does not modify the resource configuration. - Dump the resource to declarative YAML:
kongctl dump declarative \ --resources=<type> \ --filter-name "<name>" \ --include-child-resources \ --default-namespace <namespace> \ -o yaml \ --output-file <output-path> - Integrate the dumped output into existing declarative files:
- Replace the UUID-based
refvalues with human-friendly names. - Replace hard-coded UUIDs with
!refwhere the referenced resource is also managed declaratively (e.g.portal_id: !ref dev-portal#id). - Merge into existing resource files or create new ones following the repository layout conventions.
- Ensure
_defaults.kongctl.namespacematches the adopt namespace.
- Replace the UUID-based
- Verify zero drift:
A clean diff confirms the dumped config matches live state.kongctl diff -f <resources-path> --mode apply -o text - In User-run mode, explain that
adoptonly labels — it does not change any resource fields.
Dump output behavior
dumpsetsrefto the resource UUID. Replace with meaningful names.dumpfilters outKONGCTL-namespacelabels from output by design.--default-namespaceadds a_defaults.kongctlblock to the output.--include-child-resourcesincludes nested resources (pages, snippets, versions, etc.).- Use
--filter-nameor--filter-idto scope to a specific resource.
If names are ambiguous, use --filter-id for both adopt and dump.
Pattern: Build GitHub Actions workflow for declarative CI/CD
Use for prompts like:
- Create a GitHub Actions workflow that validates and syncs Konnect declarative resources.
- Add CI/CD automation that installs
kongctlanddeckand runs the repository sync script.
Steps:
- Decide trigger model from user intent:
- Pull request validation: run plan/diff only (no mutations).
- Branch deploy workflow: run apply/sync or a repo wrapper script.
- Use standard setup actions:
actions/checkout@v4kong/setup-kongctl@v1kong/setup-deck@v1(when deck is required)
- Configure authentication using repository secrets and workflow env.
- Restrict execution with path filters, for example
konnect/**. - Upload execution artifacts with
if: always()for debugging and audits. - In User-run mode, explain required secrets and expected script behavior.
Load references/cicd-github-actions.md for starter workflow templates,
trigger patterns, auth conventions, and validation workflow examples.
Safety and Troubleshooting
- Use
--dry-runforapply,sync, anddeletebefore executing changes. - If
!filefails with boundary errors, set--base-dirto include spec paths rather than moving files. - If
planincludes unexpected deletes, use--mode applyor tighten scope with--require-namespace. - Load
references/troubleshooting.mdfor detailed remediation steps.
Online Documentation
If this skill's references are not sufficient, consult or direct users to:
- kongctl docs: https://developer.konghq.com/kongctl/
- Declarative guide: https://github.com/Kong/kongctl/blob/main/docs/declarative.md
- Resource reference: https://github.com/Kong/kongctl/blob/main/docs/declarative-resource-reference.md