k8s容器化部署wordpress实战
Posted ~~~~~~~~~~~~~~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s容器化部署wordpress实战相关的知识,希望对你有一定的参考价值。
本次环境如下(3台centos7.5组成k8s v.1.14集群): master: 192.168.88.145 node1: 192.168.88.148 node2: 192.168.88.150 |
- wordpress部署
wordpress.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: wordpress
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- image: wordpress
name: wordpress
ports:
- name: wp-port
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
type: NodePort
selector:
app: wordpress
ports:
- port: 80
targetPort: wp-port
2.mysql部署
mysql.yaml:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-mysql
spec:
storageClassName: gluster-heketi
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
data:
MYSQL_ROOT_PASSWORD: YWRtaW4=
kind: Secret
metadata:
name: my-secret
namespace: default
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: mysql
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.6.48
name: mysql
ports:
- name: wp-port
containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: my-secret
key: MYSQL_ROOT_PASSWORD
volumeMounts:
- name: db-data
mountPath: "/var/lib/mysql"
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 30
timeoutSeconds: 1
volumes:
- name: db-data
persistentVolumeClaim:
claimName: pvc-mysql
---
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
spec:
type: ClusterIP
selector:
app: mysql
ports:
- name: db-port
port: 3306
targetPort: 3306
protocol: TCP
最终布署效果如下:
进入mysql容器创建wordpress数据库,使用node节点IP加端口号54548访问wordpress进行安装:
部署完成。
以上是关于k8s容器化部署wordpress实战的主要内容,如果未能解决你的问题,请参考以下文章
使用Helm 在容器服务k8s集群一键部署wordpress