k8s实战案例之运行WordPress

这篇具有很好参考价值的文章主要介绍了k8s实战案例之运行WordPress。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、WordPress架构

k8s实战案例之运行WordPress

LNMP案例之基于Nginx+PHP实现WordPress博客站点,要求Nginx+PHP运⾏在同⼀个Pod的不同容器;nginx主要作用是接入站点请求,如果请求静态资源nginx就直接响应;如果请求的是一个动态php资源,就将对应请求转发给另一个php容器进行处理;在一个pod中运行多容器,网络名称空间是共享的,所以nginx可以将对应请求转发至127.0.0.1:9000这个端口来调用php来处理对应php请求;pod中如果有数据产生,pod通过pvc/pv将对应数据存储到远端存储上;客户端访问通过防火墙,负载均衡器将请求调度到后端node上处理,如果请求所在节点没有运行对应pod,那么对应node会根据路由来转发请求,最终会将请求转发给pod所在节点进行处理;

2、镜像准备

2.1、准备PHP镜像

2.1.1、php镜像目录文件

k8s实战案例之运行WordPress

2.1.2、构建php镜像Dockerfile

root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/php# cat Dockerfile 
#PHP Base Image
FROM harbor.ik8s.cc/baseimages/magedu-centos-base:7.9.2009 

RUN yum install -y  https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm && yum install  php56-php-fpm php56-php-mysql -y 
ADD www.conf /opt/remi/php56/root/etc/php-fpm.d/www.conf
#RUN useradd nginx -u 2019
ADD run_php.sh /usr/local/bin/run_php.sh
EXPOSE 9000

CMD ["/usr/local/bin/run_php.sh"] 
root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/php#

2.1.3、运行php镜像脚本

root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/php# cat run_php.sh 
#!/bin/bash
#echo "nameserver 10.20.254.254" > /etc/resolv.conf

/opt/remi/php56/root/usr/sbin/php-fpm
#/opt/remi/php56/root/usr/sbin/php-fpm --nodaemonize
tail -f /etc/hosts
root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/php# 

2.1.4、构建php镜像脚本

root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/php# cat build-command.sh
#!/bin/bash
TAG=$1
#docker build -t harbor.ik8s.cc/magedu/wordpress-php-5.6:${TAG} .
nerdctl build -t harbor.ik8s.cc/magedu/wordpress-php-5.6:${TAG} .
echo "镜像制作完成,即将上传至Harbor服务器"
sleep 1
nerdctl push harbor.ik8s.cc/magedu/wordpress-php-5.6:${TAG}
echo "镜像上传完成"
root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/php# 

2.1.5、构建php镜像

k8s实战案例之运行WordPress

2.2、准备nginx-wordpress镜像

2.2.1、nginx-wordpress镜像目录文件

k8s实战案例之运行WordPress

2.2.2、构建nginx-wordpress镜像Dockerfile

root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/nginx# cat Dockerfile 
FROM harbor.ik8s.cc/pub-images/nginx-base-wordpress:v1.22.0 

ADD nginx.conf /apps/nginx/conf/nginx.conf
ADD run_nginx.sh /apps/nginx/sbin/run_nginx.sh
RUN mkdir -pv /home/nginx/wordpress
RUN chown nginx.nginx /home/nginx/wordpress/ -R

EXPOSE 80 443

CMD ["/apps/nginx/sbin/run_nginx.sh"] 
root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/nginx# 

该镜像依赖nginx-base-wordpress镜像,在nginx-base-wordpress镜像基础上添加nginx的配置文件,添加运行nginx脚本以及创建存放wordpress代码目录以及更改目录权限等;

2.2.2.1、构建依赖镜像nginx-base-wordpress目录文件

k8s实战案例之运行WordPress

2.2.2.2、构建nginx-base-wordpress镜像Dockerfile

root@k8s-master01:~/k8s-data/dockerfile/web/pub-images/nginx-base-wordpress# cat Dockerfile 
#Nginx Base Image
FROM harbor.ik8s.cc/baseimages/magedu-centos-base:7.9.2009 

