7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Helmを使ってEKS上にWordPressをデプロイする

Last updated at Posted at 2019-04-11

TL;DR

$ eksctl create cluster --name wordpress --region ap-northeast-1
$ kubectl apply -f https://git.io/Jembo
$ helm init --service-account tiller --upgrade
$ helm install stable/wordpress --namespace wordpress-namespace

説明

EKSクラスタの用意

WordPressをデプロイするためのクラスタを作成します。Amazon EKS の使用開始を読んで手作業で作っていってもいいのですが、やること多くてめんどくさいです。eksctlを使うと1コマンドで作ることができます。

$ eksctl create cluster --name wordpress --region ap-northeast-1

(クラスタ作成は20分くらいかかりました)

RBAC設定

Helmはクライアント側とサーバー側(Tiller)から構成されていて、サーバー側で動くTillerはKubernetesAPIにアクセスする必要があるのですが、EKSのデフォルトのRBAC設定ではこれが許可されていません。そのため、適切なアクセス権をTillerに付与してあげる必要があります。

サービスアカウントの作成

"kube-system"というnamespace内に"tiller"というサービスアカウントを作ります。

$ kubectl create serviceaccount tiller --namespace kube-system

今作ったサービスアカウントと"cluster-admin"Roleをバインド

下記のようなtiller-clusterrolebinding.yamlを作って、

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: tiller-clusterrolebinding
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: kube-system
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: ""

"ClusterRoleBinding"をデプロイ

$ kubectl create -f tiller-clusterrolebinding.yaml

Tillerデプロイメントをアップデート

$ helm init --service-acount tiller --upgrade

新しい RBAC Rules をテスト

$ helm ls

エラーがでなければ成功。

Helmを使ってWordPressをデプロイ

これだけ。

$ helm install stable/wordpress --namespace wordpress-namespace

wordpress-namespaceというnamespaceを作成して、その中にデプロイしています。

外部DBを使う

上記のコマンドだと、EKS内にデータベースまで作ってくれますが、データベースだけは外部のものを使いたいこともあると思います。
wordpressチャートはそういった使い方にも対応しています。

今回は、RDSでMariaDBをたてて繋いでみました。

(設定値の例)

  • DBインスタンス識別子: wordpress-db
  • マスターユーザの名前: admin
  • マスターパスワード: hogehogefugafuga
  • セキュリティグループ: eksctl-wordpress-cluster-ClusterSharedNodeSecurityGroup-...
  • データベースの名前: mydb
  • ポート: 3306

データベースインスタンスが完成したら、RDS>データベース>wordpress-sample>接続とセキュリティからエンドポイントを確認してからデプロイ。

$ helm install stable/wordpress --set mariadb.enabled=false,externalDatabase.host=エンドポイント,externalDatabase.user=admin,externalDatabase.database=mydb,externalDatabase.password=hogehogefugafuga --namespace wordpress-namespace

お片付け

今回作成したリソースを全て削除する手順

// リリースを確認
$ helm ls
NAME            REVISION        UPDATED                         STATUS          CHART           APP VERSION     NAMESPACE          
nuanced-boxer   1               Mon Apr 15 13:29:48 2019        DEPLOYED        wordpress-5.7.1 5.1.1           wordpress-namespace

// helmでリリースしたものを削除
$ helm delete --purge nuanced-boxer
release "nuanced-boxer" deleted

(注:削除処理が全て終了するまで1分程度待つ)

// eksctlで作成したクラスタ名を確認
$ eksctl get cluster
NAME            REGION
wordpress       ap-northeast-1

// eksctlで作成されたリソースを削除
$ eksctl delete cluster wordpress
[ℹ]  using region ap-northeast-1
[ℹ]  deleting EKS cluster "wordpress"
[✔]  kubeconfig has been updated
[ℹ]  2 sequential tasks: { delete nodegroup "ng-8114f557", delete cluster control plane "wordpress" [async] }
[ℹ]  will delete stack "eksctl-wordpress-nodegroup-ng-8114f557"
[ℹ]  waiting for stack "eksctl-wordpress-nodegroup-ng-8114f557" to get deleted
[ℹ]  will delete stack "eksctl-wordpress-cluster"
[✔]  all cluster resources were deleted
// データベースを削除
$ aws rds delete-db-instance --db-instance-identifier wordpress-db --skip-final-snapshot --delete-automated-backups

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?