来自于官网
Kubernetes Documentation
Tutorials
Stateful Applications
Example: Deploying WordPress and MySQL with Persistent Volumes

Example: Deploying WordPress and MySQL with Persistent Volumes

  1. 按照教程依次创建yaml文件并复制代码

    [root@centos7-188 wordpress]# ls
    kustomization.yaml mysql-deployment.yaml wordpress-deployment.yaml

  2. 预备image

    Failed to pull image “wordpress:4.8-apache”

    使用阿里云容器镜像的 github关联仓库,海外机器构建 Docker 镜像

    自行创建了 1 个镜像,目前是公开状态

    registry.cn-beijing.aliyuncs.com/docker-dhbm/wordpress

  3. 预备 pvc 用到的 sc

    之前已经创建了 1 个动态 pv

    k8s学习: 部署动态 pvc(nfs-subdir-external-provisioner)

    [root@centos7-188 wordpress]# kubectl get sc

     NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE managed-nfs-storage k8s-sigs.io/nfs-subdir-external-provisioner Delete Immediate false 2d3h 
  4. 准备密码
    echo ‘123456’ |base64
    MTIzNDU2Cg==

  5. 准备kustomization.yaml文件

     cat <<EOF >./kustomization.yaml secretGenerator: - name: mysql-pass literals: - password=MTIzNDU2Cg== EOF 

    追加 resource

     cat <<EOF >>./kustomization.yaml resources: - mysql-deployment.yaml - wordpress-deployment.yaml EOF 

    文件最后结果
    [root@centos7-188 wordpress]# cat kustomization.yaml

     secretGenerator: - name: mysql-pass literals: - password='MTIzNDU2Cg==' # echo '123456' |base64 # MTIzNDU2Cg== resources: - mysql-deployment.yaml - wordpress-deployment.yaml - 
  6. mysql-deployment.yaml 加上 pvc 的 storageClassName: managed-nfs-storage,原文 pvc 20G 太大,改成 2 G
    如果不支持 LoadBalancer ,自行改成 NodePort,或者使用 port-forward

    vim mysql-deployment.yaml

     clusterIP: None --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pv-claim labels: app: wordpress spec: storageClassName: managed-nfs-storage # provisioner: k8s-sigs.io/nfs-subdir-external-provisioner accessModes: - ReadWriteOnce resources: requests: storage: 2Gi --- apiVersion: apps/v1 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 
  7. wordpress-deployment.yaml 加上 pvc 的 storageClassName: managed-nfs-storage,原文 pvc 20G 太大,改成 2 G
    如果不支持 LoadBalancer ,自行改成 NodePort,或者使用 port-forward

    vim wordpress-deployment.yaml

     apiVersion: v1 kind: PersistentVolumeClaim metadata: name: wp-pv-claim labels: app: wordpress spec: storageClassName: managed-nfs-storage # provisioner: k8s-sigs.io/nfs-subdir-external-provisioner accessModes: - ReadWriteOnce resources: requests: storage: 2Gi --- apiVersion: apps/v1 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: registry.cn-beijing.aliyuncs.com/docker-dhbm/wordpress # wordpress:4.8-apache 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 
  8. 开始执行创建
    kubectl apply -k ./

  9. 验证资源和服务

    [root@centos7-188 wordpress]# kubectl get secrets

     NAME TYPE DATA AGE default-token-m66xt kubernetes.io/service-account-token 3 15d mysql-pass-82d992t59h Opaque 1 42m nfs-client-provisioner-token-9bh8g kubernetes.io/service-account-token 3 2d3h 

    [root@centos7-188 wordpress]# kubectl get pvc

     NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE mysql-pv-claim Bound pvc-3668cbb9-2210-4c23-983a-07bf8e12c55d 2Gi RWO managed-nfs-storage 43m nfs-pvc Bound nfs-pv 100Mi RWX nfs-pv 32h test-claim Bound pvc-2b577445-6302-4503-982a-00b3c476673f 1Mi RWX managed-nfs-storage 8h wp-pv-claim Bound pvc-e33c3de0-0cc0-4ac5-8de9-f179a6a1663a 2Gi RWO managed-nfs-storage 43m 

    [root@centos7-188 wordpress]# kubectl get pods

     NAME READY STATUS RESTARTS AGE demo-654c477f6d-l6lbh 1/1 Running 7 (3h26m ago) 13d demo1-deployment-67fc75ff95-2k259 1/1 Running 3 31h demo1-deployment-67fc75ff95-nc5rx 1/1 Running 3 31h frontend-6cb8c45cd5-2r5xv 1/1 Running 0 3h5m frontend-6cb8c45cd5-bshtl 1/1 Running 0 3h5m frontend-6cb8c45cd5-kh767 1/1 Running 0 3h5m nfs-client-provisioner-554dbf7dd5-qd7hc 1/1 Running 14 2d2h redis-follower-6d6d97bb46-2pxsz 1/1 Running 0 3h5m redis-follower-6d6d97bb46-mlbdk 1/1 Running 0 3h5m redis-leader-fb76b4755-cxmnw 1/1 Running 0 3h8m wordpress-557cbf5c94-lqbd8 1/1 Running 0 23m wordpress-mysql-74978f46c9-cp29d 1/1 Running 0 44m 

    [root@centos7-188 wordpress]# kubectl get services wordpress

     NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE wordpress LoadBalancer 10.111.206.184 192.168.1.245 80:30498/TCP 44m 

10 打开浏览器,查看果实

开始会要求设置语言,然后会开始安装 wordpress ,设置用户名和密码 然后就可看到以下博客画面了! 哈哈哈!本人头一次看到 wordpress 的博客界面!感觉不错! ![在这里插入图片描述](https://img-blog.csdnimg.cn/a97347c8abd34ff7955676785d241c91.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ZOI5ZOI6JmOMTIz,size_20,color_FFFFFF,t_70,g_se,x_16) 
  1. 清理现场
    kubectl delete -k ./

原文链接:https://blog.csdn.net/u010953609/article/details/122091121?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166666867416781432990880%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166666867416781432990880&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-4-122091121-null-null.nonecase&utm_term=wordpress

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注