RUN yum install -y vim wget tree  lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop
ADD nginx-1.22.0.tar.gz /usr/local/src/
RUN cd /usr/local/src/nginx-1.22.0 && ./configure --prefix=/apps/nginx  && make && make install && ln -sv  /apps/nginx/sbin/nginx /usr/sbin/nginx  &&rm -rf /usr/local/src/nginx-1.22.0.tar.gz 
root@k8s-master01:~/k8s-data/dockerfile/web/pub-images/nginx-base-wordpress# 

该镜像主要做了安装编译环境,放nginx源码包进去编译nginx;

2.2.2.3、构建nginx-base-wordpress镜像脚本

root@k8s-master01:~/k8s-data/dockerfile/web/pub-images/nginx-base-wordpress# cat build-command.sh 
#!/bin/bash
#docker build -t harbor.ik8s.cc/pub-images/nginx-base-wordpress:v1.20.2  .
#sleep 1
#docker push  harbor.ik8s.cc/pub-images/nginx-base-wordpress:v1.20.2

nerdctl build -t  harbor.ik8s.cc/pub-images/nginx-base-wordpress:v1.22.0  .
nerdctl push harbor.ik8s.cc/pub-images/nginx-base-wordpress:v1.22.0
root@k8s-master01:~/k8s-data/dockerfile/web/pub-images/nginx-base-wordpress# 

2.2.2.4、构建nginx-base-wordpress镜像

k8s实战案例之运行WordPress

2.2.3、运行nginx-wordpress镜像脚本

root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/nginx# cat run_nginx.sh 
#!/bin/bash
#echo "nameserver 10.20.254.254" > /etc/resolv.conf
#chown nginx.nginx /home/nginx/wordpress/ -R
/apps/nginx/sbin/nginx
tail -f /etc/hosts
root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/nginx# 

2.2.4、构建nginx-wordpress镜像脚本

root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/nginx# cat build-command.sh 
#!/bin/bash
TAG=$1
#docker build -t harbor.ik8s.cc/magedu/wordpress-nginx:${TAG} .
nerdctl build -t harbor.ik8s.cc/magedu/wordpress-nginx:${TAG} .
echo "镜像制作完成,即将上传至Harbor服务器"
sleep 1
nerdctl push  harbor.ik8s.cc/magedu/wordpress-nginx:${TAG}
echo "镜像上传完成"
root@k8s-master01:~/k8s-data/dockerfile/web/magedu/wordpress/nginx# 

2.2.5、构建nginx-wordpress镜像

k8s实战案例之运行WordPress

3、运行WordPress站点

3.1、在k8s上运行wordpress的配置清单

kind: Deployment
#apiVersion: extensions/v1beta1
apiVersion: apps/v1
metadata:
  labels:
    app: wordpress-app
  name: wordpress-app-deployment
  namespace: magedu
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress-app
  template:
    metadata:
      labels:
        app: wordpress-app
    spec:
      containers:
      - name: wordpress-app-nginx
        image: harbor.ik8s.cc/magedu/wordpress-nginx:v1
        imagePullPolicy: Always
        ports:
        - containerPort: 80
          protocol: TCP
          name: http
        - containerPort: 443
          protocol: TCP
          name: https
        volumeMounts:
        - name: wordpress
          mountPath: /home/nginx/wordpress
          readOnly: false

      - name: wordpress-app-php
        image: harbor.ik8s.cc/magedu/wordpress-php-5.6:v1 
        #imagePullPolicy: IfNotPresent
        imagePullPolicy: Always
        ports:
        - containerPort: 9000
          protocol: TCP
          name: http
        volumeMounts:
        - name: wordpress
          mountPath: /home/nginx/wordpress
          readOnly: false

      volumes:
      - name: wordpress
        nfs:
          server: 192.168.0.42
          path: /data/k8sdata/magedu/wordpress 


---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: wordpress-app
  name: wordpress-app-spec
  namespace: magedu
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30031
  - name: https
    port: 443
    protocol: TCP
    targetPort: 443
    nodePort: 30033
  selector:
    app: wordpress-app

该清单主要描述了用deplopment控制器部署wordpress,wordpress pod中运行nginx和php容器,两个容器共用/home/nginx/wordpress目录,该目录是远端nfs存储上共享出来的目录,通常情况下该目录放置wordpress代码文件;

3.2、在nfs服务器准备存放wordpress代码文件目录

