Más contenido relacionado La actualidad más candente (20) Similar a Ingress on Azure Kubernetes Service (20) Ingress on Azure Kubernetes Service1. Ingress on Azure Kubernetes Service
Session Affinity問題をテーマに学ぼう
真壁 徹
日本マイクロソフト株式会社
2021/6
9. 実装イメージ (Azure Application Gateway)
コントローラーはKubernetesのPod、データプレーン処理はクラスターの外で動く
Ingress
Controller
App GW
API Server
App GW Ingress
Controller Pod
データプレーン処理は
App GWが行う
Azure API
KubernetesのIngressやService
APIから、ルーティングルール
やEndpoint(PodのIPアドレス)な
どを継続的に取得する
Kubernetes APIから取得
した情報をもとに、App
GWの構成をAzure API経
由で作成、維持する
データプレーンとしての
Serviceは利用せず、App
GWは直接Pod(Endpoint)に
トラフィックを送る
10. [補足] Gateway の足音
Evolving Kubernetes networking with the Gateway API | Kubernetes
コントローラーの多様化による負
の影響が目立ってきた(似て非なる
CRD、annotation頼り とか)
その他の改善を含めた、Gateway
プロジェクトが本格化しつつある
広く普及したIngressがすぐに置き
換わるとは考えにくいが、動向は
要注視
13. 代表的な選択肢
App GW
Pod
Pod
App GW NGINX
Pod
Pod
NGINX
Pod
Pod
案1 App GW Ingress Controller 案2 NGINX Ingress Controller 案3 NGINX Ingress Controller &
App GW Frontend
• データプレーン処理をクラス
ター外にオフロードできる
• 豊富な実績と情報量
• 組み合わせをサポートする製
品、OSSが多い
• 例: Canary release、A/B
Testing、Blue/Green
deploymentを実現する
Flagger
• 案1、2のいいとこどり
• 組織で役割分担がしやすい
• 例: インターネットとの境界
になるApp GWは、ネット
ワークチームが独立して運用
したい
14. Azure 公式ドキュメントでのサンプル
Azure Kubernetes Service (AKS) クラスターのベースライン アーキテクチャ - Azure
Architecture Center | Microsoft Docs
NGINXがtraefikに変わっているが、
案3のパターン
大きな組織で役割分担をしている
場合に好まれるパターン
インターネット側/境界を専門家に
任せることで、AKS担当チームの
リスク軽減だけでなく、自由度や
裁量も増す
18. おすすめしない理由
Kubernetesでは特に
Client
Load Balancer/
Gateway / Proxy
Server side
App Pod
Server side
App Pod
Session
Client
Session
KubernetesのPodは、アプリの更新、リソース不足による排出、ノードメンテナンスなど、様々な
理由で再作成されます
graceful shutdownを実現する仕組みはありますが、そのタイミングでセッション情報をPod外部に
退避させるようなアプリを作れるのであれば、はじめからデータストアに持ったほうがよいです
Server side
App Pod
すぅーっ
わたくし
ドロンさせて
いただきます
Podのヤツ また突然
いなくなったよ…
20. Node
案1 Azure Application Gateway Ingress Controller
Client
Azure Application Gateway
Pod
Pod
Instance
Instance
LB
cookie
Application
Gatewayがセット
したcookieを保持
Node
どのインスタンスで処理さ
れても、cookieで接続バッ
クエンドが分かる
• Application Gatewayはバックエン
ド情報としてPodのIPアドレス
(Endpoint)を持つため、送信先を
判断できる
• バックエンドIPをもとにしたハッ
シュを生成し、cookieとしてレス
ポンスにセット
21. Application Gateway Affinity仕様
公式ドキュメントより
Azure Application Gateway では、ユーザー セッションを維持するた
めに、ゲートウェイで管理される Cookie を使用します。 ユーザーが
最初の要求を Application Gateway に送信すると、セッションの詳細
を含むハッシュ値を使用して、応答にアフィニティ Cookie が設定され
ます。これにより、このアフィニティ Cookie を伝送する後続の要求は、
持続性を維持するために同じバックエンド サーバーにルーティングさ
れるようになります。
Azure Application Gateway の HTTP 設定の構成 | Microsoft Docs
22. apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/cookie-based-affinity: "true"
spec:
rules:
- http:
paths:
- backend:
serviceName: frontend
servicePort: 80
利用方法
Application Gateway で Cookie ベースのアフィニティを有効にする | Microsoft Docs
24. Node
案2 NGINX Ingress Controller
Client
Pod
Pod
Azure LB
cookie
NGINXがセットし
たcookieを保持
Node
どのNGINXで処理されても、
cookieで接続Endpointが分か
る
• NGINX Ingress Controllerは
Endpointとサービス名をもとに
したハッシュを生成し、cookie
とする
NGINX
(+ Controller)
NGINX
(+ Controller)
26. --- create_map generates the node hash table
-- @tparam {[string]=number} nodes A table with the node as a key and its weight as a value.
-- @tparam string salt A salt that will be used to generate salted hash keys.
local function create_map(nodes, salt)
local hash_map = {}
for endpoint, _ in pairs(nodes) do
-- obfuscate the endpoint with a shared key to prevent brute force
-- and rainbow table attacks which could reveal internal endpoints
local key = salt .. endpoint
local hash_key = ngx.md5(key)
hash_map[hash_key] = endpoint
end
return hash_map
end
ハッシュ生成コード
ingress-nginx/nodemap.lua
27. Node
案3 NGINX Ingress Controller & App GW Frontend
Client
Pod
Pod
Azure LB
cookie
NGINXがセットし
たcookieを保持
Node
どの経路を通っても、cookie
で接続Endpointが分かる
• NGINX Ingress ControllerはEndpoint
とサービス名をもとにしたハッシュ
を生成し、cookieとする
NGINX
(+ Controller)
NGINX
(+ Controller)
Azure Application Gateway
Instance
Instance
LB
Service Type
LoadBalancer
• App GWのバックエンドはAzure LB
のフロントエンドIPアドレス(1つ)
であるため、Affinity設定は不要