旧バージョンのドキュメントを参照しています。
            
                
                最新のドキュメントはこちらをご参照ください。
              
          
          
          
          
          Kong Gatewayのインストール
            
            
              
            
          
          
          
          
          このガイドでは、Kong Konnect または Kong Ingress Controller を使用せずに Kubernetes に Kong Gateway をデプロイする方法について説明します。
  デプロイメントの複雑さを軽減するために、新規インストールにはKong Konnectをお勧めします。
Kongがコントロールプレーンとデータベースを実行します。Kong Konnectは、データプレーンを実行するだけで済み、5分以内に開始できます。
これらの手順で、コントロールプレーン(CP)とデータプレーン(DP)を別々にデプロイするように Kong Gateway を構成します。これは、推奨のインストール方法です。
前提条件
Helmのセットアップ
Kongは、 Kong GatewayをデプロイするためのHelmチャートを提供します。charts.konghq.comリポジトリを追加し、helm repo updateを実行して、最新バージョンのチャートを確保します。
helm repo add kong https://charts.konghq.com
helm repo update
 
シークレット
Kong Gateway Enterpriseライセンス
まず、kongの名前空間を作成します。
kubectl create namespace kong
 
次に、Kong Gateway Enterprise ライセンスシークレットを作成します。
  
  
    
    
      Kong Gateway Enterprise Free Mode
    
  
    
    
      Kong Gateway Enterprise Licensed Mode
    
  
   
  
  
  
  
    
kubectl create secret generic kong-enterprise-license --from-literal=license="'{}'" -n kong
 
   
  
  
    
  このコマンドを実行する前に、license.json ファイルが含まれているディレクトリにいることを確認してください。
kubectl create secret generic kong-enterprise-license --from-file=license=license.json -n kong
 
   
   
 
証明書のクラスタリング
Kong Gatewayは、ハイブリッドモードで実行している場合、mTLSを使用してコントロールプレーン/データプレーンの通信を保護します。
  - 
    
OpenSSLを使用してTLS証明書を生成します。
    
openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout ./tls.key -out ./tls.crt -days 1095 -subj "/CN=kong_clustering"
      
   
  - 
    
証明書を含む Kubernetes シークレットを作成します。
    
kubectl create secret tls kong-cluster-cert --cert=./tls.crt --key=./tls.key -n kong
      
   
インストール
コントロールプレーン(CP)
コントロールプレーンにはすべてのKong Gateway構成が含まれています。設定はPostgreSQLデータベースに保存されます。
  - 
    
values-cp.yamlファイルを作成します。
    
  
     
       
    
      Kong Gateway
    
     
       
    
      Kong Gateway (OSS)
    
     
   
  
     
     
  
       
# Do not use Kong Ingress Controller
ingressController:
  enabled: false
   
image:
  repository: kong/kong-gateway
  tag: "3.4.3.18"
   
# Mount the secret created earlier
secretVolumes:
  - kong-cluster-cert
   
env:
  # This is a control_plane node
  role: control_plane
  # These certificates are used for control plane / data plane communication
  cluster_cert: /etc/secrets/kong-cluster-cert/tls.crt
  cluster_cert_key: /etc/secrets/kong-cluster-cert/tls.key
   
  # Database
  # CHANGE THESE VALUES
  database: postgres
  pg_database: kong
  pg_user: kong
  pg_password: demo123
  pg_host: kong-cp-postgresql.kong.svc.cluster.local
  pg_ssl: "on"
   
  # Kong Manager password
  password: kong_admin_password
   
# Enterprise functionality
enterprise:
  enabled: true
  license_secret: kong-enterprise-license
   
# The control plane serves the Admin API
admin:
  enabled: true
  http:
    enabled: true
   
# Clustering endpoints are required in hybrid mode
cluster:
  enabled: true
  tls:
    enabled: true
   
clustertelemetry:
  enabled: true
  tls:
    enabled: true
   
# Optional features
manager:
  enabled: false
   
portal:
  enabled: false
   
portalapi:
  enabled: false
   
# These roles will be served by different Helm releases
proxy:
  enabled: false
 
   
   
   
   
     
  
       
# Do not use Kong Ingress Controller
ingressController:
  enabled: false
   
image:
  repository: kong
  tag: "3.4.2"
   
# Mount the secret created earlier
secretVolumes:
  - kong-cluster-cert
   
env:
  # This is a control_plane node
  role: control_plane
  # These certificates are used for control plane / data plane communication
  cluster_cert: /etc/secrets/kong-cluster-cert/tls.crt
  cluster_cert_key: /etc/secrets/kong-cluster-cert/tls.key
   
  # Database
  # CHANGE THESE VALUES
  database: postgres
  pg_database: kong
  pg_user: kong
  pg_password: demo123
  pg_host: kong-cp-postgresql.kong.svc.cluster.local
  pg_ssl: "on"
   
  # Kong Manager password
  password: kong_admin_password
   
# Enterprise functionality
enterprise:
  enabled: false
  license_secret: kong-enterprise-license
   
# The control plane serves the Admin API
admin:
  enabled: true
  http:
    enabled: true
   
# Clustering endpoints are required in hybrid mode
cluster:
  enabled: true
  tls:
    enabled: true
   
clustertelemetry:
  enabled: true
  tls:
    enabled: true
   
# Optional features
manager:
  enabled: false
   
portal:
  enabled: false
   
portalapi:
  enabled: false
   
# These roles will be served by different Helm releases
proxy:
  enabled: false
 
   
   
   
   
   
   
 
   
  - 
    
(オプション) テスト目的でクラスタ内にPostgresデータベースをデプロイする場合は、values-cp.yamlの末尾に次のコードを追加します。
    
