EKIによるカナリア配備
23988 ワード
カナリア展開はアプリケーションを段階的に展開する方法です.このパターンでは、プロダクションバージョンと一緒にアプリケーションの新しいバージョンを展開し、サーバーの小さなサブセットに変更をロールバックします.
一度アプリケーションの新しいバージョンは、実際のユーザーによってテストされ、ロールアウトのサーバーの残りの部分に変更されます.
カナリア展開は複雑でありえます、そして、生産と手動の検証でテストを含みます.
Canary展開を実証するには、Eksクラスタを設定し、Istioをインストールし、サンプルアプリケーションを配備し、新しいバージョンのアプリケーションのカナリーリリースを設定します.
以下の手順に従ったり、スクリプトを使用したりできますhere .
セットアップのEksクラスタ 最新版のダウンロードとインストール クリエイトeksクラスタ
ダウンロードしてインストール クラスタで実行中のポッドをチェックします.
iStio便利なバイナリを提供して インストール
istioに複数の構成profiles , これらのプロファイルは、ISIOデータプレーンのためのistio制御プレーンおよびサイドカーのカスタマイズを提供する.
Note :以下のエラーを取得する場合は、ノードのインスタンス型に基づいてノードにスケジュールできるPODの数に制限があるため、使用しているインスタンス型をチェックしてください.参照here インスタンス型と最大のPODのリスト.
ISTI注射envoy proxy ポッドへのサイド車コンテナは、ポッドからトラフィックを遮断するために、この動作はラベルを使用して有効になります このラベルを
インストール
カナリー展開がどのように動作するかを示すには、バージョン2.0を設定しましょう 配備する
アプリケーションをサービスとして公開します
NGNXサービスへの接続性をテストするためにテストポッドを設定します.
istioでは、トラフィックのルーティングとレプリカ展開は完全に互いに独立している.イシスrouting rules に基づいてトラフィックをルーティングする方法について細かく制御を提供する 別のバージョンを配備する
Istio Gateway HTTP/TCP接続の着信および発信を受信するロードバランサとして動作し、それは セットアップ
Destination Rule 定義するsubsets ラベルのセットに基づくアプリケーションの.例えば、我々は2つの部分集合を展開しました 目的地を設定する
Virtual Service 侵入リソースとマッチしたトラフィックと同じように動作し、HTTPルーティング規則に基づいてサービスに指示します. これは、外部サービスと同様に内部で動作することができますHTTPホスト、パス(完全な正規表現のサポート)、メソッド、ヘッダー、ポート、クエリパラメータに基づいてトラフィックを一致させることができます.
仮想サービスの設定
生産では、テスト後
一度アプリケーションの新しいバージョンは、実際のユーザーによってテストされ、ロールアウトのサーバーの残りの部分に変更されます.
カナリア展開は複雑でありえます、そして、生産と手動の検証でテストを含みます.
Canary展開を実証するには、Eksクラスタを設定し、Istioをインストールし、サンプルアプリケーションを配備し、新しいバージョンのアプリケーションのカナリーリリースを設定します.
以下の手順に従ったり、スクリプトを使用したりできますhere .
セットアップEKSクラスタ
セットアップのEksクラスタ
1.21
インus-east-1
管理ノードグループを持つ領域default-pool
機械式t3a-medium
. eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
Macと他のオペレーティングシステムのために、ステップhere . eksctl create cluster --name canary-cluster \
--version 1.21 \
--region us-east-1 \
--nodegroup-name default-pool \
--node-type t3a.medium \
--nodes 3 \
--nodes-min 0 \
--nodes-max 4 \
--managed
コントロールプレーンが準備されると、このような出力が表示されるはずです 2021-08-13 23:59:52 [ℹ] waiting for the control plane availability...
2021-08-13 23:59:52 [✔] saved kubeconfig as "/Users/shardulsrivastava/.kube/config"
2021-08-13 23:59:52 [ℹ] no tasks
2021-08-13 23:59:52 [✔] all EKS cluster resources for "canary-cluster" have been created
2021-08-14 00:01:57 [ℹ] kubectl command should work with "/Users/shardulsrivastava/.kube/config", try 'kubectl get nodes'
2021-08-14 00:01:57 [✔] EKS cluster "canary-cluster" in "us-east-1" region is ready
注:あなたは最小限のthese permissions 上記のeksctlコマンドを実行します.kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl get pods -A
この時点でクラスタはcore-dns
, kube-proxy
, and amazon-vpc-cni
プラグイン.セットアップ
iStio便利なバイナリを提供して
istioctl
を設定し、ISIOコンポーネントと対話する.istioctl
EC 2インスタンスからこれらのコマンドを実行している場合、インストールディレクトリをシステムパスに追加します. curl -L https://istio.io/downloadIstio | sh -
export PATH="$PATH:/home/ec2-user/istio-1.11.0/bin"
default
プロファイルは、生産展開を推奨します. istioctl install --set profile=default -y
また、マニフェストのダンプを取ることもできます. istioctl manifest generate --set profile=default > generated-manifest.yaml
kubectl apply -f generated-manifest.yaml
インストールが完了すると、このような出力が正常にインストールされます.Note :以下のエラーを取得する場合は、ノードのインスタンス型に基づいてノードにスケジュールできるPODの数に制限があるため、使用しているインスタンス型をチェックしてください.参照here インスタンス型と最大のPODのリスト.
istio-injection=enabled
名前空間レベルとsidecar.istio.io/inject=true
ポッドレベルで.default
名前空間を自動的にIssuyサイドカープロキシを注入するように指示する名前空間. kubectl label namespace default istio-injection=enabled
istioサイドカー噴射についての続きを読むhere .Kiali
, Prometheus
and Grafana
メッシュを監視し可視化する kubectl apply -f https://raw.githubusercontent.com/istio/istio/1.10.3/samples/addons/prometheus.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/1.10.3/samples/addons/grafana.yaml
kubectl apply -f https://raw.githubusercontent.com/istio/istio/1.10.3/samples/addons/kiali.yaml
注意:このようなエラーが発生した場合unable to recognize "https://raw.githubusercontent.com/istio/istio/1.10.3/samples/addons/kiali.yaml": no matches for kind "MonitoringDashboard" in version "monitoring.kiali.io/v1alpha1"
, コマンドを再実行します. kubectl apply -f https://raw.githubusercontent.com/istio/istio/1.10.3/samples/addons/kiali.yaml
セットアップサンプルアプリケーション
カナリー展開がどのように動作するかを示すには、バージョン2.0を設定しましょう
v1
nginxベースのサンプルアプリケーションのポートで公開するサービスを設定します80
.v1
サンプルアプリケーションの展望: apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-v1
spec:
replicas: 1
selector:
matchLabels:
app: nginx
version: v1
template:
metadata:
labels:
app: nginx
version: v1
spec:
containers:
- image: quay.io/shardul/nginx:v1
name: nginx-v1
imagePullPolicy: Always
ports:
- name: http
containerPort: 80
livenessProbe:
httpGet:
path: /health
port: 80
readinessProbe:
httpGet:
path: /health
port: 80
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx
spec:
ports:
- name: http
port: 80
selector:
app: nginx
kubectl run -it test-connection --image=radial/busyboxplus:curl -- sh
[ root@test-connection:/ ]$ while true; do curl nginx && echo ; done
You're at the root of nginx server v1
You're at the root of nginx server v1
You're at the root of nginx server v1
You're at the root of nginx server v1
Istioによるカナリア配備
istioでは、トラフィックのルーティングとレプリカ展開は完全に互いに独立している.イシスrouting rules に基づいてトラフィックをルーティングする方法について細かく制御を提供する
host
, port
, headers
, uri
, method
, source labels
とトラフィックの分布を制御します.v2
イメージを使用する同じアプリケーションのquay.io/shardul/nginx:v2
. apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-v2
spec:
replicas: 1
selector:
matchLabels:
app: nginx
version: v2
template:
metadata:
labels:
app: nginx
version: v2
spec:
containers:
- image: quay.io/shardul/nginx:v2
name: nginx-v2
imagePullPolicy: Always
ports:
- name: http
containerPort: 80
livenessProbe:
httpGet:
path: /health
port: 80
readinessProbe:
httpGet:
path: /health
port: 80
一度v2
バージョンが配備され、再びサービスをヒットすると、以下の出力が得られます. kubectl exec -it test-connection -- sh
[ root@test-connection:/ ]$ while true; do curl nginx && echo ; done
You're at the root of nginx server v2
You're at the root of nginx server v2
You're at the root of nginx server v1
You're at the root of nginx server v1
You're at the root of nginx server v2
You're at the root of nginx server v1
You're at the root of nginx server v1
You're at the root of nginx server v2
同じサービスから公開された異なるバージョンの2つの展開があるので、サービスをヒットするたびに、それはラウンドロビン方法、したがってこの出力でアプリケーションの異なるバージョンをヒットします.Istio Gateway HTTP/TCP接続の着信および発信を受信するロードバランサとして動作し、それは
istio-ingressgateway
インストール時に作成したリソースLoadBalancer
サービスdefault-gateway
ポート上のすべての着信トラフィック80
: apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: default-gateway
namespace: istio-system
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: http
number: 80
protocol: HTTP
Destination Rule 定義するsubsets ラベルのセットに基づくアプリケーションの.例えば、我々は2つの部分集合を展開しました
v1
and v2
アプリケーションの、そして、それらはラベルによって特定されますversion
. nginx-dest-rule
つのサブセットを定義するにはv1
and v2
: apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: nginx-dest-rule
spec:
host: nginx
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
Virtual Service 侵入リソースとマッチしたトラフィックと同じように動作し、HTTPルーティング規則に基づいてサービスに指示します.
仮想サービスの設定
nginx-virtual-svc
ホスト用nginx
受信したトラフィックを受信するdefault-gateway
そして、部分集合へのトラフィックの90 %を経路v1
と10 %のサブセットv2
で定義nginx-dest-rule
. apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginx-virtual-svc
spec:
hosts:
- nginx
gateways:
- istio-system/default-gateway
http:
- route:
- destination:
host: nginx
subset: v1
weight: 90
- destination:
host: nginx
subset: v2
weight: 10
適用後90%
トラフィックのバージョンはv1
and 10%
to v2
のnginx
サービス経由でNGinXサービスにアクセスistio-ingressgateway
.kubectl exec -it test-connection -- sh
while true; do curl -H "Host: nginx" istio-ingressgateway.istio-system && echo ; done
Kialiダッシュボードを使用してトラフィックフローを視覚化できます.istioctl dashboard kiali
生産では、テスト後
canary version
それがうまく動作していることを確認するために、私たちはVirtualServiceを更新してトラフィックの100 %をこのバージョンにルーティングして、すべてのユーザーのためにより新しいバージョンを出します.Reference
この問題について(EKIによるカナリア配備), 我々は、より多くの情報をここで見つけました https://dev.to/aws-builders/canary-deployment-with-istio-on-eks-2m98テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol