# 创建一个单独的名称空间
---
apiVersion: v1
kind: Namespace
metadata:
name: wordpress
# 创建mysql的deployment控制器
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: wordpress
name: word-mysql
labels:
app: wordpress-mysql
spec:
replicas: 1
selector:
matchLabels:
name: wordpress-mysql
template:
metadata:
labels:
name: wordpress-mysql
spec:
containers:
- name: wordpress-mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
name: dbport
env:
- name: MYSQL_ROOT_PASSWORD
value: rootPassW0rd
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wordpress
- name: MYSQL_PASSWORD
value: wordpress
volumeMounts:
- name: db
mountPath: /var/lib/mysql
volumes:
- name: db
hostPath:
path: /var/lib/mysql
# 为mysql创建一个service
---
# mysql service
apiVersion: v1
kind: Service
metadata:
name: wpmysql
namespace: wordpress
spec:
clusterIP: None
selector:
name: wordpress-mysql
ports:
- name: mysqlport
protocol: TCP
port: 3306
targetPort: 3306
# 创建Wordpress的deployment控制器
---
# wordpress
apiVersion: apps/v1
kind: Deployment
metadata:
name: word-deploy
namespace: wordpress
labels:
name: wordpress-web
spec:
replicas: 1
selector:
matchLabels:
name: wordpress-web
template:
metadata:
labels:
name: wordpress-web
spec:
containers:
- name: wordpress-web
image: wordpress
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: wdwebport
env:
- name: WORDPRESS_DB_HOST
value: wpmysql:3306
- name: WORDPRESS_DB_USER
value: wordpress
- name: WORDPRESS_DB_PASSWORD
value: wordpress
# 为wordpress创建service
---
# wordpress-web service
apiVersion: v1
kind: Service
metadata:
namespace: wordpress
name: wd-web-svc
spec:
selector:
name: wordpress-web
ports:
- name: wd-web-port
port: 80
protocol: TCP
type: NodePort
参考:https://blog.csdn.net/dayi_123/article/details/107297043
https://www.iteait.com/archives/914