k8s官方案例:部署WordPress+MySql个人博客
步骤:
- 创建PersistentVolumeClaims(PVC)和PersistentVolume(PV)
- 创建Secret(注入MySql密码等)
- 部署MySQL容器组(Deployment)
- 部署WordPress容器组(Deployment)
创建PersistentVolumeClaims(PVC)和PersistentVolume(PV)
MySQL和WordPress都使用持久存储(PV)来存储数据。这里我们使用基于rook-ceph项目提供的RBD块存储(存储池),为MySQL和WordPress动态创建PV。rook-ceph部署上篇博客。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: mywordpress
# StorageClass的名字,pvc调用时填的名字
provisioner: ceph.rook.io/block
parameters:
pool: replicapool
# Specify the namespace of the rook cluster from which to create volumes.
# If not specified, it will use `rook` as the default namespace of the cluster.
# This is also the namespace where the cluster will be
clusterNamespace: rook-ceph
# Specify the filesystem type of the volume. If not specified, it will use `ext4`.
fstype: xfs
# 设置回收策略默认为:Retain
reclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: mywordpress
创建资源对象
kubectl apply -f mywordpress-storageclass-pvc.yaml