본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

모킹: API 사양으로 엔드포인트 모킹하기

원문 보기 위키 갱신

모킹: API 사양으로 엔드포인트 모킹하기 (Mocking: Mock endpoints using an API spec)

Mocking 플러그인을 설정하고 PetStore API 사양을 전달해서 엔드포인트를 모킹하는 방법을 소개해요. OpenAPI 사양만 있으면 실제 백엔드를 구현하지 않아도 가짜 응답으로 API를 손쉽게 테스트할 수 있어요. decK 설정 파일에 플러그인을 추가하는 글로벌 설정 방법을 예시와 함께 차근차근 살펴봐요

출처: 문서

본문

API 사양을 사용해 엔드포인트 모킹하기v2.4+

Mocking 플러그인을 구성하고 PetStore API 사양을 전달해요.

플러그인 설정하기

글로벌

decK

다음 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: mocking
    config:
      api_specification: |
        openapi: 3.0.2
        servers:
          - url: /v3
        info:
          description: |-
            This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
            Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
            You can now help us improve the API whether it's by making changes to the definition itself or to the code.
            That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
            Some useful links:
            - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
            - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
          version: 1.0.20-SNAPSHOT
          title: Swagger Petstore - OpenAPI 3.0
          termsOfService: 'http://swagger.io/terms/'
          contact:
            email: apiteam@swagger.io
          license:
            name: Apache 2.0
            url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
        tags:
          - name: pet
            description: Everything about your Pets
            externalDocs:
              description: Find out more
              url: 'http://swagger.io'
          - name: store
            description: Access to Petstore orders
            externalDocs:
              description: Find out more about our store
              url: 'http://swagger.io'
          - name: user
            description: Operations about user
        paths:
          /pet:
            post:
              tags:
                - pet
              summary: Add a new pet to the store
              description: Add a new pet to the store
              operationId: addPet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '405':
                  description: Invalid input
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Create a new pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'
            put:
              tags:
                - pet
              summary: Update an existing pet
              description: Update an existing pet by Id
              operationId: updatePet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '400':
                  description: Invalid ID supplied
                '404':
                  description: Pet not found
                '405':
                  description: Validation exception
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Update an existent pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'

{: data-file="kong.yaml" data-tool="deck" }

Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '
Konnect API

다음 요청을 만들어 보세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

  • region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요.

  • KONNECT_TOKEN: 여러분의 Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

지역별 URL과 개인 액세스 토큰에 대해 자세히 알아보려면 Konnect Control Planes Config API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
  labels:
    global: 'true'