root@harbor:~# tail -1 /etc/exports
/data/k8sdata/magedu/wordpress *(rw,no_root_squash)
root@harbor:~# mkdir -pv /data/k8sdata/magedu/wordpress
mkdir: created directory '/data/k8sdata/magedu/wordpress'
root@harbor:~# exportfs -av
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/kuboard".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/volumes".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [3]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/pod-vol".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [4]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/myserver".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [5]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/mysite".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [7]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/images".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [8]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/static".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [11]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/zookeeper-datadir-1".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [12]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/zookeeper-datadir-2".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [13]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/zookeeper-datadir-3".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [16]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis-datadir-1".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [18]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis0".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [19]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis1".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [20]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis2".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [21]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis3".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [22]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis4".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [23]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/redis5".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [27]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/mysql-datadir-1".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [28]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/mysql-datadir-2".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [29]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/mysql-datadir-3".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [30]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/mysql-datadir-4".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [31]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/mysql-datadir-5".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [34]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/jenkins-data".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [35]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/jenkins-root-data".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [37]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/wordpress".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

exporting *:/data/k8sdata/magedu/wordpress
exporting *:/data/k8sdata/magedu/jenkins-root-data
exporting *:/data/k8sdata/magedu/jenkins-data
exporting *:/data/k8sdata/magedu/mysql-datadir-5
exporting *:/data/k8sdata/magedu/mysql-datadir-4
exporting *:/data/k8sdata/magedu/mysql-datadir-3
exporting *:/data/k8sdata/magedu/mysql-datadir-2
exporting *:/data/k8sdata/magedu/mysql-datadir-1
exporting *:/data/k8sdata/magedu/redis5
exporting *:/data/k8sdata/magedu/redis4
exporting *:/data/k8sdata/magedu/redis3
exporting *:/data/k8sdata/magedu/redis2
exporting *:/data/k8sdata/magedu/redis1
exporting *:/data/k8sdata/magedu/redis0
exporting *:/data/k8sdata/magedu/redis-datadir-1
exporting *:/data/k8sdata/magedu/zookeeper-datadir-3
exporting *:/data/k8sdata/magedu/zookeeper-datadir-2
exporting *:/data/k8sdata/magedu/zookeeper-datadir-1
exporting *:/data/k8sdata/magedu/static
exporting *:/data/k8sdata/magedu/images
exporting *:/data/k8sdata/mysite
exporting *:/data/k8sdata/myserver
exporting *:/pod-vol
exporting *:/data/volumes
exporting *:/data/k8sdata/kuboard
root@harbor:~#

3.3、运行WordPress

root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl apply -f wordpress.yaml 
deployment.apps/wordpress-app-deployment created
service/wordpress-app-spec created
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl get pods -n magedu 
NAME                                            READY   STATUS      RESTARTS       AGE
magedu-consumer-deployment-798c7d785b-fp4b9     1/1     Running     2 (16m ago)    8d
magedu-consumer-deployment-798c7d785b-wmv9p     1/1     Running     2 (16m ago)    8d
magedu-consumer-deployment-798c7d785b-zqm74     1/1     Running     2 (16m ago)    8d
magedu-dubboadmin-deployment-798c4dfdd8-kvfvh   1/1     Running     2 (16m ago)    8d
magedu-provider-deployment-6fccc6d9f5-k6z7m     1/1     Running     2 (16m ago)    8d
magedu-provider-deployment-6fccc6d9f5-nl4zd     1/1     Running     2 (16m ago)    8d
magedu-provider-deployment-6fccc6d9f5-p94rb     1/1     Running     2 (16m ago)    8d
mysql-0                                         2/2     Running     10 (16m ago)   65d
mysql-1                                         2/2     Running     10 (16m ago)   65d
mysql-2                                         2/2     Running     10 (16m ago)   65d
redis-0                                         1/1     Running     7 (16m ago)    74d
redis-1                                         1/1     Running     7 (16m ago)    74d
redis-2                                         1/1     Running     7 (16m ago)    74d
redis-3                                         1/1     Running     7 (16m ago)    74d
redis-4                                         1/1     Running     7 (16m ago)    74d
redis-5                                         1/1     Running     7 (16m ago)    74d
ubuntu1804                                      0/1     Completed   0              74d
wordpress-app-deployment-64c956bf9c-6qp8q       2/2     Running     0              38s
zookeeper1-675c5477cb-vmwwq                     1/1     Running     9 (16m ago)    76d
zookeeper2-759fb6c6f-7jktr                      1/1     Running     9 (16m ago)    76d
zookeeper3-5c78bb5974-vxpbh                     1/1     Running     9 (16m ago)    76d
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl get svc -n magedu 
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                        AGE
magedu-consumer-server      NodePort    10.100.208.121   <none>        80:49630/TCP                                   8d
magedu-dubboadmin-service   NodePort    10.100.244.92    <none>        80:31080/TCP                                   8d
magedu-provider-spec        NodePort    10.100.187.168   <none>        80:44873/TCP                                   8d
mysql                       ClusterIP   None             <none>        3306/TCP                                       65d
mysql-read                  ClusterIP   10.100.15.127    <none>        3306/TCP                                       65d
redis                       ClusterIP   None             <none>        6379/TCP                                       74d
redis-access                NodePort    10.100.117.185   <none>        6379:36379/TCP                                 74d
wordpress-app-spec          NodePort    10.100.189.214   <none>        80:30031/TCP,443:30033/TCP                     47s
zookeeper                   ClusterIP   10.100.237.95    <none>        2181/TCP                                       76d
zookeeper1                  NodePort    10.100.63.118    <none>        2181:32181/TCP,2888:30541/TCP,3888:31200/TCP   76d
zookeeper2                  NodePort    10.100.199.43    <none>        2181:32182/TCP,2888:32670/TCP,3888:32264/TCP   76d
zookeeper3                  NodePort    10.100.41.9      <none>        2181:32183/TCP,2888:31329/TCP,3888:32546/TCP   76d
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# 

