10
7

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.

Docker for Mac with Kubernetes で WordPressを立てる

Last updated at Posted at 2018-01-12

はじめに

Docker for Mac with Kubernetes のBeta版が利用できるようになったようなので、WordPressを立ててみました

使用バージョン

$ docker -v
Docker version 17.12-kube_beta, build ca0c9dbcb219048a1a61fbf82a2e69f1b9795023

手順

Kubernetesをインストールする過程は省略

こちらを参考にしてください:
https://qiita.com/taishin/items/920d62a641c9cd58f289

wordpressを準備する

https://github.com/kubernetes/examples/tree/master/mysql-wordpress-pd の以下のファイルをダウンロード
・ mysql-deployment.yaml
・ wordpress-deployment.yaml

wordpress-deployment.yamlのイメージを最新版に変更

...
    spec:
      containers:
      - image: wordpress:4.9.1-php7.1-apache #変更
...

Kubernetesに設定を反映する

mysqlのパスワードを設定する

kubectl create secret generic mysql-pass --from-literal=password=yourpassword

mysqlを立ち上げる

kubectl apply -f mysql-deployment.yaml

wordpressを立ち上げる

kubectl create -f wordpress-deployment.yaml

起動を確認する

$ kubectl get pvc
NAME             STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mysql-pv-claim   Bound     pvc-64a467ef-f759-11e7-9b74-025000000001   20Gi       RWO            hostpath       42m
wp-pv-claim      Bound     pvc-c9ce4309-f75c-11e7-9b74-025000000001   20Gi       RWO            hostpath       17m
$ kubectl get pod
NAME                               READY     STATUS    RESTARTS   AGE
wordpress-5566d7675-9bs57          1/1       Running   0          17m
wordpress-mysql-7b4ffb6fb4-6rkkj   1/1       Running   0          42m
$ kubectl get svc
NAME              TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes        ClusterIP      10.96.0.1       <none>        443/TCP        3h
wordpress         LoadBalancer   10.101.234.56   <pending>     80:31689/TCP   17m
wordpress-mysql   ClusterIP      None            <none>        3306/TCP       42m

GKEなどではServiceのEXTERNAL-IPに接続先のIPアドレスが表示されますが、Docker for Macは localhost で繋ぐようです。

$ curl -sSL -D - localhost -o /dev/null
HTTP/1.1 200 OK
Date: Fri, 12 Jan 2018 06:16:50 GMT
Server: Apache/2.4.10 (Debian)
X-Powered-By: PHP/7.1.13
Link: <http://localhost/wp-json/>; rel="https://api.w.org/"
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

片付ける

# 一気に削除する場合
$ kubectl delete all,pvc,secret --all
# 設定ファイルを使って削除する場合
kubectl delete -f wordpress-deployment.yaml
kubectl delete -f mysql-deployment.yaml

参考記事

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?