config:
  api_specification: |
    openapi: 3.0.2
    servers:
      - url: /v3
    info:
      description: |-
        This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
        Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
        You can now help us improve the API whether it's by making changes to the definition itself or to the code.
        That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
        Some useful links:
        - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
        - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
      version: 1.0.20-SNAPSHOT
      title: Swagger Petstore - OpenAPI 3.0
      termsOfService: 'http://swagger.io/terms/'
      contact:
        email: apiteam@swagger.io
      license:
        name: Apache 2.0
        url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
    tags:
      - name: pet
        description: Everything about your Pets
        externalDocs:
          description: Find out more
          url: 'http://swagger.io'
      - name: store
        description: Access to Petstore orders
        externalDocs:
          description: Find out more about our store
          url: 'http://swagger.io'
      - name: user
        description: Operations about user
    paths:
      /pet:
        post:
          tags:
            - pet
          summary: Add a new pet to the store
          description: Add a new pet to the store
          operationId: addPet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '405':
              description: Invalid input
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Create a new pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
        put:
          tags:
            - pet
          summary: Update an existing pet
          description: Update an existing pet by Id
          operationId: updatePet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '400':
              description: Invalid ID supplied
            '404':
              description: Pet not found
            '405':
              description: Validation exception
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Update an existent pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -
Terraform
사전 준비: 개인 액세스 토큰 구성하기
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_mocking" "my_mocking" {
  enabled = true

  config = {
    api_specification = <<EOF
openapi: 3.0.2
servers:
  - url: /v3
info:
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
  version: 1.0.20-SNAPSHOT
  title: Swagger Petstore - OpenAPI 3.0
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
  - name: user
    description: Operations about user
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '405':
          description: Invalid input
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Create a new pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
        '405':
          description: Validation exception
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Update an existent pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
EOF
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

Service

decK

이 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: mocking
    service: serviceName|Id
    config:
      api_specification: |
        openapi: 3.0.2
        servers:
          - url: /v3
        info:
          description: |-
            This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
            Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
            You can now help us improve the API whether it's by making changes to the definition itself or to the code.
            That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
            Some useful links:
            - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
            - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
          version: 1.0.20-SNAPSHOT
          title: Swagger Petstore - OpenAPI 3.0
          termsOfService: 'http://swagger.io/terms/'
          contact:
            email: apiteam@swagger.io
          license:
            name: Apache 2.0
            url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
        tags:
          - name: pet
            description: Everything about your Pets
            externalDocs:
              description: Find out more
              url: 'http://swagger.io'
          - name: store
            description: Access to Petstore orders
            externalDocs:
              description: Find out more about our store
              url: 'http://swagger.io'
          - name: user
            description: Operations about user
        paths:
          /pet:
            post:
              tags:
                - pet
              summary: Add a new pet to the store
              description: Add a new pet to the store
              operationId: addPet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '405':
                  description: Invalid input
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Create a new pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'
            put:
              tags:
                - pet
              summary: Update an existing pet
              description: Update an existing pet by Id
              operationId: updatePet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '400':
                  description: Invalid ID supplied
                '404':
                  description: Pet not found
                '405':
                  description: Validation exception
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Update an existent pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'

{: data-file="kong.yaml" data-tool="deck" }

다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:

  • serviceName|Id: 플러그인 구성이 대상으로 지정할 서비스의 id 또는 name이에요.
Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:

  • serviceName|Id: 플러그인 구성이 대상으로 지정할 서비스의 id 또는 name이에요.
Konnect API

다음 요청을 만들어 보세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 자리표를 여러분의 값으로 바꿔야 해요:

  • region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • serviceId: 플러그인 구성이 대상으로 삼을 서비스의 id예요.

지역별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API reference를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  api_specification: |
    openapi: 3.0.2
    servers:
      - url: /v3
    info:
      description: |-
        This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
        Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
        You can now help us improve the API whether it's by making changes to the definition itself or to the code.
        That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
        Some useful links:
        - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
        - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
      version: 1.0.20-SNAPSHOT
      title: Swagger Petstore - OpenAPI 3.0
      termsOfService: 'http://swagger.io/terms/'
      contact:
        email: apiteam@swagger.io
      license:
        name: Apache 2.0
        url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
    tags:
      - name: pet
        description: Everything about your Pets
        externalDocs:
          description: Find out more
          url: 'http://swagger.io'
      - name: store
        description: Access to Petstore orders
        externalDocs:
          description: Find out more about our store
          url: 'http://swagger.io'
      - name: user
        description: Operations about user
    paths:
      /pet:
        post:
          tags:
            - pet
          summary: Add a new pet to the store
          description: Add a new pet to the store
          operationId: addPet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '405':
              description: Invalid input
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Create a new pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
        put:
          tags:
            - pet
          summary: Update an existing pet
          description: Update an existing pet by Id
          operationId: updatePet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '400':
              description: Invalid ID supplied
            '404':
              description: Pet not found
            '405':
              description: Validation exception
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Update an existent pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -

다음으로, service 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용해 보세요:

kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=
Terraform
사전 요구 사항: Personal Access Token 구성하기
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_mocking" "my_mocking" {
  enabled = true

  config = {
    api_specification = <<EOF
openapi: 3.0.2
servers:
  - url: /v3
info:
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
  version: 1.0.20-SNAPSHOT
  title: Swagger Petstore - OpenAPI 3.0
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
  - name: user
    description: Operations about user
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '405':
          description: Invalid input
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Create a new pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
        '405':
          description: Validation exception
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Update an existent pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
EOF
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  service = {
    id = konnect_gateway_service.my_service.id
  }
}

라우트

decK

이 섹션을 kong.yaml 구성 파일에 추가하세요:

_format_version: "3.0"
plugins:
  - name: mocking
    route: routeName|Id
    config:
      api_specification: |
        openapi: 3.0.2
        servers:
          - url: /v3
        info:
          description: |-
            This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
            Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
            You can now help us improve the API whether it's by making changes to the definition itself or to the code.
            That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
            Some useful links:
            - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
            - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
          version: 1.0.20-SNAPSHOT
          title: Swagger Petstore - OpenAPI 3.0
          termsOfService: 'http://swagger.io/terms/'
          contact:
            email: apiteam@swagger.io
          license:
            name: Apache 2.0
            url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
        tags:
          - name: pet
            description: Everything about your Pets
            externalDocs:
              description: Find out more
              url: 'http://swagger.io'
          - name: store
            description: Access to Petstore orders
            externalDocs:
              description: Find out more about our store
              url: 'http://swagger.io'
          - name: user
            description: Operations about user
        paths:
          /pet:
            post:
              tags:
                - pet
              summary: Add a new pet to the store
              description: Add a new pet to the store
              operationId: addPet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '405':
                  description: Invalid input
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Create a new pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'
            put:
              tags:
                - pet
              summary: Update an existing pet
              description: Update an existing pet by Id
              operationId: updatePet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '400':
                  description: Invalid ID supplied
                '404':
                  description: Pet not found
                '405':
                  description: Validation exception
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Update an existent pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'

{: data-file="kong.yaml" data-tool="deck" }

다음 플레이스홀더는 반드시 여러분의 값으로 바꾸세요:

  • routeName|Id: 플러그인 구성이 대상으로 지정할 라우트의 id 또는 name이에요.
Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

  • routeName|Id: 플러그인 구성이 대상으로 삼을 라우트의 id 또는 name이에요.
Konnect API

다음 요청을 보내세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

  • region: 여러분의 Kong Konnect가 호스팅되고 운영되는 지리적 지역이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • routeId: 플러그인 구성이 대상으로 삼을 라우트의 id예요.

지역별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 참조를 확인하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  api_specification: |
    openapi: 3.0.2
    servers:
      - url: /v3
    info:
      description: |-
        This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
        Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
        You can now help us improve the API whether it's by making changes to the definition itself or to the code.
        That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
        Some useful links:
        - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
        - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
      version: 1.0.20-SNAPSHOT
      title: Swagger Petstore - OpenAPI 3.0
      termsOfService: 'http://swagger.io/terms/'
      contact:
        email: apiteam@swagger.io
      license:
        name: Apache 2.0
        url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
    tags:
      - name: pet
        description: Everything about your Pets
        externalDocs:
          description: Find out more
          url: 'http://swagger.io'
      - name: store
        description: Access to Petstore orders
        externalDocs:
          description: Find out more about our store
          url: 'http://swagger.io'
      - name: user
        description: Operations about user
    paths:
      /pet:
        post:
          tags:
            - pet
          summary: Add a new pet to the store
          description: Add a new pet to the store
          operationId: addPet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '405':
              description: Invalid input
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Create a new pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
        put:
          tags:
            - pet
          summary: Update an existing pet
          description: Update an existing pet by Id
          operationId: updatePet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '400':
              description: Invalid ID supplied
            '404':
              description: Pet not found
            '405':
              description: Validation exception
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Update an existent pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -

다음으로, httproute 또는 ingress 리소스에 어노테이션을 추가해서 KongPlugin 리소스를 적용해요:

Gateway API
kubectl annotate -n kong httproute  konghq.com/plugins=
Ingress
kubectl annotate -n kong ingress  konghq.com/plugins=
Terraform
사전 준비: Personal Access Token 구성하기
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway Plugin을 생성하려면 Terraform 구성에 다음 내용을 추가해요:

resource "konnect_gateway_plugin_mocking" "my_mocking" {
  enabled = true

  config = {
    api_specification = <<EOF
openapi: 3.0.2
servers:
  - url: /v3
info:
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
  version: 1.0.20-SNAPSHOT
  title: Swagger Petstore - OpenAPI 3.0
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
  - name: user
    description: Operations about user
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '405':
          description: Invalid input
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Create a new pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
        '405':
          description: Validation exception
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Update an existent pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
EOF
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  route = {
    id = konnect_gateway_route.my_route.id
  }
}

Consumer

decK

kong.yaml 설정 파일에 다음 섹션을 추가해요:

_format_version: "3.0"
plugins:
  - name: mocking
    consumer: consumerName|Id
    config:
      api_specification: |
        openapi: 3.0.2
        servers:
          - url: /v3
        info:
          description: |-
            This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
            Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
            You can now help us improve the API whether it's by making changes to the definition itself or to the code.
            That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
            Some useful links:
            - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
            - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
          version: 1.0.20-SNAPSHOT
          title: Swagger Petstore - OpenAPI 3.0
          termsOfService: 'http://swagger.io/terms/'
          contact:
            email: apiteam@swagger.io
          license:
            name: Apache 2.0
            url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
        tags:
          - name: pet
            description: Everything about your Pets
            externalDocs:
              description: Find out more
              url: 'http://swagger.io'
          - name: store
            description: Access to Petstore orders
            externalDocs:
              description: Find out more about our store
              url: 'http://swagger.io'
          - name: user
            description: Operations about user
        paths:
          /pet:
            post:
              tags:
                - pet
              summary: Add a new pet to the store
              description: Add a new pet to the store
              operationId: addPet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '405':
                  description: Invalid input
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Create a new pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'
            put:
              tags:
                - pet
              summary: Update an existing pet
              description: Update an existing pet by Id
              operationId: updatePet
              responses:
                '200':
                  description: Successful operation
                  content:
                    application/xml:
                      schema:
                        $ref: '#/components/schemas/Pet'
                    application/json:
                      schema:
                        $ref: '#/components/schemas/Pet'
                '400':
                  description: Invalid ID supplied
                '404':
                  description: Pet not found
                '405':
                  description: Validation exception
              security:
                - petstore_auth:
                    - 'write:pets'
                    - 'read:pets'
              requestBody:
                description: Update an existent pet in the store
                required: true
                content:
                  application/json:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/xml:
                    schema:
                      $ref: '#/components/schemas/Pet'
                  application/x-www-form-urlencoded:
                    schema:
                      $ref: '#/components/schemas/Pet'

{: data-file="kong.yaml" data-tool="deck" }

다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:

  • consumerName|Id: 플러그인 구성이 대상으로 할 컨슈머의 id 또는 name이에요.
Admin API

다음 요청을 보내세요:

curl -i -X POST http://localhost:8001/consumers/{consumerName|Id}/plugins/ \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 플레이스홀더는 여러분의 값으로 바꿔야 해요:

  • consumerName|Id: 플러그인 구성이 대상으로 할 컨슈머의 id 또는 name이에요.
Konnect API

다음 요청을 보내세요:

curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumers/{consumerId}/plugins/ \
    --header "accept: application/json" \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $KONNECT_TOKEN" \
    --data '
    {
      "name": "mocking",
      "config": {
        "api_specification": "openapi: 3.0.2\nservers:\n  - url: /v3\ninfo:\n  description: |-\n    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\n    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n    You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n    Some useful links:\n    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n  version: 1.0.20-SNAPSHOT\n  title: Swagger Petstore - OpenAPI 3.0\n  termsOfService: 'http://swagger.io/terms/'\n  contact:\n    email: apiteam@swagger.io\n  license:\n    name: Apache 2.0\n    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n  - name: pet\n    description: Everything about your Pets\n    externalDocs:\n      description: Find out more\n      url: 'http://swagger.io'\n  - name: store\n    description: Access to Petstore orders\n    externalDocs:\n      description: Find out more about our store\n      url: 'http://swagger.io'\n  - name: user\n    description: Operations about user\npaths:\n  /pet:\n    post:\n      tags:\n        - pet\n      summary: Add a new pet to the store\n      description: Add a new pet to the store\n      operationId: addPet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '405':\n          description: Invalid input\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Create a new pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n    put:\n      tags:\n        - pet\n      summary: Update an existing pet\n      description: Update an existing pet by Id\n      operationId: updatePet\n      responses:\n        '200':\n          description: Successful operation\n          content:\n            application/xml:\n              schema:\n                $ref: '#/components/schemas/Pet'\n            application/json:\n              schema:\n                $ref: '#/components/schemas/Pet'\n        '400':\n          description: Invalid ID supplied\n        '404':\n          description: Pet not found\n        '405':\n          description: Validation exception\n      security:\n        - petstore_auth:\n            - 'write:pets'\n            - 'read:pets'\n      requestBody:\n        description: Update an existent pet in the store\n        required: true\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/xml:\n            schema:\n              $ref: '#/components/schemas/Pet'\n          application/x-www-form-urlencoded:\n            schema:\n              $ref: '#/components/schemas/Pet'\n"
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • consumerId: 플러그인 구성이 대상으로 삼을 컨슈머의 id예요.

리전별 URL과 개인 액세스 토큰에 대해 자세히 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  api_specification: |
    openapi: 3.0.2
    servers:
      - url: /v3
    info:
      description: |-
        This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
        Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
        You can now help us improve the API whether it's by making changes to the definition itself or to the code.
        That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
        Some useful links:
        - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
        - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
      version: 1.0.20-SNAPSHOT
      title: Swagger Petstore - OpenAPI 3.0
      termsOfService: 'http://swagger.io/terms/'
      contact:
        email: apiteam@swagger.io
      license:
        name: Apache 2.0
        url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
    tags:
      - name: pet
        description: Everything about your Pets
        externalDocs:
          description: Find out more
          url: 'http://swagger.io'
      - name: store
        description: Access to Petstore orders
        externalDocs:
          description: Find out more about our store
          url: 'http://swagger.io'
      - name: user
        description: Operations about user
    paths:
      /pet:
        post:
          tags:
            - pet
          summary: Add a new pet to the store
          description: Add a new pet to the store
          operationId: addPet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '405':
              description: Invalid input
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Create a new pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
        put:
          tags:
            - pet
          summary: Update an existing pet
          description: Update an existing pet by Id
          operationId: updatePet
          responses:
            '200':
              description: Successful operation
              content:
                application/xml:
                  schema:
                    $ref: '#/components/schemas/Pet'
                application/json:
                  schema:
                    $ref: '#/components/schemas/Pet'
            '400':
              description: Invalid ID supplied
            '404':
              description: Pet not found
            '405':
              description: Validation exception
          security:
            - petstore_auth:
                - 'write:pets'
                - 'read:pets'
          requestBody:
            description: Update an existent pet in the store
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/xml:
                schema:
                  $ref: '#/components/schemas/Pet'
              application/x-www-form-urlencoded:
                schema:
                  $ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -

다음으로, KongConsumer 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용하세요:

kubectl annotate -n kong kongconsumer CONSUMER_NAME konghq.com/plugins=
Terraform
사전 요구 사항: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음을 추가하세요:

resource "konnect_gateway_plugin_mocking" "my_mocking" {
  enabled = true

  config = {
    api_specification = <<EOF
openapi: 3.0.2
servers:
  - url: /v3
info:
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
  version: 1.0.20-SNAPSHOT
  title: Swagger Petstore - OpenAPI 3.0
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
  - name: user
    description: Operations about user
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '405':
          description: Invalid input
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Create a new pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      responses:
        '200':
          description: Successful operation
          content:
            application/xml:
              schema:
                $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        '400':
          description: Invalid ID supplied
        '404':
          description: Pet not found
        '405':
          description: Validation exception
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
      requestBody:
        description: Update an existent pet in the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
          application/xml:
            schema:
              $ref: '#/components/schemas/Pet'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Pet'
EOF
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  consumer = {
    id = konnect_gateway_consumer.my_consumer.id
  }
}

관련 리소스

더 알아보기 (Learn more)