【Kong初心者向け】Canary Release Pluginの使い方

「SIOS社員が今年一年で学んだこと」アドベントカレンダー9日目です。

最近少し苦戦した、Kongの小ネタを紹介させていただきます。

想定状況

旧サービスから新サービスに移行するにあたって、まずは一部のユーザーにのみ公開し動作を確認してから全体公開したい…という状況を考えます。

旧サービス:http://httpbin.org/xml
新サービス:http://httpbin.org/json

こういった作業を本番で作業を行う場合はdecKコマンドを叩くと思いますが、今回は分かりやすさ重視でKong Manager上からポチポチ設定していく手順を紹介します。

また、canary release pluginはenterprise onlyのため、順当な手段で試そうとするとハードルが高いです。幸いKong academy内で実際のKongの操作を試せるvirtual labではenterprise onlyなpluginでも使うことができるので、そちらを使わせていただきましょう。

操作手順

workspace作成

適当なworkspaceを作ります。複数のworkspace作成もenterprise機能だった気が…

serviceの作成

Gateway Servicesから、旧サービスとなるhttp://httpbin.org/xmlを割り当てたcanary-api-serviceを作成します。

Name: canary-api-service
Full URL: http://httpbin.org/xml

routeの作成

上記のserviceに紐づいたrouteを作成します。

Name: canary-api-route
Service: canary-api-service
Path: /api/canary

疎通確認

curl -i http://localhost:8000/api/canary
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 522
Connection: keep-alive
Date: Sat, 06 Dec 2025 11:55:35 GMT
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Kong-Upstream-Status: 200
X-Kong-Upstream-Latency: 2009
X-Kong-Proxy-Latency: 2
Via: 1.1 kong/3.10.0.6-enterprise-edition

<?xml version='1.0' encoding='us-ascii'?>

<!--  A SAMPLE set of slides  -->

<slideshow 
    title="Sample Slide Show"
    date="Date of publication"
    author="Yours Truly"
    >

    <!-- TITLE SLIDE -->
    <slide type="all">
      <title>Wake up to WonderWidgets!</title>
    </slide>

    <!-- OVERVIEW -->
    <slide type="all">
        <title>Overview</title>
        <item>Why <em>WonderWidgets</em> are great</item>
        <item/>
        <item>Who <em>buys</em> WonderWidgets</item>
    </slide>

</slideshow>

key auth pluginを設定

routeに対してpluginを適応します。

Scoped
Route: canary-api-route

consumerを作成

旧サービスを見せるか新サービスを見せるか分類するため、2つのconsumerを作成します。

Username: general-consumer

同様に、Username: vip-consumerでvip-consumerを作成します。

key auth credential付与

それぞれのconsumerにcredentialを付与します。

general-consumerはgeneral-apiを割り当てます

同様に、vip-consumerにはvip-apiを割り当てます。

疎通確認

apikeyがない場合、401で弾かれます。

curl -i http://localhost:8000/api/canary
HTTP/1.1 401 Unauthorized
Date: Thu, 06 Nov 2025 02:13:07 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
WWW-Authenticate: Key realm="kong"
Content-Length: 96
X-Kong-Response-Latency: 5
Server: kong/3.4.3.21-enterprise-edition

{
  "message":"No API key found in request",
  "request_id":"e9f5080d632bba08e2ba023597c3d006"
}

先ほど設定したapikeyがあれば、アクセスが可能です。

curl -i http://localhost:8000/api/canary?apikey=general-api
curl -i http://localhost:8000/api/canary?apikey=vip-api
HTTP/1.1 200 OK
(以下略)

acl pluginを設定

Scoped
Route: canary-api-route
Allow: general-acl, vip-acl

acl credentialを付与

各consumerにacl credentialを付与します

vip-consumerに対しても同様に、vip-aclを設定します。

canary pluginを設定

以下の通り設定します。

Scoped
Route: canary-api-route
UpstreamHost : httpbin.org
UpstreamPort : 80
UpstreamUri : /json
Groups : vip-acl
Hash: allow

疎通確認

これで、general-consumerは旧サービス(/xml)が見え、vip-consumerは新サービス(/json)が見えるようになりました。

curl -i http://localhost:8000/api/canary?apikey=general-api
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 522
Connection: keep-alive
Date: Sat, 06 Dec 2025 11:55:35 GMT
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Kong-Upstream-Status: 200
X-Kong-Upstream-Latency: 2009
X-Kong-Proxy-Latency: 2
Via: 1.1 kong/3.10.0.6-enterprise-edition

<?xml version='1.0' encoding='us-ascii'?>

<!--  A SAMPLE set of slides  -->

<slideshow 
    title="Sample Slide Show"
    date="Date of publication"
    author="Yours Truly"
    >

    <!-- TITLE SLIDE -->
    <slide type="all">
      <title>Wake up to WonderWidgets!</title>
    </slide>

    <!-- OVERVIEW -->
    <slide type="all">
        <title>Overview</title>
        <item>Why <em>WonderWidgets</em> are great</item>
        <item/>
        <item>Who <em>buys</em> WonderWidgets</item>
    </slide>

</slideshow>
curl -i http://localhost:8000/api/canary?apikey=vip-api
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 429
Connection: keep-alive
Date: Sat, 06 Dec 2025 12:02:41 GMT
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Kong-Upstream-Status: 200
X-Kong-Upstream-Latency: 1530
X-Kong-Proxy-Latency: 3
Via: 1.1 kong/3.10.0.6-enterprise-edition

{
  "slideshow": {
    "author": "Yours Truly", 
    "date": "date of publication", 
    "slides": [
      {
        "title": "Wake up to WonderWidgets!", 
        "type": "all"
      }, 
      {
        "items": [
          "Why <em>WonderWidgets</em> are great", 
          "Who <em>buys</em> WonderWidgets"
        ], 
        "title": "Overview", 
        "type": "all"
      }
    ], 
    "title": "Sample Slide Show"
  }
}

本リリース

vip-consumerに対してカナリアリリースを行い、十分に動作検証ができたとします。canary release状態から通常リリースに変更するには、serviceに登録しているendpointを新サービスのものに変更し、canary release pluginを削除すればOKです

いかがでしたか?

長々とした拙筆にお付き合いいただきありがとうございました。本記事が皆様の、何かしらの助けになれば幸いです。

ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

0人がこの投稿は役に立ったと言っています。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です