3.4、创建PHP测试页

root@harbor:/data/k8sdata/magedu/wordpress# ll 
total 12
drwxr-xr-x  2 root root 4096 Aug 19 16:33 ./
drwxr-xr-x 22 root root 4096 Aug 19 16:26 ../
-rw-r--r--  1 root root   20 Aug 19 16:33 test.php
root@harbor:/data/k8sdata/magedu/wordpress# cat test.php 
<?php
phpinfo();
?>
root@harbor:/data/k8sdata/magedu/wordpress# 

3.5、访问PHP测试页

k8s实战案例之运行WordPress

能够正常访问到php测试页面,说明nginx+php环境准备ok,远端nfs存储挂载ok;

4、初始化WordPress站点

4.1、k8s中MySQL创建数据库

root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl exec -it mysql-0 bash -n magedu 
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Defaulted container "mysql" out of: mysql, xtrabackup, init-mysql (init), clone-mysql (init)
root@mysql-0:/# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 905
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.02 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"%" IDENTIFIED BY
    -> "wordpress";
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show databases;
+------------------------+
| Database               |
+------------------------+
| information_schema     |
| mydb                   |
| mysql                  |
| performance_schema     |
| sys                    |
| wordpress              |
| xtrabackup_backupfiles |
+------------------------+
7 rows in set (0.02 sec)

mysql> 

使⽤k8s中运⾏的mysql服务,作为mysql服务器;

4.2、k8s中测试MySQL连接

root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl get svc -n magedu 
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                        AGE
magedu-consumer-server      NodePort    10.100.208.121   <none>        80:49630/TCP                                   8d
magedu-dubboadmin-service   NodePort    10.100.244.92    <none>        80:31080/TCP                                   8d
magedu-provider-spec        NodePort    10.100.187.168   <none>        80:44873/TCP                                   8d
mysql                       ClusterIP   None             <none>        3306/TCP                                       65d
mysql-read                  ClusterIP   10.100.15.127    <none>        3306/TCP                                       65d
redis                       ClusterIP   None             <none>        6379/TCP                                       74d
redis-access                NodePort    10.100.117.185   <none>        6379:36379/TCP                                 74d
wordpress-app-spec          NodePort    10.100.189.214   <none>        80:30031/TCP,443:30033/TCP                     25m
zookeeper                   ClusterIP   10.100.237.95    <none>        2181/TCP                                       76d
zookeeper1                  NodePort    10.100.63.118    <none>        2181:32181/TCP,2888:30541/TCP,3888:31200/TCP   76d
zookeeper2                  NodePort    10.100.199.43    <none>        2181:32182/TCP,2888:32670/TCP,3888:32264/TCP   76d
zookeeper3                  NodePort    10.100.41.9      <none>        2181:32183/TCP,2888:31329/TCP,3888:32546/TCP   76d
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl get pods 
NAME   READY   STATUS    RESTARTS      AGE
bash   1/1     Running   4 (41m ago)   13d
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl exec -it bash bash 
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
[root@bash ~]# mysql -uwordpress -pwordpress -hmysql.magedu
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1502
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wordpress          |
+--------------------+
2 rows in set (0.01 sec)

