一般社団法人 全国個人事業主支援協会

COLUMN コラム

Kubernetes クラスタ内で HTTP(S) トラフィックを管理するため、Ingressを利用するケースがあるだろう

ただし、Ingressで定義できるのはホスト名、pathベースのルーティングくらいで、URL pathの書き換えとか、namespaceを跨いだ転送ができない

そこで、Nginx Ingress Controller の Custom Resource Definition (以降、CRD)を利用して、そういったnamespace転送やアドレス制限、外部認証など、NGINXでお馴染みの機能が利用することができる

CRDとしては VirtualServer、VirtualServerRouteが利用される

VirtualServerは冒頭のIngressの代わりとなる

VirtualServerRouteはNGINXの機能となるnamespace転送やRate制限などが可能となる

manifestとしては以下のようなイメージとなる


apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: example-virtual-server
namespace: nginx-ingress
spec:
host: example.com
tls:
secret: example-tls-secret
routes:
– path: /app1
route: namespaceA/app1-route
– path: /app2
route: namespaceB/app2-route


-> path /app1 には app1-route serviceに、/app2には app2-route service にトラフィックを流す


kind: VirtualServerRoute
metadata:
name: app1-route
namespace: namespaceA
spec:
host: example.com
upstreams:
– name: app1-upstream
service: app1-service
port: 80
subroutes:
– path: /
action:
pass: app1-upstream

apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: app2-route
namespace: namesapceB
spec:
host: example.com
upstreams:
– name: app2-upstream
service: app2-service
port: 80
subroutes:
– path: /
action:
pass: app2-upstream


-> namespaceごとに virtualserverrouteを作成する。トラフィックを捌くapp podに対応するsvcを記載する

とてもシンプル

The following two tabs change content below.

大関 研丞

インフラ周りを担当するITエンジニアです。 経験はオンプレ5年、クラウド7年ほど python, go などで簡単な運用ツールも作成してます

この記事をシェアする

  • Twitterでシェア
  • Facebookでシェア
  • LINEでシェア