Skip to content
2023 API Summit Hackathon: Experiment with AI for APIs (August 28 - September 27) Learn More →
Kong Logo | Kong Docs Logo
search
  • We're Hiring!
  • Docs
    • 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
  • API Specs
  • 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.25.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.27.x (latest)
  • 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
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: Mockbin API
  description: Simple API for testing purposes
  version: 1.0.0
servers:
  - url: http://mockbin.org
paths:
  /request:
    get:
      summary: Get a simple response from the /request resource of the mockbin API
      responses:
        '200':
          description: Successful response

You can generate a Kong Gateway configuration with the following:

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

Which produces a complete decK configuration file:

_format_version: "3.0"
services:
- host: mockbin.org
  id: de7107e7-a39c-5574-9e8c-e66787ae50e7
  name: mockbin-api
  path: /
  plugins: []
  port: 80
  protocol: http
  routes:
  - id: 803b324e-98ed-5ec5-aecf-b4ce973036f4
    methods:
    - GET
    name: mockbin-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 syncronize this directly to the gateway using deck sync:

deck sync -s mockbin.yaml

Which creates the service and route:

creating service mockbin-api
creating route mockbin-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 syncronizing 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-mockbin.yaml:

_format_version: "3.0"
services:
- host: mockbin.org
  id: 7cc31086-3837-4e7e-bbe9-271e51c1f614 
  name: another-mockbin-api
  path: /
  plugins: []
  port: 80
  protocol: http
  routes:
  - id: 08ac3482-843a-40f8-a277-a4e73baf19d9 
    methods:
    - GET
    name: another-mockbin-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 mockbin.yaml another-mockbin.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 mockbin.yaml && 
  deck file merge mockbin.yaml another-mockbin.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.

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
    THE CLOUD CONNECTIVITY COMPANY

    Kong powers reliable digital connections across APIs, hybrid and multi-cloud environments.

    • Company
    • Customers
    • Events
    • Investors
    • Careers Hiring!
    • Partners
    • Press
    • Contact
  • Products
    • Kong Konnect
    • Kong Gateway
    • Kong Mesh
    • Get Started
    • Pricing
  • Resources
    • eBooks
    • Webinars
    • Briefs
    • Blog
    • API Gateway
    • Microservices
  • Open Source
    • Install Kong Gateway
    • Kong Community
    • Kubernetes Ingress
    • Kuma
    • Insomnia
  • Solutions
    • Decentralize
    • Secure & Govern
    • Create a Dev Platform
    • API Gateway
    • Kubernetes
    • Service Mesh
Star
  • Terms•Privacy
© Kong Inc. 2023