使用Docker for Mac与Kubernetes搭建WordPress
首先 .
由于 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
请下载以下文件:
– mysql-deployment.yaml
– wordpress-deployment.yaml
从 https://github.com/kubernetes/examples/tree/master/mysql-wordpress-pd
将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地址,但对于Mac上的Docker来说,似乎应该使用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
请参阅相关文章。
-
- https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/
-
- https://github.com/kubernetes/examples/tree/master/mysql-wordpress-pd
- https://qiita.com/taishin/items/920d62a641c9cd58f289