本次环境如下(3台centos7.5组成k8s v.1.14集群):

master: 192.168.88.145

node1: 192.168.88.148

node2: 192.168.88.150

  1. 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进行安装:

部署完成。

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