MySQL [(none)]> 

这里需要注意一点mysql在k8s中是以svc的方式向外提供服务,所以测试我们需要写mysql的svc名称;如果在同一名称空间写mysql svc名称即可,如果跨名称空间需要写mysql svc名称.mysql svc所在名称空间名称,这样coredns才能正常解析mysql svc;

4.3、在nfs服务器上上传wordpress代码

root@harbor:~# wget https://cn.wordpress.org/wordpress-5.6.10-zh_CN.tar.gz
--2023-08-19 17:00:28--  https://cn.wordpress.org/wordpress-5.6.10-zh_CN.tar.gz
Resolving cn.wordpress.org (cn.wordpress.org)... 198.143.164.253
Connecting to cn.wordpress.org (cn.wordpress.org)|198.143.164.253|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16316134 (16M) [application/octet-stream]
Saving to: ‘wordpress-5.6.10-zh_CN.tar.gz’

wordpress-5.6.10-zh_CN.tar.gz         100%[========================================================================>]  15.56M  2.14MB/s    in 8.7s    

2023-08-19 17:00:38 (1.79 MB/s) - ‘wordpress-5.6.10-zh_CN.tar.gz’ saved [16316134/16316134]

root@harbor:~# ll
total 635096
drwx------  8 root root      4096 Aug 19 17:00 ./
drwxr-xr-x 22 root root      4096 May 10 13:57 ../
-rw-------  1 root root      8360 Aug  6 07:33 .bash_history
-rw-r--r--  1 root root      3106 Oct 15  2021 .bashrc
drwx------  3 root root      4096 Apr 20 16:45 .cache/
drwx------  3 root root      4096 Jun  5 17:55 .config/
drwx------  2 root root      4096 Apr 22 07:21 .docker/
-rw-------  1 root root        20 Jun  6 14:44 .lesshst
-rw-r--r--  1 root root       161 Jul  9  2019 .profile
drwx------  2 root root      4096 Apr 20 16:41 .ssh/
-rw-------  1 root root      9366 Aug 19 16:33 .viminfo
-rw-r--r--  1 root root 633942863 Apr 17 19:00 harbor-offline-installer-v2.8.0.tgz
drwxr-xr-x  2 root root      4096 Aug  6 03:18 jenkins-data/
drwxr-xr-x  2 root root      4096 Aug  6 03:18 jenkins-root-data/
-rw-r--r--  1 root root  16316134 Oct 18  2022 wordpress-5.6.10-zh_CN.tar.gz
root@harbor:~# tar -xf wordpress-5.6.10-zh_CN.tar.gz -C /data/k8sdata/magedu/
root@harbor:~# ll /data/k8sdata/magedu/wordpress/
total 228
drwxr-xr-x  5 1006 1006  4096 Oct 18  2022 ./
drwxr-xr-x 22 root root  4096 Aug 19 16:26 ../
-rw-r--r--  1 1006 1006   405 Feb  6  2020 index.php
-rw-r--r--  1 1006 1006 19915 Oct 18  2022 license.txt
-rw-r--r--  1 1006 1006  7278 Oct 18  2022 readme.html
-rw-r--r--  1 root root    20 Aug 19 16:33 test.php
-rw-r--r--  1 1006 1006  7101 Jul 28  2020 wp-activate.php
drwxr-xr-x  9 1006 1006  4096 Oct 18  2022 wp-admin/
-rw-r--r--  1 1006 1006   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 1006 1006  2328 Oct  8  2020 wp-comments-post.php
-rw-r--r--  1 1006 1006  2913 Oct 18  2022 wp-config-sample.php
drwxr-xr-x  5 1006 1006  4096 Oct 18  2022 wp-content/
-rw-r--r--  1 1006 1006  3939 Jul 30  2020 wp-cron.php
drwxr-xr-x 25 1006 1006 12288 Oct 18  2022 wp-includes/
-rw-r--r--  1 1006 1006  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--  1 1006 1006  3300 Feb  6  2020 wp-load.php
-rw-r--r--  1 1006 1006 49831 Nov  9  2020 wp-login.php
-rw-r--r--  1 1006 1006  8454 Oct 17  2022 wp-mail.php
-rw-r--r--  1 1006 1006 20975 Nov 12  2020 wp-settings.php
-rw-r--r--  1 1006 1006 31337 Sep 30  2020 wp-signup.php
-rw-r--r--  1 1006 1006  4816 Oct 17  2022 wp-trackback.php
-rw-r--r--  1 1006 1006  3236 Jun  8  2020 xmlrpc.php
root@harbor:~# 

