LoginSignup
3
1

More than 1 year has passed since last update.

RDS Blue/Green デプロイを試してみた

Last updated at Posted at 2023-01-23

RDS Blue/Green デプロイを試してみた

なぜテストするか

  • RDSから除外されるMySQLのバージョンがアナウンスされた
  • バッチリ当てはまるインスタンスがあった
  • 切り替えテストをやっていると、RDSの画面にBlue/Greenデプロイのアナウンスが有ることに気がついた
  • やってみよう

テスト概要

  • db.t3.micro(MySQL5.7.40 → MySQL8.0.31にアップデートする)
  • Blue/Green切り替え前に稼働系に書き込みを行って、待機系に反映されることを確認
  • 実際に切り替えを行う際の挙動を確認(ダウンタイム計測など)

やってみた

  1. 適当にインスタンス作成

    • db.t3.micro
    • MySQL5.7.40
    • マルチAZなし、バックアップ無し
  2. Blue/Greenデプロイ環境の作成
    MySQL8.0.31にアップデートする以外はデフォルトのままで作成
    1.png

  3. 怒られた
    バックアップ取得されていないと、レプリケーションを作成できない模様
    2.png

  4. バックアップ取得するように変更
    3.png

  5. Blue/Greenデプロイ環境の作成(二回目)
    無事成功し、ブルーグリーンデプロイというロールのリソースが作成される
    4.png
    しばし待つと、Green側のインスタンスが勝手に作成される
    7.png

  6. Blue側に書き込みテストしてみる

    creat_database
    $ mysql -uroot -phogehoge -hbgdeploy-test.hogehoge.ap-northeast-1.rds.amazonaws.com
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1916
    Server version: 5.7.40-log Source distribution
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create database bgdeploy1;
    Query OK, 1 row affected (0.01 sec)
    
    mysql> create database bgdeploy2;
    Query OK, 1 row affected (0.01 sec)
    
    mysql> create database bgdeploy3;
    Query OK, 1 row affected (0.01 sec)
    
  7. Green側で同期を確認する
    だいじょうぶそう

    show database
    $ mysql -uroot -phogehoge -hbgdeploy-test-green-0bvg3a.hogehoge.ap-northeast-1.rds.amazonaws.com
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 17
    Server version: 8.0.31 Source distribution
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | bgdeploy1          |
    | bgdeploy2          |
    | bgdeploy3          |
    | dbtest             |
    | information_schema |
    | innodb             |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    9 rows in set (0.01 sec)
    
  8. 切り替えしてみる
    11.png

  9. 切り替え中の挙動をテスト
    毎秒mysqlpingを打って確認すると、以下の時間で疎通が取れなくなった

    • 疎通不能:January 23, 2023, 18:39:22 UTC+9:00
    • 疎通再開:January 23, 2023, 18:39:48 UTC+9:00
      16.png
      17.png
  10. 切り替え後の確認(デプロイ)

    • デプロイロールが切り替え完了となっている
    • 元のインスタンス(Brue側)にold1がついている
    • 新しいインスタンス(Green側)が元のホスト名になっている
      15.png
  11. 切り替え後の確認(DBの中身)
    元のホスト名に接続して、MySQL8.0.31でDatabaseが表示されてる事を確認

    show database(after faiover)
    $ mysql -uroot -phogehoge -hbgdeploy-test.hogehoge.ap-northeast-1.rds.amazonaws.com
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 27
    Server version: 8.0.31 Source distribution
    
    Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | bgdeploy1          |
    | bgdeploy2          |
    | bgdeploy3          |
    | dbtest             |
    | information_schema |
    | innodb             |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    9 rows in set (0.00 sec)
    
  12. おそうじ

    • 以下の2つを削除する
      1. bgdeploy-test-green(デプロイロール)
      2. bgdeploy-test-old1(元あったインスタンス)

    18.png

  13. 終了


所感

  1. メリット
    1. かなりダウンタイムが短くなる(通常2~5分かかるところが数十秒)
    2. 事前にGreen側で動作確認ができる
    3. 同期は問題なくおこなわれている
  2. デメリット
    1. テスト中は二倍+αのコストがかかる
    2. DB切り替わりの際にセッションがはられていると、タイムアウトしてしまう
  3. まとめ
    1. なかなかの神機能なのでは?
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1