# This is for testing purposes only
# DO NOT DO THIS IN PRODUCTION
# Your cluster needs a way to create PersistentVolumeClaims
# if this option is enabled
postgresql:
  enabled: true
  auth:
    password: demo123
      
   
  - 
    
values-cp.yamlのデータベース接続値を更新します。
    
      - 
env.pg_database: 使用するデータベース名 
      - 
env.pg_user:データベースのユーザー名 
      - 
env.pg_password: データベースのパスワード 
      - 
env.pg_host: Postgresデータベースのホスト名 
      - 
env.pg_ssl:SSLを使用してデータベースに接続します 
    
   
  - 
    
values-cp.yamlでKong Managerスーパー管理者パスワードを設定します。
    
      - 
env.password:Kong Managerのスーパー管理者パスワード 
    
   
  - 
    
helm installを実行してリリースを作成します。
    
helm install kong-cp kong/kong -n kong --values ./values-cp.yaml
      
   
  - 
    
kubectl get pods -n kongを実行します。コントロールプレーン(CP)が期待どおりに実行されるようにします。
    
NAME                                 READY   STATUS
kong-cp-kong-7bb77dfdf9-x28xf        1/1     Running
      
   
データプレーン(DP)
Kong Gateway データプレーンは、受信トラフィックの処理をします。クラスタリングエンドポイントを使用して、コントロールプレーンからルーティング構成を受け取ります。
  - 
    
values-dp.yamlファイルを作成します。
    
  
     
       
    
      Kong Gateway
    
     
       
    
      Kong Gateway (OSS)
    
     
   
  
     
     
  
       
# Do not use Kong Ingress Controller
ingressController:
  enabled: false
   
image:
  repository: kong/kong-gateway
  tag: "3.4.3.18"
   
# Mount the secret created earlier
secretVolumes:
  - kong-cluster-cert
   
env:
  # data_plane nodes do not have a database
  role: data_plane
  database: "off"
   
  # Tell the data plane how to connect to the control plane
  cluster_control_plane: kong-cp-kong-cluster.kong.svc.cluster.local:8005
  cluster_telemetry_endpoint: kong-cp-kong-clustertelemetry.kong.svc.cluster.local:8006
   
  # Configure control plane / data plane authentication
  lua_ssl_trusted_certificate: /etc/secrets/kong-cluster-cert/tls.crt
  cluster_cert: /etc/secrets/kong-cluster-cert/tls.crt
  cluster_cert_key: /etc/secrets/kong-cluster-cert/tls.key
   
# Enterprise functionality
enterprise:
  enabled: true
  license_secret: kong-enterprise-license
   
# The data plane handles proxy traffic only
proxy:
  enabled: true
   
# These roles are served by the kong-cp deployment
admin:
  enabled: false
   
portal:
  enabled: false
   
portalapi:
  enabled: false
   
manager:
  enabled: false
 
   
   
   
   
     
  
       
# Do not use Kong Ingress Controller
ingressController:
  enabled: false
   
image:
  repository: kong
  tag: "3.4.2"
   
# Mount the secret created earlier
secretVolumes:
  - kong-cluster-cert
   
env:
  # data_plane nodes do not have a database
  role: data_plane
  database: "off"
   
  # Tell the data plane how to connect to the control plane
  cluster_control_plane: kong-cp-kong-cluster.kong.svc.cluster.local:8005
  cluster_telemetry_endpoint: kong-cp-kong-clustertelemetry.kong.svc.cluster.local:8006
   
  # Configure control plane / data plane authentication
  lua_ssl_trusted_certificate: /etc/secrets/kong-cluster-cert/tls.crt
  cluster_cert: /etc/secrets/kong-cluster-cert/tls.crt
  cluster_cert_key: /etc/secrets/kong-cluster-cert/tls.key
   
# Enterprise functionality
enterprise:
  enabled: false
  license_secret: kong-enterprise-license
   
# The data plane handles proxy traffic only
proxy:
  enabled: true
   
# These roles are served by the kong-cp deployment
admin:
  enabled: false
   
portal:
  enabled: false
   
portalapi:
  enabled: false
   
manager:
  enabled: false
 
   
   
   
   
   
   
 
   
  - 
    
helm installを実行してリリースを作成します。
    
helm install kong-dp kong/kong -n kong --values ./values-dp.yaml
      
   
  - 
    
kubectl get pods -n kongを実行します。データプレーンが期待どおりに実行されることを確実にします。
    
NAME                                 READY   STATUS
kong-dp-kong-5dbcd9f6b9-f2w49        1/1     Running
      
   
テスト
Kong Gateway現在実行中です。テストトラフィックを送信するには、次の操作を試してください。
  - 
    
kong-dpサービスのLoadBalancerアドレスを取得し、PROXY_IP環境変数に保存します
    
PROXY_IP=$(kubectl get service --namespace kong kong-dp-kong-proxy -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}')
      
   
  - 
    
$PROXY_IP に HTTP リクエストを送信します。これには、Kong Gateway によって提供される HTTP 404 が返されます
    
curl $PROXY_IP/mock/anything
      
   
  - 
    
別のターミナルで、 kubectl port-forwardを実行してポート転送を設定し、管理 API にアクセスします。
    
kubectl port-forward -n kong service/kong-cp-kong-admin 8001
      
   
  - 
    
模擬サービスとルートの作成
    
curl localhost:8001/services -d name=mock  -d url="http://httpbin.org"
curl localhost:8001/services/mock/routes -d "paths=/mock"
      
   
  - 
    
$PROXY_IPに対して HTTP 要求を再度行います。今回はKong Gatewayリクエストをhttpbinにルーティングします。
    
curl $PROXY_IP/mock/anything