4.4、更改wordpress代码文件权限

4.4.1、查看nginx用户id

root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl get pods -n magedu 
NAME                                            READY   STATUS      RESTARTS       AGE
magedu-consumer-deployment-798c7d785b-fp4b9     1/1     Running     2 (53m ago)    8d
magedu-consumer-deployment-798c7d785b-wmv9p     1/1     Running     2 (53m ago)    8d
magedu-consumer-deployment-798c7d785b-zqm74     1/1     Running     2 (53m ago)    8d
magedu-dubboadmin-deployment-798c4dfdd8-kvfvh   1/1     Running     2 (53m ago)    8d
magedu-provider-deployment-6fccc6d9f5-k6z7m     1/1     Running     2 (53m ago)    8d
magedu-provider-deployment-6fccc6d9f5-nl4zd     1/1     Running     2 (53m ago)    8d
magedu-provider-deployment-6fccc6d9f5-p94rb     1/1     Running     2 (53m ago)    8d
mysql-0                                         2/2     Running     10 (53m ago)   65d
mysql-1                                         2/2     Running     10 (53m ago)   65d
mysql-2                                         2/2     Running     10 (53m ago)   65d
redis-0                                         1/1     Running     7 (53m ago)    74d
redis-1                                         1/1     Running     7 (53m ago)    74d
redis-2                                         1/1     Running     7 (53m ago)    74d
redis-3                                         1/1     Running     7 (53m ago)    74d
redis-4                                         1/1     Running     7 (53m ago)    74d
redis-5                                         1/1     Running     7 (53m ago)    74d
ubuntu1804                                      0/1     Completed   0              74d
wordpress-app-deployment-64c956bf9c-6qp8q       2/2     Running     0              37m
zookeeper1-675c5477cb-vmwwq                     1/1     Running     9 (53m ago)    76d
zookeeper2-759fb6c6f-7jktr                      1/1     Running     9 (53m ago)    76d
zookeeper3-5c78bb5974-vxpbh                     1/1     Running     9 (53m ago)    76d
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# kubectl exec -it wordpress-app-deployment-64c956bf9c-6qp8q id nginx -n magedu 
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Defaulted container "wordpress-app-nginx" out of: wordpress-app-nginx, wordpress-app-php
uid=2088(nginx) gid=2088(nginx) groups=2088(nginx)
root@k8s-master01:~/k8s-data/yaml/magedu/wordpress# 

4.4.2、在nfs服务器上更改wordpress目录权限

