Canary パブリッシングに nginx シミュレーションを使用する方法

王林
リリース: 2023-05-15 11:25:05
転載
851 人が閲覧しました

カナリア リリース/グレースケール リリース

カナリア リリースの焦点は、試行錯誤です。カナリアの放鳥自体の起源は、人間の産業の発展における美しい自然の生き物たちの悲劇的な物語です。カナリアは、鉱山労働者の安全のために自らの命をかけて試行錯誤します。全体的なセキュリティのための交換には、少額のコストが使用されます。継続的デプロイメントの実践では、カナリアはトラフィック制御です。1 パーセントや 10 分の 1 などの非常に少量のトラフィックが、特定のバージョンが正常かどうかを確認するために使用されます。異常であれば、その機能は最小限のコストで達成され、リスクは軽減されます。正常であれば、100% に達するまで徐々に重みを増やし、すべてのトラフィックを新しいバージョンにスムーズに切り替えることができます。グレースケール パブリッシングも一般に同様の概念です。グレーは黒と白の間の移行です。青か緑のどちらかであるブルー アンド グリーン デプロイメントとは異なります。グレースケール リリース/カナリア リリースには両方が同時に存在する期間がありますが、この 2 つの対応するトラフィックはカナリア リリースとグレースケール リリースが異なる場合、その違いが目的である必要があります。カナリア リリースの目的は試行錯誤ですが、グレースケール リリースは安定リリースについてであり、カナリア リリースには問題はありません。スムーズな移行です。グレースケール出版の状況下で。

カナリア リリースのシミュレーション

次に、nginx のアップストリームを使用して、カナリア リリース シナリオを単純にシミュレートします。具体的なシナリオとしては、現在メインバージョンがアクティブになっており、nginx の設定を調整し、常に Canary バージョンのウェイトを調整することで、最終的にスムーズなリリースが実現されます。

Canary パブリッシングに nginx シミュレーションを使用する方法

#事前準備

2 つのポート 7001/7002 で 2 つのサービスを事前に起動し、異なる情報を表示します。便利です tornadoを使って画像を作成しました Dockerコンテナ起動時に渡される各種パラメータはサービスの違いを表示するために使用されます。

docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello main service: v1 in 7001"
docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello canary deploy service: v2 in 7002"
ログイン後にコピー

実行ログ

[root@kong ~]# docker run -d -p 7001:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello main service: v1 in 7001"
28f42bbd21146c520b05ff2226514e62445b4cdd5d82f372b3791fdd47cd602a
[root@kong ~]# docker run -d -p 7002:8080 liumiaocn/tornado:latest python /usr/local/bin/daemon.py "hello canary deploy service: v2 in 7002"
b86c4b83048d782fadc3edbacc19b73af20dc87f5f4cf37cf348d17c45f0215d
[root@kong ~]# curl http://192.168.163.117:7001
hello, service :hello main service: v1 in 7001
[root@kong ~]# curl http://192.168.163.117:7002
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#
ログイン後にコピー

nginxの開始

[root@kong ~]# docker run -p 9080:80 --name nginx-canary -d nginx
659f15c4d006df6fcd1fab1efe39e25a85c31f3cab1cda67838ddd282669195c
[root@kong ~]# docker ps |grep nginx-canary
659f15c4d006    nginx           "nginx -g 'daemon ..."  7 seconds ago    up 7 seconds    0.0.0.0:9080->80/tcp   nginx-canary
[root@kong ~]#
ログイン後にコピー

nginxコードセグメント

以下の nginx コード スニペットを用意し、nginx の /etc/nginx/conf.d/default.conf に追加します。シミュレーション方法は非常に簡単です。トラフィックがゼロであることを示すには、down を使用します (重みをゼロに設定することはできません)。 nginx 内) 最初は、トラフィックの 100% がメイン バージョンに送信されます。

http {
upstream nginx_canary {
  server 192.168.163.117:7001 weight=100;
  server 192.168.163.117:7002 down;
}
server {
  listen    80;
  server_name www.liumiao.cn 192.168.163.117;
  location / {
    proxy_pass http://nginx_canary;
  }
}
ログイン後にコピー

default.conf を変更する方法

vim をコンテナにインストールすることで効果を実現できます。また、ローカルで変更して docker cp 経由で渡すこともできます。 、または直接 sed 変更が可能です。 vim をコンテナにインストールする場合は、次の方法を使用します。

[root@kong ~]# docker exec -it nginx-lb sh
# apt-get update
...省略
# apt-get install vim
...省略
ログイン後にコピー

変更前

# cat default.conf
server {
  listen    80;
  server_name localhost;
  #charset koi8-r;
  #access_log /var/log/nginx/host.access.log main;
  location / {
    root  /usr/share/nginx/html;
    index index.html index.htm;
  }
  #error_page 404       /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  /usr/share/nginx/html;
  }
  # proxy the php scripts to apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #  proxy_pass  http://127.0.0.1;
  #}
  # pass the php scripts to fastcgi server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  #  root      html;
  #  fastcgi_pass  127.0.0.1:9000;
  #  fastcgi_index index.php;
  #  fastcgi_param script_filename /scripts$fastcgi_script_name;
  #  include    fastcgi_params;
  #}
  # deny access to .htaccess files, if apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #  deny all;
  #}
}
#
ログイン後にコピー

変更後

