2019年7月1日月曜日

k8s for GCP (wordpressデプロイ)

[目的]
raspberry piでのk8sをメインで検証してきたので、GCPで検証してみる。

今回、自宅のMac経由で、GCPで接続して、kubernetesでwordpressをデプロイしてみる。
(gcloudコマンドなどのインストールや初期設定については割愛。)


[手順]
1)wordpressのマニフェストのサンプルをダウンロードする。
git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples
cd kubernetes-engine-samples/wordpress-persistent-disks


2)永続ディスクのコンテナの作成を行う。(ノードを2つ)
gcloud container clusters create persistent-disk-tutorial --num-nodes=2
==================================================================================================
WARNING: In June 2019, node auto-upgrade will be enabled by default for newly created clusters and node pools. To disable it, use the `--no-enable-autoupgrade` flag.
WARNING: Starting in 1.12, new clusters will have basic authentication disabled by default. Basic authentication can be enabled (or disabled) manually using the `--[no-]enable-basic-auth` flag.
WARNING: Starting in 1.12, new clusters will not have a client certificate issued. You can manually enable (or disable) the issuance of the client certificate using the `--[no-]issue-client-certificate` flag.
WARNING: Starting in 1.12, default node pools in new clusters will have their legacy Compute Engine instance metadata endpoints disabled by default. To create a cluster with legacy instance metadata endpoints disabled in the default node pool, run `clusters create` with the flag `--metadata disable-legacy-endpoints=true`.
WARNING: The Pod address range limits the maximum size of the cluster. Please refer to https://cloud.google.com/kubernetes-engine/docs/how-to/flexible-pod-cidr to learn how to optimize IP address allocation.
This will enable the autorepair feature for nodes. Please see https://cloud.google.com/kubernetes-engine/docs/node-auto-repair for more information on node autorepairs.
Creating cluster persistent-disk-tutorial in asia-northeast1-b... Cluster is being health-checked...  
NAME                      LOCATION           MASTER_VERSION  MASTER_IP       MACHINE_TYPE   NODE_VERSION   NUM_NODES  STATUS
persistent-disk-tutorial  asia-northeast1-b  1.12.8-gke.10   104.198.89.185  n1-standard-1  1.12.8-gke.10  2          RUNNING
=================================================================================================


3)ノードが生成されているの確認を行ってみる。
kubectl get node
=========================================================================
NAME                                                  STATUS   ROLES    AGE   VERSION
gke-persistent-disk-tuto-default-pool-aafc462d-3l7h   Ready    <none>   19s   v1.12.8-gke.10
gke-persistent-disk-tuto-default-pool-aafc462d-pzjp   Ready    <none>   20s   v1.12.8-gke.10
========================================================================

4)早速、mysqlwordpressの永続ディスクのマニュフェストを実施する。
kubectl apply -f mysql-volumeclaim.yaml
kubectl apply -f wordpress-volumeclaim.yaml


5)ディスクが作成できたのか確認を行ってみる。
kubectl get pvc
==========================================================================
NAME                    STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mysql-volumeclaim       Bound    pvc-2433e9f5-9c06-11e9-ae37-42010a920050   200Gi      RWO            standard       37s
wordpress-volumeclaim   Bound    pvc-28e681c6-9c06-11e9-ae37-42010a920050   200Gi      RWO            standard       29s
============================================================================


6)MySQL用のシークレットの作成を行う。
kubectl create secret generic mysql --from-literal=password=********


7)MySQLのマニュフェストを実行する。
kubectl create -f mysql.yaml


8)MySQLのサービスの作成する。
kubectl create -f mysql-service.yaml


9)サービスが作成できたか確認してみる。
kubectl get svc
================================================================
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.0.16.1    <none>        443/TCP    12m
mysql        ClusterIP   10.0.24.72   <none>        3306/TCP   6s
==================================================================



10)Wordpressのマニュフェストの実行する
kubectl create -f wordpress.yaml


11)mysqlwordpresspodが作成できたか確認してみる。
kubectl get pod -o wide
===============================================================================================
NAME                         READY   STATUS    RESTARTS   AGE     IP          NODE                                                  NOMINATED NODE
mysql-5b9b49cf46-vf8qk       1/1     Running   0          4m42s   10.60.0.9   gke-persistent-disk-tuto-default-pool-aafc462d-pzjp   <none>
wordpress-74c847b8cd-s8xgp   1/1     Running   0          62s     10.60.1.5   gke-persistent-disk-tuto-default-pool-aafc462d-3l7h   <none>
===============================================================================================

12)MySQLのサービスのマニュフェストの実施する。
kubectl create -f wordpress-service.yaml


13)サービスの確認をすると、成功しているようだ。
kubectl get svc
==============================================================================
NAME         TYPE           CLUSTER-IP    EXTERNAL-IP    PORT(S)        AGE
kubernetes   ClusterIP      10.0.16.1     <none>         443/TCP        22m
mysql        ClusterIP      10.0.24.72    <none>         3306/TCP       11m
wordpress    LoadBalancer   10.0.18.170   ************   80:32729/TCP   5m45s
================================================================================

14)早速、接続をしてみる。
http://***********/wp-admin/install.php





15)初期設定方法については割愛。




16)GCP側でも確認してみる。













0 件のコメント:

コメントを投稿

memo

  1)RDS に接続してみる 2)ドライバーを環境変数で定義してみる 以下、dockerfileに記載 ———————— # /bin/shを/bin/sh_tmpにリネーム > 同時に/bin/shに対して/bin/bashへのシンボリックリンクを作成 R...