root@harbor:~# ll /data/k8sdata/magedu/wordpress/
total 228
drwxr-xr-x  5 1006 1006  4096 Oct 18  2022 ./
drwxr-xr-x 22 root root  4096 Aug 19 16:26 ../
-rw-r--r--  1 1006 1006   405 Feb  6  2020 index.php
-rw-r--r--  1 1006 1006 19915 Oct 18  2022 license.txt
-rw-r--r--  1 1006 1006  7278 Oct 18  2022 readme.html
-rw-r--r--  1 root root    20 Aug 19 16:33 test.php
-rw-r--r--  1 1006 1006  7101 Jul 28  2020 wp-activate.php
drwxr-xr-x  9 1006 1006  4096 Oct 18  2022 wp-admin/
-rw-r--r--  1 1006 1006   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 1006 1006  2328 Oct  8  2020 wp-comments-post.php
-rw-r--r--  1 1006 1006  2913 Oct 18  2022 wp-config-sample.php
drwxr-xr-x  5 1006 1006  4096 Oct 18  2022 wp-content/
-rw-r--r--  1 1006 1006  3939 Jul 30  2020 wp-cron.php
drwxr-xr-x 25 1006 1006 12288 Oct 18  2022 wp-includes/
-rw-r--r--  1 1006 1006  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--  1 1006 1006  3300 Feb  6  2020 wp-load.php
-rw-r--r--  1 1006 1006 49831 Nov  9  2020 wp-login.php
-rw-r--r--  1 1006 1006  8454 Oct 17  2022 wp-mail.php
-rw-r--r--  1 1006 1006 20975 Nov 12  2020 wp-settings.php
-rw-r--r--  1 1006 1006 31337 Sep 30  2020 wp-signup.php
-rw-r--r--  1 1006 1006  4816 Oct 17  2022 wp-trackback.php
-rw-r--r--  1 1006 1006  3236 Jun  8  2020 xmlrpc.php
root@harbor:~# chown 2088.2088 /data/k8sdata/magedu/wordpress/ -R
root@harbor:~# ll /data/k8sdata/magedu/wordpress/
total 228
drwxr-xr-x  5 2088 2088  4096 Oct 18  2022 ./
drwxr-xr-x 22 root root  4096 Aug 19 16:26 ../
-rw-r--r--  1 2088 2088   405 Feb  6  2020 index.php
-rw-r--r--  1 2088 2088 19915 Oct 18  2022 license.txt
-rw-r--r--  1 2088 2088  7278 Oct 18  2022 readme.html
-rw-r--r--  1 2088 2088    20 Aug 19 16:33 test.php
-rw-r--r--  1 2088 2088  7101 Jul 28  2020 wp-activate.php
drwxr-xr-x  9 2088 2088  4096 Oct 18  2022 wp-admin/
-rw-r--r--  1 2088 2088   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 2088 2088  2328 Oct  8  2020 wp-comments-post.php
-rw-r--r--  1 2088 2088  2913 Oct 18  2022 wp-config-sample.php
drwxr-xr-x  5 2088 2088  4096 Oct 18  2022 wp-content/
-rw-r--r--  1 2088 2088  3939 Jul 30  2020 wp-cron.php
drwxr-xr-x 25 2088 2088 12288 Oct 18  2022 wp-includes/
-rw-r--r--  1 2088 2088  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--  1 2088 2088  3300 Feb  6  2020 wp-load.php
-rw-r--r--  1 2088 2088 49831 Nov  9  2020 wp-login.php
-rw-r--r--  1 2088 2088  8454 Oct 17  2022 wp-mail.php
-rw-r--r--  1 2088 2088 20975 Nov 12  2020 wp-settings.php
-rw-r--r--  1 2088 2088 31337 Sep 30  2020 wp-signup.php
-rw-r--r--  1 2088 2088  4816 Oct 17  2022 wp-trackback.php
-rw-r--r--  1 2088 2088  3236 Jun  8  2020 xmlrpc.php
root@harbor:~# 

4.5、通过web界面初始化数据库

k8s实战案例之运行WordPress
k8s实战案例之运行WordPress

这里的数据库主机需要填写mysql svc名称.名称空间名称;如果你的mysql是主从架构,这里就需要填写主库的svc名称.名称空间;

k8s实战案例之运行WordPress

页面提示不错,这里表示我们写的mysql主机地址正常;点击现在安装即可;

k8s实战案例之运行WordPress

填写好站点名称,用户名密码 点击安装wordpress即可;

k8s实战案例之运行WordPress

能够看到成功,表示wordpress初始化成功;填写我们刚才设置的密码点击登录即可;

k8s实战案例之运行WordPress
k8s实战案例之运行WordPress

5、验证k8s中MySQL数据

5.1、验证master数据

k8s实战案例之运行WordPress

5.2、验证slave数据

k8s实战案例之运行WordPress文章来源地址https://www.toymoban.com/news/detail-658591.html

