k8s实战案例之运行WordPress
1、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镜像目录文件
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镜像
2.2、准备nginx-wordpress镜像
2.2.1、nginx-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目录文件
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镜像
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镜像
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测试页
能够正常访问到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界面初始化数据库
这里的数据库主机需要填写mysql svc名称.名称空间名称;如果你的mysql是主从架构,这里就需要填写主库的svc名称.名称空间;
页面提示不错,这里表示我们写的mysql主机地址正常;点击现在安装即可;
填写好站点名称,用户名密码 点击安装wordpress即可;
能够看到成功,表示wordpress初始化成功;填写我们刚才设置的密码点击登录即可;
5、验证k8s中MySQL数据
5.1、验证master数据
5.2、验证slave数据
k8s实战案例之运行WordPress的更多相关文章
- HTML+CSS小实战案例
HTML+CSS小实战案例 登录界面的美化,综合最近所学进行练习 网页设计先布局,搭建好大框架,然后进行填充,完成页面布局 <html> <head> <meta htt ...
- python实战案例--银行系统
stay hungry, stay foolish.求知若饥,虚心若愚. 今天和大家分享一个python的实战案例,很多人在学习过程中都希望通过一些案例来试一下,也给自己一点动力.那么下面介绍一下这次 ...
- 如何从40亿整数中找到不存在的一个 webservice Asp.Net Core 轻松学-10分钟使用EFCore连接MSSQL数据库 WPF实战案例-打印 RabbitMQ与.net core(五) topic类型 与 headers类型 的Exchange
如何从40亿整数中找到不存在的一个 前言 给定一个最多包含40亿个随机排列的32位的顺序整数的顺序文件,找出一个不在文件中的32位整数.(在文件中至少确实一个这样的数-为什么?).在具有足够内存的情况 ...
- 阿里云云主机swap功能设置实战案例
阿里云云主机swap功能设置实战案例 阿里云提供的云服务器(Elastic Compute Service,简称 ECS),是云主机的一种,当前采用的虚拟化驱动是Xen(这一点可以通过bios ven ...
- 基于SpringCloud的Microservices架构实战案例-架构拆解
自第一篇< 基于SpringCloud的Microservices架构实战案例-序篇>发表出来后,差不多有半年时间了,一直也没有接着拆分完,有如读本书一样,也是需要契机的,还是要把未完成的 ...
- Flume实战案例运维篇
Flume实战案例运维篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Flume概述 1>.什么是Flume Flume是一个分布式.可靠.高可用的海量日志聚合系统,支 ...
- Salesforce学习之路-developer篇(五)一文读懂Aura原理及实战案例分析
1. 什么是Lightning Component框架? Lightning Component框架是一个UI框架,用于为移动和台式设备开发Web应用程序.这是一个单页面Web应用框架,用于为Ligh ...
- Ubuntu系统部署tomcat并启用JMX实战案例
Ubuntu系统部署tomcat并启用JMX实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装JDK环境 1>.更换阿里云的软件源 [root@zabbix_g ...
- 基于Ambari Server部署HDP集群实战案例
基于Ambari Server部署HDP集群实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.部署Ambari Server端 博主推荐阅读: https://www.c ...
- K8S实战-构建Django项目-03-使用共享存储
上篇博文,发布之后,正好跟着双十一,不知道大家剁手了没~~.好啦,言归正传先声明一下,每周1,3,5更新教程,大家如果想要了解更多的教程可以重温一下之前的教程或者,关注崔格拉斯 公众号,大家想要源码的 ...
随机推荐
- 2021-05-22:假设所有字符都是小写字母, 大字符串是str,arr是去重的单词表, 每个单词都不是空字符串且可以使用任意次。使用arr中的单词有多少种拼接str的方式。 返回方法数。
2021-05-22:假设所有字符都是小写字母, 大字符串是str,arr是去重的单词表, 每个单词都不是空字符串且可以使用任意次.使用arr中的单词有多少种拼接str的方式. 返回方法数. 福大大 ...
- 如何借助Kafka持久化存储K8S事件数据?
大家应该对 Kubernetes Events 并不陌生,特别是当你使用 kubectl describe 命令或 Event API 资源来了解集群中的故障时. $ kubectl get even ...
- 2014年蓝桥杯C/C++大学B组省赛真题(蚂蚁感冒)
题目描述: 长100厘米的细长直杆子上有n只蚂蚁.它们的头有的朝左,有的朝右. 每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒.当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行.这些蚂蚁中,有1只蚂蚁 ...
- javascript中的错误类型
javascript 中的错误类型: SyntaxError TypeError ReferenceError RangeError URLError Error SyntaxError 语法错误 / ...
- 巧用OpenSSH进行域内权限维持
最近在Windows服务器上安装OpenSSH,意外发现了一个很有意思的技巧,可用来做域内权限维持,废话不多说,直接上步骤. 01.利用方式 (1)在已经获得权限的Windows服务器上,使用msie ...
- Could not resolve com.android.tools.lint:lint-kotlin:26.2.0.
好久没有使用weexplus publish android 打包apk, 今一运行失败了,提示Could not resolve com.android.tools.lint:lint-kotlin ...
- 整合vxgPlayer使chrome支持vxg_media_player播放rtsp视频
目前有一个关于接入海康监控进行视频融合的项目需求,按理说在前端技术发展如此迅速的今天,使用web播放一个视频应该是不算什么难事,只是万事都有意外,因很多视频厂家的监控数据都不是普通的mp4啥的,所以使 ...
- @Override注解的使用
先看看@Override注解在Java SE中的声明: package .lang; import java.lang.annotation.*; @Target(ElementType.METHOD ...
- pcie reset系列之 内核框架
FLR是pci reset的一种. 关于FLR的寄存器操作比较简单, 相关的寄存器有: 配置空间里device cap里的FLR capability bit, 这个表示设备是否支持FLR. 配置空间 ...
- 【智能安防】基于AI的智能家居安全系统设计与实现
目录 智能家居安全系统设计与实现:AI技术的应用 摘要 随着智能家居市场的快速发展,安全问题也日益突出.本文将介绍基于AI的智能家居安全系统设计与实现技术,重点阐述相关概念.实现步骤和优化改进.通过实 ...