Skip to content
Kong Logo | Kong Docs Logo
search
  • Docs
    • Explore the API Specs
      View all API Specs View all API Specs View all API Specs arrow image
    • Documentation
      API Specs
      Kong Gateway
      Lightweight, fast, and flexible cloud-native API gateway
      Kong Konnect
      Single platform for SaaS end-to-end connectivity
      Kong Mesh
      Enterprise service mesh based on Kuma and Envoy
      decK
      Helps manage Kong’s configuration in a declarative fashion
      Kong Ingress Controller
      Works inside a Kubernetes cluster and configures Kong to proxy traffic
      Kong Gateway Operator
      Manage your Kong deployments on Kubernetes using YAML Manifests
      Insomnia
      Collaborative API development platform
      Kuma
      Open-source distributed control plane with a bundled Envoy Proxy integration
  • Plugin Hub
    • Explore the Plugin Hub
      View all plugins View all plugins View all plugins arrow image
    • Functionality View all View all arrow image
      View all plugins
      Authentication's icon
      Authentication
      Protect your services with an authentication layer
      Security's icon
      Security
      Protect your services with additional security layer
      Traffic Control's icon
      Traffic Control
      Manage, throttle and restrict inbound and outbound API traffic
      Serverless's icon
      Serverless
      Invoke serverless functions in combination with other plugins
      Analytics & Monitoring's icon
      Analytics & Monitoring
      Visualize, inspect and monitor APIs and microservices traffic
      Transformations's icon
      Transformations
      Transform request and responses on the fly on Kong
      Logging's icon
      Logging
      Log request and response data using the best transport for your infrastructure
  • Support
  • Community
  • Kong Academy
Get a Demo Start Free Trial
decK
1.27.x
  • Home icon
  • decK
  • Guides
  • Apiops
  • APIOps with decK
github-edit-pageEdit this page
report-issueReport an issue
  • Kong Gateway
  • Kong Konnect
  • Kong Mesh
  • Plugin Hub
  • decK
  • Kong Ingress Controller
  • Kong Gateway Operator
  • Insomnia
  • Kuma

  • Docs contribution guidelines
  • 1.29.x (latest)
  • 1.28.x
  • 1.27.x
  • 1.26.x
  • 1.25.x
  • 1.24.x
  • 1.23.x
  • 1.22.x
  • 1.21.x
  • 1.20.x
  • 1.19.x
  • 1.18.x
  • 1.17.x
  • 1.16.x
  • 1.15.x
  • 1.14.x
  • 1.13.x
  • 1.12.x
  • 1.11.x
  • 1.10.x
  • 1.9.x
  • 1.8.x
  • 1.7.x
  • pre-1.7
enterprise-switcher-icon Switch to OSS
On this pageOn this page
  • Configuration generation
  • Configuration transformations
  • More information
You are browsing documentation for an outdated version. See the latest documentation here.

APIOps with decK

API Lifecycle Automation (APIOps) is the process of applying automation frameworks to API best practices. decK enables APIOps by providing a tool with varied commands that can be coordinated to build API delivery automations.

decK commands break down into the following categories:

  • Configuration generation
  • Configuration transformation
  • Gateway state management

This guide walks you through using the configuration generation and transformation commands to build an API automation delivery pipeline.

Configuration generation

OpenAPI is the most commonly used standard for defining API behavior. OpenAPI Specifications (OAS) are useful for many API development related tasks including generating documentation and API client code. With decK, you can also generate Kong Gateway configuration from OAS files.

Let’s assume you have the following minimal OAS in a file named oas.yaml:

openapi: 3.0.0
info:
  title: httpbin API
  description: Simple API for testing purposes
  version: 1.0.0
servers:
  - url: http://httpbin.org
paths:
  /request:
    get:
      summary: Get a simple response from the /request resource of the httpbin API
      responses:
        '200':
          description: Successful response

You can generate a Kong Gateway configuration with the following:

deck file openapi2kong \
  --spec oas.yaml \
  --output-file httpbin.yaml

Which produces a complete decK configuration file:

_format_version: "3.0"
services:
- host: httpbin.org
  id: de7107e7-a39c-5574-9e8c-e66787ae50e7
  name: httpbin-api
  path: /
  plugins: []
  port: 80
  protocol: http
  routes:
  - id: 803b324e-98ed-5ec5-aecf-b4ce973036f4
    methods:
    - GET
    name: httpbin-api_request_get
    paths:
    - ~/request$
    plugins: []
    regex_priority: 200
    strip_path: false
    tags: []
  tags: []
