WordPress是一款免费开源的内容管理系统(CMS),它是使用PHP语言和MySQL数据库开发的,用户可以在支持 PHP 和 MySQL数据库的服务器上使用自己的博客。
(1)WordPress如今已经占据全球web的35%以上了。
(2)WordPress适合海外买家的使用习惯。
(3)WordPress容易获取谷歌排名。
(4)WordPress针对移动用户进行了优化。
(5)WordPress安全可靠。
(6)安装简单、操作方便。
商业网站
电子商务商店
博客
作品集网站
简历
论坛
社交网络
会员网站
……
[root@k8s-master ~]# kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 3d16h v1.23.1 192.168.3.201 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node01 Ready <none> 3d16h v1.23.1 192.168.3.202 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node02 Ready <none> 3d16h v1.23.1 192.168.3.203 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
yum install -y nfs-utils
mkdir -p /nfs/data
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
exportfs -r
systemctl enable --now rpcbind
systemctl enable --now nfs-server
service rpcbind stop
service nfs stop
service rpcbind start
service nfs start
[root@k8s-node01 ~]# showmount -e 192.168.3.201
Export list for 192.168.3.201:
/nfs/data *
[root@k8s-master ~]# kubectl create namespace wordpress
namespace/wordpress created
mkdir -p /nfs/data/wordpressdb
[root@k8s-master wordpress]# cat wordpressdb.yaml
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: wordpressdb-pv
spec:
capacity: #创建存储的大小
storage: 10Gi
volumeMode: Filesystem #存储的类型
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /nfs/data/wordpressdb
server: 192.168.3.201
mountOptions:
- hard
- nfsvers=4.1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpressdb-pvc
namespace: wordpress
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem #存储类型 ,块存储Block
resources:
requests:
storage: 8Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: wordpressdb
name: wordpressdb
namespace: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpressdb
strategy: {}
template:
metadata:
labels:
app: wordpressdb
spec:
volumes:
- name: wordpressdb-data
persistentVolumeClaim:
claimName: wordpressdb-pvc
containers:
- image: mysql:5.7
name: mysql
ports:
- name: mysql
containerPort: 3306
protocol: TCP
volumeMounts:
- name: wordpressdb-data
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: wordpress
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wordpress
- name: MYSQL_PASSWORD
value: wordpress
resources:
requests:
cpu: 0.1
memory: 128Mi
limits:
cpu: 0.3
memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: wordpressdb
name: wordpressdb
namespace: wordpress
spec:
clusterIP: 10.110.221.111
ports:
- name: 3306-3306
port: 3306
protocol: TCP
targetPort: 3306
selector:
app: wordpressdb
type: ClusterIP
status:
loadBalancer: {}
[root@k8s-master wordpress]# kubectl apply -f wordpressdb.yaml
persistentvolume/wordpressdb-pv created
persistentvolumeclaim/wordpressdb-pvc created
deployment.apps/wordpressdb created
service/wordpressdb created
[root@k8s-master wordpress]# kubectl get pods -n wordpress
NAME READY STATUS RESTARTS AGE
wordpressdb-54745c765-gtv79 1/1 Running 0 2m8s
[root@k8s-master ~]# kubectl get svc -n wordpress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpressdb ClusterIP 10.110.221.111 <none> 3306/TCP 38s
[root@k8s-master wordpress]# mysql -uwordpress -pwordpress -h10.110.221.111
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 5
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)]>
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wordpress |
+--------------------+
2 rows in set (0.01 sec)
[root@k8s-master wordpress]# cat wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: wordpress
name: wordpress
namespace: wordpress
spec:
replicas: 2
selector:
matchLabels:
app: wordpress
strategy: {}
template:
metadata:
labels:
app: wordpress
spec:
containers:
- image: wordpress:php8.0-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: 10.110.221.111
- name: WORDPRESS_DB_USER
value: root
- name: WORDPRESS_DB_PASSWORD
value: wordpress
- name: WORDPRESS_DB_NAME
value: wordpress
resources: {}
~
---
apiVersion: v1
kind: Service
metadata:
labels:
app: wordress
name: wordress
namespace: wordpress
spec:
ports:
- name: 80-80
port: 80
protocol: TCP
targetPort: 80
nodePort: 30088
selector:
app: wordpress
type: NodePort
status:
loadBalancer: {}
[root@k8s-master wordpress]# kubectl apply -f wordpress.yaml
[root@k8s-master wordpress]# kubectl get pods -n wordpress
NAME READY STATUS RESTARTS AGE
wordpress-7db67c5bd8-7nblw 1/1 Running 0 9s
wordpress-7db67c5bd8-hfc86 1/1 Running 0 9s
wordpressdb-54745c765-gtv79 1/1 Running 0 4m33s
[root@k8s-master ~]# kubectl get svc -n wordpress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpressdb ClusterIP 10.110.221.111 <none> 3306/TCP 4m53s
wordress NodePort 10.109.18.248 <none> 80:30088/TCP 29s
http://192.168.3.202:30088