用kubernetes部署wordpress

举报
gugubengu 发表于 2022/08/10 23:49:49 2022/08/10
【摘要】 # 首先创建nfs (略)# kubectl create secret generic mysql-pass --from-literal='password=123456'# cat mysql-persistent-storage.yaml apiVersion: v1kind: PersistentVolumemetadata:  name: mysql-persistent-sto...

# 首先创建nfs (略)

# kubectl create secret generic mysql-pass --from-literal='password=123456'

# cat mysql-persistent-storage.yaml

apiVersion: v1

kind: PersistentVolume

metadata:

  name: mysql-persistent-storage

spec:

    capacity:

      storage: 20Gi

    accessModes:

              - ReadWriteOnce

    persistentVolumeReclaimPolicy: Recycle

    storageClassName: nfs

    nfs:

       path: /home/pvdata/mysql/

       server: 10.24.2.10

# cat mysql-deployment.yaml

apiVersion: v1

kind: Service

metadata:

  name: wordpress-mysql

  labels:

    app: wordpress

spec:

  ports:

    - port: 3306

  selector:

    app: wordpress

    tier: mysql

  clusterIP: None

---

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

  name: mysql-pv-claim

  labels:

    app: wordpress

spec:

  accessModes:

    - ReadWriteOnce

  resources:

    requests:

      storage: 20Gi

  storageClassName: nfs

---

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2

kind: Deployment

metadata:

  name: wordpress-mysql

  labels:

    app: wordpress

spec:

  selector:

    matchLabels:

      app: wordpress

      tier: mysql

  strategy:

    type: Recreate

  template:

    metadata:

      labels:

        app: wordpress

        tier: mysql

    spec:

      containers:

      - image: mysql:5.6

        name: mysql

        env:

        - name: MYSQL_ROOT_PASSWORD

          valueFrom:

            secretKeyRef:

              name: mysql-pass

              key: password

        ports:

        - containerPort: 3306

          name: mysql

        volumeMounts:

        - name: mysql-persistent-storage

          mountPath: /var/lib/mysql

      volumes:

      - name: mysql-persistent-storage

        persistentVolumeClaim:

          claimName: mysql-pv-claim

 

# cat wordpress-persistent-storage.yaml

apiVersion: v1

kind: PersistentVolume

metadata:

  name: wordpress-persistent-storage

spec:

    capacity:

      storage: 20Gi

    accessModes:

              - ReadWriteOnce

    persistentVolumeReclaimPolicy: Recycle

    storageClassName: nfs

    nfs:

       path: /home/pvdata/wordpress/

       server: 10.24.2.10

 

# cat wordpress-deployment.yaml

apiVersion: v1

kind: Service

metadata:

  name: wordpress

  labels:

    app: wordpress

spec:

  type: NodePort

  ports:

    - port: 80

      nodePort: 31000

  selector:

    app: wordpress

    tier: frontend

  type: NodePort

---

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

  name: wp-pv-claim

  labels:

    app: wordpress

spec:

  accessModes:

    - ReadWriteOnce

  resources:

    requests:

      storage: 20Gi

  storageClassName: nfs

---

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2

kind: Deployment

metadata:

  name: wordpress

  labels:

    app: wordpress

spec:

  selector:

    matchLabels:

      app: wordpress

      tier: frontend

  strategy:

    type: Recreate

  template:

    metadata:

      labels:

        app: wordpress

        tier: frontend

    spec:

      containers:

      - image: wordpress

        name: wordpress

        env:

        - name: WORDPRESS_DB_HOST

          value: wordpress-mysql

        - name: WORDPRESS_DB_PASSWORD

          valueFrom:

            secretKeyRef:

              name: mysql-pass

              key: password

        ports:

        - containerPort: 80

          name: wordpress

        volumeMounts:

        - name: wordpress-persistent-storage

          mountPath: /var/www/html

      volumes:

      - name: wordpress-persistent-storage

        persistentVolumeClaim:

          claimName: wp-pv-claim

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。