upstreams: []

Note: The Kong Gateway getting started guide can help you quickly run a gateway in Docker to follow along with these instructions.

You can synchronize this directly to the gateway using deck sync:

deck sync -s httpbin.yaml

Which creates the service and route:

creating service httpbin-api
creating route httpbin-api_request_get
Summary:
  Created: 2
  Updated: 0
  Deleted: 0

This is a very simple example. In reality, you will generally want to configure more sophisticated Kong Gateway capabilities for your API. Maybe you want to secure your API with an authentication plugin, or protect it with traffic management. These API Gateway concepts are usually orthogonal to the OAS, and a clearer separation of concerns is achieved if they are configured independently of the specification.

This can be accomplished with decK file transformations.

Configuration transformations

If you are building microservices or an API platform for multiple teams, you likely have multiple services and code repositories with their own decK configuration files. Using decK file transformation commands, you can organize your decK configuration files into partial segments of the full configuration and assemble them prior to synchronizing with Kong Gateway. This allows you to organize different aspects of the configuration in alignment with the rest of your software development artifacts.

Continuing the example above, let’s take a look at how commands can be pipelined to create API lifecycle automations.

Let’s assume you have a second team that builds a different API, and provides a Kong Gateway decK configuration segment for their service and route. Copy the following configuration into a file named another-httpbin.yaml:

_format_version: "3.0"
services:
- host: httpbin.org
  id: 7cc31086-3837-4e7e-bbe9-271e51c1f614 
  name: another-httpbin-api
  path: /
  plugins: []
  port: 80
  protocol: http
  routes:
  - id: 08ac3482-843a-40f8-a277-a4e73baf19d9 
    methods:
    - GET
    name: another-httpbin-api_request_get
    paths:
    - ~/another-request$
    plugins: []
    regex_priority: 200
    strip_path: false
    tags: []
  tags: []
upstreams: []

You can use the decK file merge command to bring these two configurations into one:

deck file merge httpbin.yaml another-httpbin.yaml \
  --output-file merged-kong.yaml

You now have a file named merged-kong.yaml, which is a single decK file with both services and routes merged. This file is also a complete deck file and could be synchronized to a gateway. Before doing that, let’s take the example one step further.

Now assume you want to ensure that all services in your configuration communicate with the upstream endpoint via https only. You can use the deck file patch command to accomplish this:

deck file patch --state merged-kong.yaml \
  --selector "$.services[*]" \
  --value 'protocol: "https"' \
  --output-file kong.yaml

The final kong.yaml file is a full configuration you can synchronize to the gateway:

deck sync -s kong.yaml

Here is an example of putting the above together in a Unix-style pipeline:

deck file openapi2kong --spec oas.yaml --output-file httpbin.yaml && 
  deck file merge httpbin.yaml another-httpbin.yaml | 
  deck file patch --selector "$.services[*]" --value 'protocol: "https"' |
  deck sync -s -

Most commonly, you will use the commands from CI/CD tools built into your version control system to bring full and partial Kong Gateway configurations together to create APIOps for your particular needs.

More information

See the example file at Kong/go-apiops for extensive annotations explaining the conversion process, as well as all supported custom annotations (x-kong-... directives).

Thank you for your feedback.
Was this page useful?
Too much on your plate? close cta icon
More features, less infrastructure with Kong Konnect. 1M requests per month for free.
Try it for Free
  • Kong
    Powering the API world

    Increase developer productivity, security, and performance at scale with the unified platform for API management, service mesh, and ingress controller.

    • Products
      • Kong Konnect
      • Kong Gateway Enterprise
      • Kong Gateway
      • Kong Mesh
      • Kong Ingress Controller
      • Kong Insomnia
      • Product Updates
      • Get Started
    • Documentation
      • Kong Konnect Docs
      • Kong Gateway Docs
      • Kong Gateway Enterprise Docs
      • Kong Mesh Docs
      • Kong Insomnia Docs
      • Kong Konnect Plugin Hub
    • Open Source
      • Kong Gateway
      • Kuma
      • Insomnia
      • Kong Community
    • Company
      • About Kong
      • Customers
      • Careers
      • Press
      • Events
      • Contact
  • Terms• Privacy• Trust and Compliance
© Kong Inc. 2023