到了这里,关于k8s实战案例之运行WordPress的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • K8S原理架构与实战教程

    在介绍K8S之前,先来看看服务器的演变过程:物理机时代、虚拟机时代、容器化时代。 物理机时代的缺点: 部署慢 :每台服务器都要安装操作系统、相关的应用程序所需要的环境,各种配置 成本高:物理服务器的价格十分昂贵 资源浪费:硬件资源不能充分利用 扩展和迁移

    2024年02月09日
    浏览(63)
  • k8s实战案例之部署Zookeeper集群

    zookeeper是一个开源的分布式协调服务,由知名互联网公司Yahoo创建,它是Chubby的开源实现;换句话讲,zookeeper是一个典型的分布式数据一致性解决方案,分布式应用程序可以基于它实现数据的发布/订阅、负载均衡、名称服务、分布式协调/通知、集群管理、Master选举、分布式锁

    2024年02月08日
    浏览(53)
  • 【云原生|K8s系列第1篇】:K8s的基础概念、组件架构及实战安装

    首先,K8s并不是一个传统意义上的 PaaS平台即服务的工具,它充分给使用者提供了很多很多选择的空间。 不限制支持的应用程序类型,K8s并不插手应用程序框架, 也不限制支持的语言 (如 Java, Python, Ruby 等),只要应用符合 12 因素即可。也就是说,只需要应用可以在容器中运行

    2024年02月03日
    浏览(76)
  • K8S+DevOps架构师实战课 | 汇总

    视频来源:B站《Dockerk8s教程天花板,绝对是B站讲的最好的,这一套学会k8s搞定Docker 全部核心知识都在这里》 一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持! 1.K8S+DevOps架构师实战课 | 认识docker_热爱编程的通信人的博客-CSDN博客 2.K8S+Dev

    2024年02月13日
    浏览(46)
  • 云原生架构设计与实现:Spark 在 K8s 上运行的基本原理

    在 Kubernetes(K8s)中,Pod 是最小的可调度单元。当 Spark 任务运行在 K8s 上时,无论是 Driver 还是 Executor 都由一个单独的 Pod 来表示。每个 Pod 都被分配了一个唯一的 IP 地址,并且可以包含一个或多个容器(Container)。Driver 和 Executor 的 JVM 进程都是在这些 Container 中启动、运行

    2024年01月19日
    浏览(48)
  • k8s实战案例之部署redis单机和redis cluster

    redis是一款基于BSD协议,开源的非关系型数据库(nosql数据库),作者是意大利开发者Salvatore Sanfilippo在2009年发布,使用C语言编写;redis是基于内存存储,而且是目前比较流行的键值数据库(key-value database),它提供将内存通过网络远程共享的一种服务,提供类似功能的还有

    2024年02月08日
    浏览(49)
  • k8s实战案例之部署Nginx+Tomcat+NFS实现动静分离

    根据业务的不同,我们可以导入官方基础镜像,在官方基础镜像的基础上自定义需要用的工具和环境,然后构建成自定义出自定义基础镜像,后续再基于自定义基础镜像,来构建不同服务的基础镜像,最后基于服务的自定义基础镜像构建出对应业务镜像;最后将这些镜像上传

    2024年02月07日
    浏览(50)
  • 云原生之深入解析Flink on k8s的运行模式与实战操作

    Flink 核心是一个流式的数据流执行引擎,并且能够基于同一个 Flink 运行时,提供支持流处理和批处理两种类型应用。其针对数据流的分布式计算提供了数据分布,数据通信及容错机制等功能。 Flink 官网 不同版本的文档 flink on k8s 官方文档 GitHub 地址 官方文档 Flink on yarn 有三

    2024年02月13日
    浏览(52)
  • 云原生之深入解析K8S Istio Gateway服务的架构分析与实战操作

    Istio 提供一种简单的方式来为已部署的服务建立网络,该网络具有负载均衡、服务间认证、监控、网关等功能,而不需要对服务的代码做任何改动。 istio 适用于容器或虚拟机环境(特别是 k8s),兼容异构架构; istio 使用 sidecar(边车模式)代理服务的网络,不需要对业务代

    2024年02月13日
    浏览(59)
  • 【云原生】Dockerfile制作WordPress镜像,实现Compose + K8s编排部署

    大家好,我是秋意零。 😈 CSDN作者主页 😎 博客主页 👿 简介 👻 普通本科生在读 在校期间参与众多计算机相关比赛,如:🌟 “省赛”、“国赛” ,斩获多项奖项荣誉证书 🔥 各个平台, 秋意临 账号创作者 🔥 云社区 创建者 点赞、收藏+关注下次不迷路! 欢迎加入 云社

    2024年02月03日
    浏览(51)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包