k8s实战之k8s+wordpress
8), 创建wordpress-deployment.yaml。5), 创建mysql-deployment.yaml。7),创建 wordpress-pvc.yaml。6),创建wordpress-pv.yaml。2),在NFSmaster节点执行以下指令。4), 创建 mysql-pvc.yaml。10),创建ns wordpress。3),创建mysql-pv.yaml。9),创建wp-sv
一,准备环境:
参考以往文章
二,部署:
1),各个节点安装NFS
yum install nfs-utils -y
2),在NFSmaster节点执行以下指令
systemctl enable nfs-server && systemctl start nfs-server
mkdir -p /kube/mysql-db/conf
mkdir -p /kube/mysql-db/data
mkdir -p /kube/mysql-db/logs
mkdir -p /kube/wordpress/www
mkdir -p /kube/wordpress/log
echo "/kube/mysql-db 192.168.142.0/24(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports
echo "/kube/wordpress 192.168.142.0/24(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports
其余节点挂载
3),创建mysql-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-data
labels:
app: mysql-data
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /kube/mysql-db/data
server: 192.168.142.158---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-conf
namespace: wordpress
labels:
app: mysql-conf
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /kube/mysql-db/conf
server: 192.168.142.158---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-logs
namespace: wordpress
labels:
app: mysql-logs
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /kube/mysql-db/logs
server: 192.168.142.158
4), 创建 mysql-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-pv-data-claim
namespace: wordpress
labels:
app: mysql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
selector:
matchLabels:
app: mysql-data
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-pv-conf-claim
namespace: wordpress
labels:
app: mysql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
selector:
matchLabels:
app: mysql-conf
---kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-pv-logs-claim
namespace: wordpress
labels:
app: mysql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
selector:
matchLabels:
app: mysql-logs
5), 创建mysql-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mysql
namespace: wordpress
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-pv-data
mountPath: /var/lib/mysql
- name: mysql-pv-conf
mountPath: /etc/mysql/conf.d
- name: mysql-pv-logs
mountPath: /logs
volumes:
- name: mysql-pv-data
persistentVolumeClaim:
claimName: mysql-pv-data-claim
- name: mysql-pv-conf
persistentVolumeClaim:
claimName: mysql-pv-conf-claim
- name: mysql-pv-logs
persistentVolumeClaim:
claimName: mysql-pv-logs-claim
6),创建wordpress-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: wp-pv-www
labels:
app: wordpress-www
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /kube/wordpress/www
server: 192.168.142.158
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: wp-pv-log
namespace: wordpress
labels:
app: wordpress-log
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /kube/wordpress/log
server: 192.168.142.158
7),创建 wordpress-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: wp-pv-www-claim
namespace: wordpress
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
selector:
matchLabels:
app: wordpress-www
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: wp-pv-log-claim
namespace: wordpress
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
selector:
matchLabels:
app: wordpress-log
8), 创建wordpress-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
namespace: 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: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: wp-pv-www
mountPath: /var/www/html
- name: wp-pv-log
mountPath: /logvolumes:
- name: wp-pv-log
persistentVolumeClaim:
claimName: wp-pv-log-claim
- name: wp-pv-www
persistentVolumeClaim:
claimName: wp-pv-www-claim
9),创建wp-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
namespace: wordpress
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
namespace: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
nodePort: 30011
selector:
app: wordpress
tier: frontend
type: NodePort
10), 修改wp-config-sample.php
cd /data/docker/www/wordpress/
vim wp-config-sample.php
修改wp-db.php文件,将mysql_connect替换为mysqli_connect
sed -i "s/mysql_connect/mysqli_connect/g" wp-includes/wp-db.php
复制wp-config-sample.php为wp-config.php
cp wp-config-sample.php wp-config.php
11),创建ns wordpress
kubectl create ns wordpress
12),执行刚才创建的文件
kubectl apply -f ./
kubectl create secret generic mysql-pass --from-literal='password=Nebula@123'
echo -e "[mysqld]\ndefault-authentication-plugin=mysql_native_password" >> /data/docker/mysql/conf/docker_mysql.cnf
13),查看创建结果
kubectl get pvc,pv,deploy,pod,svc -n wordpress -o wide
14),浏览器访问
更多推荐
所有评论(0)