# cat default.conf
upstream nginx_canary {
  server 192.168.163.117:7001 weight=100;
  server 192.168.163.117:7002 down;
}
server {
  listen    80;
  server_name www.liumiao.cn 192.168.163.117;
  #charset koi8-r;
  #access_log /var/log/nginx/host.access.log main;
  location / {
    #root  /usr/share/nginx/html;
    #index index.html index.htm;
    proxy_pass http://nginx_canary;
  }
  #error_page 404       /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  /usr/share/nginx/html;
  }
  # proxy the php scripts to apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #  proxy_pass  http://127.0.0.1;
  #}
  # pass the php scripts to fastcgi server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  #  root      html;
  #  fastcgi_pass  127.0.0.1:9000;
  #  fastcgi_index index.php;
  #  fastcgi_param script_filename /scripts$fastcgi_script_name;
  #  include    fastcgi_params;
  #}
  # deny access to .htaccess files, if apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #  deny all;
  #}
}
#
ログイン後にコピー

nginx 設定をリロードします

# nginx -s reload
2018/05/28 05:16:20 [notice] 319#319: signal process started
#
ログイン後にコピー

#結果を確認します

##10 回の呼び出しすべての出力は 7001 の v1 です

[ root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; docurl ; let cnt ; 完了

hello, サービス :hello メイン サービス: v1 in 7001

hello, サービス :hello メイン サービス: v1 in 7001
hello, サービス :hello メイン サービス: v1 in 7001

hello, サービス :hello メイン サービス: v1 in 7001
hello, サービス :hello メイン サービス: v1 in 7001
hello 、サービス :hello メイン サービス: 7001 の v1
hello、サービス :hello メイン サービス: 7001 の v1
hello、サービス :hello メイン サービス: 7001 の v1
hello、サービス :hello メイン サービス : v1 in 7001
hello, service :hello main service: v1 in 7001
[root@kong ~]



# カナリア リリース: カナリア バージョン トラフィックの重み 10%

##default.conf の重みを調整してから nginx -s reload を実行することで、カナリア バージョンの重みを 10% に調整すると、トラフィックの 10% が新しいサービスを実行します

default.conf を変更する方法

次のようにアップストリームのサーバーの重みを調整するだけです:

upstream nginx_canary {
  server 192.168.163.117:7001 weight=10;
  server 192.168.163.117:7002 weight=90;
}
ログイン後にコピー
ログイン後にコピー
nginx 設定をリロードします決定

# nginx -s reload
2018/05/28 05:20:14 [notice] 330#330: signal process started
#
ログイン後にコピー

結果を確認

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; docurl ; let cnt ; 完了hello、サービス :hello カナリア デプロイ サービス: 7002 年の v2 hello、サービス :hello カナリア デプロイ サービス: 7002 の v2

hello、サービス :hello カナリア デプロイ サービス: 7002 の v2
こんにちは、サービス :hello Canary デプロイ サービス: v2 で 7002

hello、サービス :hello メイン サービス: v1 で 7001
hello、サービス :hello Canary デプロイ サービス: v2 で 7002
hello、サービス :hello Canaryデプロイ サービス: v2 で 7002
hello, サービス :hello Canary デプロイ サービス: v2 で 7002
hello, サービス :hello Canary デプロイ サービス: v2 で 7002
hello, サービス :hello Canary デプロイ サービス : v2 で7002
[root@kong ~]



#Canary リリース: Canary バージョンのトラフィックの重み 50%

調整により、default.conf の重み、次に、nginx -s reload を実行し、カナリア バージョンの重みを 50% に調整すると、トラフィックの 50% が新しいサービスを実行します

##default.conf を変更する方法

次のようにアップストリームのサーバーの重みを調整するだけです:

upstream nginx_canary {
  server 192.168.163.117:7001 weight=50;
  server 192.168.163.117:7002 weight=50;
}
ログイン後にコピー

nginx 設定をリロード

# nginx -s reload
2018/05/28 05:22:26 [notice] 339#339: signal process started
#
ログイン後にコピー

确认结果

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

金丝雀发布: 金丝雀版本流量权重90%

通过调整default.conf的weight,然后执行nginx -s reload的方式,调节金丝雀版本的权重为90%,流量的90%会执行新的服务

修改default.conf的方法

只需要将upstream中的server的权重做如下调整:

upstream nginx_canary {
  server 192.168.163.117:7001 weight=10;
  server 192.168.163.117:7002 weight=90;
}
ログイン後にコピー
ログイン後にコピー

重新加载nginx设定

# nginx -s reload
2018/05/28 05:24:29 [notice] 346#346: signal process started
#
ログイン後にコピー

确认结果

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello main service: v1 in 7001
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

金丝雀发布: 金丝雀版本流量权重100%

通过调整default.conf的weight,然后执行nginx -s reload的方式,调节金丝雀版本的权重为100%,流量的100%会执行新的服务

修改default.conf的方法

只需要将upstream中的server的权重做如下调整:

upstream nginx_canary {
  server 192.168.163.117:7001 down;
  server 192.168.163.117:7002 weight=100;
}
ログイン後にコピー

重新加载nginx设定

# nginx -s reload
2018/05/28 05:26:37 [notice] 353#353: signal process started
ログイン後にコピー

确认结果

[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
hello, service :hello canary deploy service: v2 in 7002
[root@kong ~]#

以上がCanary パブリッシングに nginx シミュレーションを使用する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:yisu.com
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!