Kubernetes(k8s)中部署项目wordpress(php博客项目,数据库mysql)
要在Kubernetes中部署WordPress项目,您需要定义一个配置文件,其中包含了WordPress应用程序和MySQL数据库的定义。以下是一个简化的例子,展示了如何使用Kubernetes部署WordPress和MySQL。
首先,创建一个名为wordpress-deployment.yaml
的文件来定义WordPress部署和服务:
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
component: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 250Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
component: wordpress
template:
metadata:
labels:
app: wordpress
component: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
ports:
- containerPort: 80
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_USER
value: wordpress
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
- name: WORDPRESS_DB_NAME
value: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
- name: mysql
image: mysql:5.7
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
- name: MYSQL_DATABASE
value: wordpress
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wordpress-mysql-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
component: wordpress
type: LoadBalancer
然后,创建一个名为mysql-secret.yaml
的文件来定义M
评论已关闭