LoginSignup
6
4

More than 5 years have passed since last update.

ALBでEC2を利用しBlue Green Deployを試してみる

Last updated at Posted at 2016-11-11

AWSのApplication Load Balancer(ALB)を用いて、Blue Green Deployを試してみる
アプリケーションはEC2(docker/dockerhub)に配置する。

手順は以下
0. ALBとEC2のセットアップ
1. リリース版デプロイ
2. リリース版の稼働確認
3. ALBに新規に構築したインスタンスに付け替える
4. 旧環境を破棄します。

概要フロー

0. 切り替え前の状態

ALBとEC2のみの単純な構成を用意します。

1.png

1. リリース版をデプロイ

リリース版のデプロイ。
今回は、EC2にdockerでデプロイします。
※EC2にはセキュリティグループでIPフィルタを設定します。

2.png

2. リリース版の稼働確認

3.png

3. ALBにリリース版を付け替え

4.png

4. 旧稼働系を破棄

稼働確認取れたのち、旧稼働系を破棄します。

5.png

0. ALBとEC2のセットアップ

前提条件として、稼働系環境を用意します。

  • EC2(Amazon Linux)を以下手順でセットアップ
$ yum install -y docker
$ service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:    .                                  [  OK  ]
$ docker run -d -p 80:80 mirrored1976/demo-ver1
Unable to find image 'mirrored1976/demo-ver1:latest' locally
latest: Pulling from mirrored1976/demo-ver1
386a066cd84a: Pull complete
a11d6b8e2fac: Pull complete
c1fdc7beec37: Pull complete
bd14a67deca2: Pull complete
92b34ad02810: Pull complete
d724f4fd3384: Pull complete
38659aeb166c: Pull complete
Digest: sha256:127cbd88db7f84f0762e75dafde4498e9d055ce7501f2b9c76af8ccfda53273a
Status: Downloaded newer image for mirrored1976/demo-ver1:latest
139ffe0a233c4b3be7363638fe9ae046cebc279e97493842d51656697f4a8651
  • ALBのセットアップ

公式を参考にしてポチポチ作成します。
Targetに上で作成したインスタンスを紐付けます。

1. リリース版のデプロイ

EC2(Amazon Linux)の起動は割愛します。
EC2に以下手順でデプロイ。

$ yum install -y docker
$ service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:    .                                  [  OK  ]
$ docker run -d -p 80:80 mirrored1976/demo-ver2
Unable to find image 'mirrored1976/demo-ver2:latest' locally
latest: Pulling from mirrored1976/demo-ver2
386a066cd84a: Pull complete
a11d6b8e2fac: Pull complete
c1fdc7beec37: Pull complete
bd14a67deca2: Pull complete
92b34ad02810: Pull complete
85ce4a6f05c1: Pull complete
7b537dad97cd: Pull complete
Digest: sha256:4d200131e18991d2227488cc34b1c6047cb22195cdad59b99989239f24d81e2f
Status: Downloaded newer image for mirrored1976/demo-ver2:latest
267bc2ce4d4f074a012b65915ff22f33a5b0f2e345c83e56be4197bf82eb9529

2. リリース版の稼働確認

リリース版の稼働確認を実施。

3. ALBに新規に構築したインスタンスに付け替える

新旧のインスタンスを付け替える。
※瞬断なしでデプロイしたい場合は、カナリアデプロイ(新を追加保存→旧環境を除く保存)する。

6.png

4. 旧環境の破棄

旧環境のEC2を削除します。

最後に

ALBのターゲットグループでBlue Green Deployがより容易になりました。
アプリ構成的に可能であれば、積極的に利用すべきですね。

6
4
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
6
4