Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Azure Kubernetes Serviceで実現する超低予算&(ほぼ)フルマネージド&本格的なWordPress環境

Azure Kubernetes Serviceで実現する超低予算&(ほぼ)フルマネージド&本格的なWordPress環境

Noriyuki TAKEI

March 25, 2020
Tweet

More Decks by Noriyuki TAKEI

Other Decks in Technology

Transcript

  1. © SIOS Technology, Inc. All rights Reserved. Azure Kubernetes Serviceで実現する

    超低予算 & (ほぼ)フルマネージド & 本格的なWordPress環境 2020年3⽉25⽇ 第26回 Tokyo Jazug Night
  2. © SIOS Technology, Inc. All rights Reserved. About me 2

    Internal Only BCPVUNF Noriyuki TAKEI ෢Ҫ ٓߦ Information • サイオステクノロジー株式会社 • 千葉県在住 Favorites • Azure • Squash • Sweets blog https://tech-lab.sios.jp/ core skill Azure Kubernetes Service Cloud Native, Serverless全般 Twitter @noriyukitakei
  3. © SIOS Technology, Inc. All rights Reserved. WordPress on k8s

    3 Internal Only Azure Kubernetes Serviceとは なんぞやというお話と、 その活⽤⽅法として WordPress(弊社技術ブログ)を AKS上に構築したお話を お届けします。
  4. © SIOS Technology, Inc. All rights Reserved. WordPress on k8s

    4 Internal Only ハッシュタグ #jazug もしくは @noriyukitakei に忌憚ないご意⾒ お願いいたします
  5. © SIOS Technology, Inc. All rights Reserved. WordPress on k8s

    5 Internal Only Internal Only https://tech-lab.sios.jp/archives/18794 今回のセッションのお話は、弊社技術ブログでも ご覧頂けます。
  6. © SIOS Technology, Inc. All rights Reserved. Azure Kubernetes Service

    7 Internal Only Azure Kubernetes Serviceの特徴は以下のとおりです。 Masterサーバー、Nodeサーバーを構築する必要な し。管理も全ておまかせ。 Kubernetes⾃⾝のバージョンアップもGUIで⼀発 あとからNodeの追加も可能 本セッションの ブログのURL
  7. © SIOS Technology, Inc. All rights Reserved. Azure Kubernetes Service

    8 Internal Only GUIでらくらく環境構築︕︕ 本セッションの ブログのURL
  8. © SIOS Technology, Inc. All rights Reserved. Azure Kubernetes Service

    9 Internal Only Kubernetesで実は⼀番⼤変なロギングもすでにサービスが⽤意され ている。 本セッションの ブログのURL
  9. © SIOS Technology, Inc. All rights Reserved. Azure Kubernetes Service

    10 Internal Only もし、負荷が増⼤しNodeの追加が必要になったときでも、簡単に増 減が可能。 本セッションの ブログのURL
  10. © SIOS Technology, Inc. All rights Reserved. Azure Kubernetes Service

    11 Internal Only 進化が速いKubernetesのバージョンアップもGUIで⼀発︕︕ 本セッションの ブログのURL
  11. © SIOS Technology, Inc. All rights Reserved. 概要 13 Internal

    Only WordPressの基本的な構成は以下のとおりです。 /var/www/html wp-content index.php ・・・ wp-admin uploads plugins WordPressのコアモジュー ルでユーザーデータは含ま ず、基本的に変更はない。 画像やプラグインなど運⽤ 後に変更のあるファイルが ある。 MySQL Cookie Salt付きCookieです。 セッションは使っていない ので、サーバー側はステー トです。
  12. © SIOS Technology, Inc. All rights Reserved. 概要 14 Internal

    Only Kubernetes移⾏前の構成です。 /var/www/html wp-content index.php ・・・ wp-admin uploads plugins Virtual Machine MySQL https://tech-lab.sios.jp/ /var/www/html wp-content index.php ・・・ wp-admin uploads plugins Virtual Machine MySQL https://azure.sios.jp/ 本セッションの ブログのURL
  13. © SIOS Technology, Inc. All rights Reserved. 概要 15 Internal

    Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング Dockerイメージをpull メールを送信 画像などの コンテンツを マウント tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーのアクセス L7でWordPressのPodにロードバランシング 投稿情報などの データを参照 Kubernetes移⾏後の構成です。
  14. © SIOS Technology, Inc. All rights Reserved. 概要 16 Internal

    Only 基本構成は以下のとおりです。 2つのブログを4ノードのクラスターで運⽤している。 低性能で安価のVMにて静的なHTMLを処理、⾼性能で⾼価なVMでPHP やDBアクセスなど負荷の⾼い処理を実現している。 低性能で安価なVM、⾼性能で⾼価なVMへのリクエストの振り分けは NGINX Ingressにて実現している。 データベース、メール送信サービス、リポジトリサービスなど可能な限 りマネージドを利⽤している。 残念ながら共有ストレージのみVMにて運⽤している。 (理由は後述)
  15. © SIOS Technology, Inc. All rights Reserved. フロントエンド⽤Nodeと バックエンド⽤Nodeの振り分け 18

    Internal Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーがtech-lab.sios.jp の管理画⾯にアクセス L7でホスト名tech-lab.sios.jpで、ロケーション が/wp-adminだったものは、tech-lab.sios.jp 管理画⾯Podにリクエストを振る。
  16. © SIOS Technology, Inc. All rights Reserved. フロントエンド⽤Nodeと バックエンド⽤Nodeの振り分け 19

    Internal Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Kubernetes Service PHPの実⾏やDBへのアクセスなど、管理画⾯系の 負荷の⾼い処理はCPU優先VMであるFシリーズの VMにリクエストを振る。 フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod バックエンド⽤ノードプール (インスタンスサイズ:F2s_v2) フロントエンド⽤ノードプール (インスタンスサイズ:B2s) 静的なHTML参照という負荷の低い処理は、性能は 控えめだけど安いVMであるBシリーズのVMにリク エストを振る。
  17. © SIOS Technology, Inc. All rights Reserved. フロントエンド⽤Nodeと バックエンド⽤Nodeの振り分け 20

    Internal Only WordPressの「WP Super Cache」というプラグインを⽤いて、 ⼀度アクセスしたページを静的なHTMLとしてキャッシュしていま す。 本セッションの ブログのURL
  18. © SIOS Technology, Inc. All rights Reserved. フロントエンド⽤Nodeと バックエンド⽤Nodeの振り分け 21

    Internal Only フロントエンド⽤Node × 2 Pod app: techlab-user Label env=user Label Pod app: ossonaz-user Label バックエンド⽤Node × 2 Pod app: techlab-admin Label env=admin Label Pod app: ossonaz-admin Label tech-lab.sios.jp ブログページ⽤ deployment tech-lab.sios.jp ブログページ⽤ ReplicaSets azure.sios.jp ブログページ⽤ deployment azure.sios.jp ブログページ⽤ ReplicaSets tech-lab.sios.jp 管理画⾯⽤ deployment tech-lab.sios.jp 管理画⾯⽤ ReplicaSets azure.sios.jp 管理画⾯⽤ deployment azure.sios.jp 管理画⾯⽤ ReplicaSets ・・・リソース ・・・ラベル azure.sios.jpブログページ⽤Podをenv=userの ラベルが付いたNodeに配置 tech-lab.sios.jp管理画⾯⽤Podをenv=admin のラベルが付いたNodeに配置 azure.sios.jp管理画⾯⽤Podをenv=adminのラ ベルが付いたNodeに配置 tech-lab.sios.jpブログページ⽤Podを env=userのラベルが付いたNodeに配置 システム管理者
  19. © SIOS Technology, Inc. All rights Reserved. フロントエンド⽤Nodeと バックエンド⽤Nodeの振り分け 22

    Internal Only nginx フロントエンド⽤Node × 2 Pod app: techlab-user Label env=user Label Pod app: ossonaz-user Label バックエンド⽤Node × 2 Pod app: techlab-admin Label env=admin Label Pod app: ossonaz-admin Label azure.sios.jp ブログページ⽤ NodePort tech-lab.sios.jp ブログページ⽤ NodePort tech-lab.sios.jp 管理画⾯⽤ NodePort azure.sios.jp 管理画⾯⽤ NodePort ・・・リソース ・・・ラベル アクセス先がhttps://azure.sios.jp/wp-adminの場合 アクセス先がhttps://tech-lab.sios.jp/wp-adminの場合 アクセス先がhttps://azure.sios.jp/wp-admin以外の場合 アクセス先がhttps://tech-lab.sios.jp/wp-admin以外の場合 ユーザー
  20. © SIOS Technology, Inc. All rights Reserved. WordPress on k8s

    23 Internal Only これより 詳細を ご説明します。 本セッションの ブログのURL
  21. © SIOS Technology, Inc. All rights Reserved. Load Balancer周り 25

    Internal Only Azure Kubernetes Serviceとは︖ Masterサーバー、Nodeサーバーを構築する必要なし。管理 も全ておまかせ。 Kubernetes⾃⾝のバージョンアップもGUIで⼀発 あとからNodeの追加も可能 Azureが提供するKubernetesのフルマネージドサービス 本セッションの ブログのURL
  22. © SIOS Technology, Inc. All rights Reserved. 26 Internal Only

    tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング Dockerイメージをpull メールを送信 画像などの コンテンツを マウント tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーのアクセス L7でWordPressのPodにロードバランシング 投稿情報などの データを参照
  23. © SIOS Technology, Inc. All rights Reserved. Load Balancer周り 27

    Internal Only ロードバランサー周りの詳細は以下のとおりです。 NGINX IngressでServiceにリクエストを振っている。 NGINX IngressへのリクエストはパブリックIPアドレスを 割り当てたAzure Load Balancerで⾏っている。 NGINX Ingressで、ホスト名及びロケーションによって リクエストを割り振るPodを定義している。 本セッションの ブログのURL
  24. © SIOS Technology, Inc. All rights Reserved. Load Balancer周り 28

    Internal Only Azure Load Balancer及びNGINX Ingress両⽅とも構築はHelmで ⼀発︕︕ $ helm install stable/nginx-ingress \ --namespace techblog-nginx \ --set controller.replicaCount=2 \ --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \ --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \ --set controller.service.externalTrafficPolicy=Local \ --set controller.service.loadBalancerIP=“[ロードバランサーのPublicIP]" \ --generate-name 本セッションの ブログのURL
  25. © SIOS Technology, Inc. All rights Reserved. Load Balancer周り 29

    Internal Only NGINX Ingressのリソースを作成するマニフェストは以下の通り。 apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: kubernetes.io/ingress.class: nginx name: techblog-ingress-nginx spec: rules: - host: tech-lab.sios.jp http: paths: # SIOS Tech.lab (https://tech-lab.sios.jp/)のブログページ向けのリクエストを # それ⽤に作成したNodePortに振ります。 - path: / backend: serviceName: techlab-user-np servicePort: 80 # SIOS Tech.lab (https://tech-lab.sios.jp/)の管理画⾯向けのリクエストを # それ⽤に作成したNodePortに振ります。 - path: /wp-admin backend: serviceName: techlab-admin-np servicePort: 80 ingress.yml 本セッションの ブログのURL
  26. © SIOS Technology, Inc. All rights Reserved. Load Balancer周り 30

    Internal Only - host: azure.sios.jp http: paths: # OSS on Azure (https://azure.sios.jp/)のブログページ向けのリクエストを # それ⽤に作成したNodePortに振ります。 - path: / backend: serviceName: ossonaz-user-np servicePort: 80 # OSS on Azure (https://azure.sios.jp/)の管理画⾯向けのリクエストを # それ⽤に作成したNodePortに振ります。 - path: /wp-admin backend: serviceName: ossonaz-admin-np servicePort: 80 # SSL終端するための証明書が格納されたSecertを定義します。 # この構成では、ワイルドカード証明書で2つのサイトを同じ証明書で終端しています。 tls: - secretName: siosjp-tls hosts: - tech-lab.sios.jp - azure.sios.jp 〜 前ページからの続き 〜 ingress.yml 本セッションの ブログのURL
  27. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 32 Internal

    Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング Dockerイメージをpull メールを送信 画像などの コンテンツを マウント tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーのアクセス L7でWordPressのPodにロードバランシング 投稿情報などの データを参照
  28. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 33 Internal

    Only WordPressのDocker Imageは、起動時のdocker-entrypoint.sh で、毎回起動時にwp-content配下のプラグインを上書きしてしま うので、そうしないように修正してDockerイメージを作り直して、 Azure Container Registryにpushする。 sourceTarArgs=( --create --file - --directory /usr/src/wordpress --owner "$user" --group "$group" ) targetTarArgs=( --extract --file - ) if [ "$user" != '0' ]; then # avoid "tar: .: Cannot utime: Operation not permitted" and "tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted" targetTarArgs+=( --no-overwrite-dir ) fi # これを追加してwp-contentを削除して上書きされるのを防ぐ rm -rf /usr/src/wordpress/wp-content tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}" docker-entrypoint.sh
  29. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 34 Internal

    Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング Dockerイメージをpull メールを送信 画像などの コンテンツを マウント tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーのアクセス L7でWordPressのPodにロードバランシング 投稿情報などの データを参照
  30. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 35 Internal

    Only ここからは各Podを⽣成するためのdeployment.yamlを説明しま すが、その前にWordPressでRollingUpdateを⾏うための⼿法につ いて説明します。 terminationGracePeriodSeconds (40秒) preStop sleep 3 apachectl –k graceful-stop sleep 30 SIGTERM SIGKILL サービス 除外 ユーザーの接続 ユーザーの接続 サービスからPodを切り離す処理と preStopは⾮同期で⾏われるため、サー ビス除外が終わってからpreStopが始ま るようにする。 SIGTERMだとApacheはユーザーのリ クエストをブッツリ切ってしまうので、 SIGTERMが送られる前にpreStopで Graceful Shutdownする。
  31. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 36 Internal

    Only ここからは各Podを⽣成するためのdeployment.yamlを説明しま す。 apiVersion: apps/v1beta1 kind: Deployment metadata: name: techlab-user spec: replicas: 2 selector: matchLabels: app: techlab-user # ローリングアップデートする際、次のPodの更新に移るまでの間隔を指定する。 minReadySeconds: 60 # デプロイのタイムアウトで、この時間過ぎてもデプロイが成功しなければ中⽌する。 progressDeadlineSeconds: 600 strategy: # RollingUpdateするための設定。最⼤1個のPodの増加まで許容する形でRollingUpdateを⾏う。 type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 deployment.yml
  32. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 37 Internal

    Only template: metadata: labels: app: techlab-user spec: # preStop + SIGTERM送信が終わるまでの時間を指定する。 terminationGracePeriodSeconds: 40 containers: - name: wordpress # 先程Azure Container RegistryにプッシュしたWordPressのイメージを指定する。 image: XXXXXX.azurecr.io/techblog/wordpress:php7.4 ports: - containerPort: 80 〜 前ページからの続き 〜 deployment.yml 本セッションの ブログのURL
  33. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 38 Internal

    Only env: - name: WORDPRESS_DB_HOST value: "XXXXXX.mysql.database.azure.com" - name: WORDPRESS_DB_USER value: "siosadmin@techblog-db" # Secretリソースに登録したデータベースのパスワードを環境変数に格納する。 - name: WORDPRESS_DB_PASSWORD valueFrom: secretKeyRef: name: techblog-secret key: WORDPRESS_DB_PASSWORD - name: WORDPRESS_DB_NAME value: "techlab" # Secretリソースに登録したSALT値等をを環境変数に格納する。以下すべて同じ。 - name: WORDPRESS_AUTH_KEY valueFrom: secretKeyRef: name: techblog-secret key: WORDPRESS_AUTH_KEY ・・・以降かなりの数の環境変数の格納が続くので割愛・・・ 〜 前ページからの続き 〜 deployment.yml 本セッションの ブログのURL
  34. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 39 Internal

    Only lifecycle: preStop: exec: # https://tech-lab.sios.jp/archives/18730を参照 # 確実にRollingUpdateを⾏うためにApacheをGracefulにShutdownする。 command: ["sh", "-c", "sleep 3; apachectl -k graceful-stop; sleep 30"] 〜 前ページからの続き 〜 deployment.yml 本セッションの ブログのURL
  35. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 40 Internal

    Only # ヘルスチェック⽤の定義をする。 livenessProbe: httpGet: # ⾃前で作成したヘルスチェック⽤のPHPを指定する。 # ※MySQLに簡単なクエリを投げるスクリプトですが、後ほど詳細をご説明します。 path: /wp-content/healthcheck.php port: 80 scheme: HTTP # 何故かMySQLへのSSL接続が安定するまで時間かかるので、 # ヘルスチェック開始を4分ほど遅らせる。 initialDelaySeconds: 240 timeoutSeconds: 5 periodSeconds: 10 failureThreshold: 5 〜 前ページからの続き 〜 deployment.yml 本セッションの ブログのURL
  36. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 41 Internal

    Only # Podがサービスインする準備ができているかどうかをチェックする。 readinessProbe: httpGet: # ⾃前で作成したヘルスチェック⽤のPHPを指定する。 # ※MySQLに簡単なクエリを投げるスクリプトですが、後ほど詳細をご説明します。 path: /wp-content/healthcheck.php port: 80 scheme: HTTP # 何故かMySQLへのSSL接続が安定するまで時間かかるので、 # ヘルスチェック開始を4分ほど遅らせる。 initialDelaySeconds: 240 timeoutSeconds: 5 periodSeconds: 10 failureThreshold: 5 〜 前ページからの続き 〜 deployment.yml
  37. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 42 Internal

    Only resources: limits: memory: "500Mi" requests: memory: "500Mi" # NFS Serverで作成したボリュームをマウントする。 volumeMounts: - name: techblog-vlm mountPath: /var/www/html/wp-content # subPathを切って、NFS Serverのボリューム上に作成された # techlabディレクトリをマウントする。(NFS Serverの詳細は後ほど、、、) subPath: techlab 〜 前ページからの続き 〜 deployment.yml 本セッションの ブログのURL
  38. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 43 Internal

    Only # env=userというラベルが付与されたNode(フロントエンド⽤Node)に # Podをスケジューリングする。 affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: env operator: In values: - user 〜 前ページからの続き 〜 deployment.yml 本セッションの ブログのURL
  39. © SIOS Technology, Inc. All rights Reserved. Pod⽣成周り 44 Internal

    Only Podのヘルスチェックスクリプトです。MySQLへの接続も含めて 確認をします。 <?php require_once('/var/www/html/wp-load.phpʼ); # DB接続⽤インスタンスを格納しているグローバル変数 global $wpdb; # 超簡単なSQLを発⾏します。 $result = $wpdb->get_col('select 1 as val'); # SQLの結果が無事返ってきたらHTTPステータスコード200、 # そうでない場合は、500を返します。 if ($result[0] == 1) { http_response_code(200); } else { http_response_code(500); } ?> healthcheck.php 本セッションの ブログのURL
  40. © SIOS Technology, Inc. All rights Reserved. データベース周り 46 Internal

    Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング Dockerイメージをpull メールを送信 画像などの コンテンツを マウント tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーのアクセス L7でWordPressのPodにロードバランシング 投稿情報などの データを参照
  41. © SIOS Technology, Inc. All rights Reserved. データベース周り 47 Internal

    Only AzureのMySQLマネージドサービス「Azure Database for MySQL」を利⽤します。 tech-lab.sios.jp ブログページ Pod tech-lab.sios.jp 管理画⾯ Pod azure.sios.jp ブログページ Pod azure.sios.jp 管理画⾯ Pod アクセス Azure Database for MySQL techlab ossonaz アクセス アクセス アクセス 本セッションの ブログのURL
  42. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 49 Internal

    Only tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress Pod Pod tech-lab.sios.jp ブログページ azure.sios.jp ブログページ NGINX Ingress バックエンド⽤Node バックエンド⽤Node Azure Load Balancer Azure Container Registry Azure Database for MySQL SendGrid NFS Server on VM tech-lab.sios.jp⽤ コンテンツ azure.sios.jp⽤ コンテンツ Azure Kubernetes Service L4でNGINX IngressのPodにロードバランシング Dockerイメージをpull メールを送信 画像などの コンテンツを マウント tech-lab.sios.jp⽤ データベース azure.sios.jp⽤ データベース フロントエンド⽤Node フロントエンド⽤Node Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod tech-lab.sios.jp 管理画⾯ azure.sios.jp 管理画⾯ Pod ユーザーのアクセス L7でWordPressのPodにロードバランシング 投稿情報などの データを参照
  43. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 50 Internal

    Only ⼀番苦労しました。 本セッションの ブログのURL
  44. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 51 Internal

    Only 今回のストレージ周りの構成は以下のとおりです。 techlab plugins theme ・・・ ossonaz plugins theme ・・・ tech-lab.sios.jp ブログページ /var/www/html/wp-content Pod tech-lab.sios.jp 管理画⾯ /var/www/html/wp-content Pod azure.sios.jp ブログページ /var/www/html/wp-content Pod azure.sios.jp 管理画⾯ /var/www/html/wp-content Pod マウント マウント マウント マウント 共有ストレージ
  45. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 52 Internal

    Only AzureにはKubernetesから利⽤できる3つの共有ストレージがあり ます。 Azure FilesというSMBベースの マネージドサービス Azure NetApp FilesというNFSベースの マネージドサービス VM上にNFS Serverを インストールしたもの 本セッションの ブログのURL
  46. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 53 Internal

    Only Azure FilesというSMBベースの マネージドサービス Azure NetApp FilesというNFSベースの マネージドサービス VM上にNFS Serverを インストールしたもの Azure Filesを選択しました。 本セッションの ブログのURL
  47. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 54 Internal

    Only 激オソ。 1ページあたり8秒程度の レスポンス 本セッションの ブログのURL
  48. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 56 Internal

    Only <?php require_once('/var/www/html/wp-load.phpʼ); # DB接続⽤インスタンスを格納しているグローバル変数 global $wpdb; # 超簡単なSQLを発⾏します。 $result = $wpdb->get_col('select 1 as val'); # SQLの結果が無事返ってきたらHTTPステータスコード200、 # そうでない場合は、500を返します。 if ($result[0] == 1) { http_response_code(200); } else { http_response_code(500); } ?> healthcheck.php 単純なDBアクセススクリプト動かしたけど問題なし。 本セッションの ブログのURL
  49. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 57 Internal

    Only プロファイラ(Blackfire) 使おう︕︕ 本セッションの ブログのURL
  50. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 58 Internal

    Only エラーで 動かない 本セッションの ブログのURL
  51. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 59 Internal

    Only Print debug しよう 本セッションの ブログのURL
  52. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 60 Internal

    Only error_log(“hoge1”); // Turn register_globals off. wp_unregister_GLOBALS(); error_log(“hoge2”); // Standardize $_SERVER variables across setups. wp_fix_server_vars(); error_log(“hoge3”); // Check if we have received a request due to missing favicon.ico wp_favicon_request(); error_log(“hoge4”); // Check if we're in maintenance mode. wp_maintenance(); error_log(“hoge5”); // Start loading timer. timer_start(); error_log(“hoge6”); // Check if we're in WP_DEBUG mode. wp_debug_mode(); error_log(“hoge7”); if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) { error_log(“hoge8”); include( WP_CONTENT_DIR . '/advanced-cache.php' ); error_log(“hoge9”); if ( $wp_filter ) { $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); } 本セッションの ブログのURL
  53. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 61 Internal

    Only error_log(“hoge10”); foreach ( wp_get_mu_plugins() as $mu_plugin ) { error_log(“hoge11”); include_once( $mu_plugin ); error_log(“hoge12”); do_action( 'mu_plugin_loaded', $mu_plugin ); error_log(“hoge13”); } error_log(“hoge14”); unset( $mu_plugin ); error_log(“hoge14”); if ( is_multisite() ) { error_log(“hoge15”); foreach ( wp_get_active_network_plugins() as $network_plugin ) { error_log(“hoge16”); wp_register_plugin_realpath( $network_plugin ); error_log(“hoge17”); include_once( $network_plugin ); error_log(“hoge18”); do_action( 'network_plugin_loaded', $network_plugin ); error_log(“hoge19”); } error_log(“hoge20”); unset( $network_plugin ); } 本セッションの ブログのURL
  54. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 62 Internal

    Only do_action( 'muplugins_loaded' ); error_log(“hoge21”); if ( is_multisite() ) { error_log(“hoge22”); ms_cookie_constants(); error_log(“hoge23”); } error_log(“hoge24”); wp_cookie_constants(); error_log(“hoge25”); wp_ssl_constants(); error_log(“hoge26”); require( ABSPATH . WPINC . '/vars.php' ); error_log(“hoge27”); create_initial_taxonomies(); error_log(“hoge28”); create_initial_post_types(); error_log(“hoge29”); wp_start_scraping_edited_file_errors(); error_log(“hoge30”); register_theme_directory( get_theme_root() ); error_log(“hoge31”); if ( ! is_multisite() ) { error_log(“hoge32”); wp_recovery_mode()->initialize(); error_log(“hoge33”); } 本セッションの ブログのURL
  55. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 64 Internal

    Only error_log(“hoge10”); foreach ( wp_get_mu_plugins() as $mu_plugin ) { error_log(“hoge11”); include_once( $mu_plugin ); error_log(“hoge12”); do_action( 'mu_plugin_loaded', $mu_plugin ); error_log(“hoge13”); } error_log(“hoge14”); unset( $mu_plugin ); error_log(“hoge14”); if ( is_multisite() ) { error_log(“hoge15”); foreach ( wp_get_active_network_plugins() as $network_plugin ) { error_log(“hoge16”); wp_register_plugin_realpath( $network_plugin ); error_log(“hoge17”); include_once( $network_plugin ); error_log(“hoge18”); do_action( 'network_plugin_loaded', $network_plugin ); error_log(“hoge19”); } error_log(“hoge20”); unset( $network_plugin ); } ここで処理に異様に時間がか かっていることが発覚。 WordPressのプラグインを読み 取っているだけのところ。⼤量 のPHPファイルをincludeしてい る。
  56. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 65 Internal

    Only SMBがボトルネックに なっているのでは︖ 本セッションの ブログのURL
  57. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 66 Internal

    Only Azure FilesというSMBベースの マネージドサービス Azure NetApp FilesというNFSベースの マネージドサービス VM上にNFS Serverを インストールしたもの Azure NetApp Filesに置き換えました。
  58. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 67 Internal

    Only 解決︕︕ レスポンスが激ハヤに︕︕ 本セッションの ブログのURL
  59. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 68 Internal

    Only リリース前⽇に 問題発覚 本セッションの ブログのURL
  60. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 70 Internal

    Only 焦って夜中にSR あげてしまいました、、、 本セッションの ブログのURL
  61. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 71 Internal

    Only その直後に海外から着信が︕︕(後 で知ったのですが、海外のMSサ ポートからでした。怖くて出られ ませんでした、、、すみません) ※サポート⾔語は⽇本語にしたと 思ったのですが、、、
  62. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 72 Internal

    Only Hello 宜行 武井, Thank you for contacting Microsoft Support. My name is XXX XXX and I am the Microsoft Support Engineer who will be working with you on support request XXXXXXXXXXXXXXXXXX. You can reach me using the contact information in my signature or simply by replying to this email. 〜以下略〜 そして、その直後にサポートの⽅からメール が︕︕なんとありがたい、、、MSのサポート ステキすぎる(T_T)
  63. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 73 Azureサブスクリプション

    NetAppアカウント NetAppアカウント NetAppアカウント 容量プール (最⼩4TiB) ボリューム (最⼩100GiB) 容量プール (最⼩4TiB) 容量プール (最⼩4TiB) ボリューム (最⼩100GiB) ボリューム (最⼩100GiB) Pod Pod Pod Azure Kubernetes Cluster ここに対して課⾦ がされるものかと 思ったら、、、 本セッションの ブログのURL
  64. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 74 Azureサブスクリプション

    NetAppアカウント NetAppアカウント NetAppアカウント 容量プール (最⼩4TiB) ボリューム (最⼩100GiB) 容量プール (最⼩4TiB) 容量プール (最⼩4TiB) ボリューム (最⼩100GiB) ボリューム (最⼩100GiB) Pod Pod Pod Azure Kubernetes Cluster 実はここでした。 本セッションの ブログのURL
  65. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 75 Internal

    Only Azure FilesというSMBベースの マネージドサービス Azure NetApp FilesというNFSベースの マネージドサービス VM上にNFS Serverを インストールしたもの VM上のNFSサーバーに置き換えました。
  66. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 76 Internal

    Only 今度こそ本当に解決︕︕ (価格的な意味でも) 本セッションの ブログのURL
  67. © SIOS Technology, Inc. All rights Reserved. ストレージ周り 77 Internal

    Only ストレージでVM使っ ているので(ほぼ)に なります。。。
  68. © SIOS Technology, Inc. All rights Reserved. 気になるお値段は・・・ 79 Internal

    Only フロントエンド⽤Node 9,076円/⽉ (4,538円/⽉ × 2) バックエンド⽤Node 17,856円/⽉ (8,928円/⽉ × 2) Azure Database for MySQL 4,337円/⽉ NFS Server on VM 4,129円/⽉ 合計 35,398円/⽉ 本セッションの ブログのURL
  69. © SIOS Technology, Inc. All rights Reserved. さいごに 81 ⾊々ありましたが

    無事稼働できて何よりです 本セッションの ブログのURL
  70. © SIOS Technology, Inc. All rights Reserved. さいごに 82 今回の教訓です。

    クラウドサービスの料⾦は注意しないと、 意図しない課⾦がされてしまう、、、 ストレージの選定は⼗分な検証をしましょう 令和になってもプリントデバッグは健在
  71. © SIOS Technology, Inc. All rights Reserved. さいごに 83 Internal

    Only Internal Only https://tech-lab.sios.jp/ そんな苦労して移⾏した弊社技術ブログは、下記URL でお届けしております。⾒てね︕︕
  72. © SIOS Technology, Inc. All rights Reserved. さいごに 84 Internal

    Only Internal Only Japan Azure User Groupは、Azureの ユーザーが積極的に情報を交換しあうス テキなコミュニティです。みなさんも是 ⾮参加して、情報発信してみて下さ い︕︕