一个pod下的mysql和wordpress
apiVersion: v1
kind: Pod
metadata:
name: wp-mysql57
namespace: default
labels:
web: wp
spec:
volumes:
- name: mysql-data
hostPath:
path: /data/mysql
- name: wp-data
hostPath:
path: /data/wp
containers:
- name: mysql57
image: mysql:5.7
imagePullPolicy: IfNotPresent
env:
- name: MYSQL_ROOT_PASSWORD
value: '123'
- name: MYSQL_DATABASE
value: 'wordpress'
- name: MYSQL_USER
value: 'wp_user'
- name: MYSQL_PASSWORD
value: '123'
args:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
- name: wp
image: wordpress
imagePullPolicy: IfNotPresent
env:
- name: WORDPRESS_DB_HOST
value: '127.0.0.1'
- name: WORDPRESS_DB_USER
value: 'wp_user'
- name: WORDPRESS_DB_PASSWORD
value: '123'
- name: WORDPRESS_DB_NAME
value: 'wordpress'
volumeMounts:
- name: wp-data
mountPath: /var/www/html
##### 执行上述资源清单
### 找出 IP
[root@master kubernetes]# kubectl get pod -o wide
NAME READY RESTARTS AGE IP NODE NOMINATED NODE
wp-mysql57 2/2 0 70m 10.2.3.17 node03 <none>
nginx-565785f75c-hn9ql 1/1 0 106m 10.2.3.13 node03 <none>
### 利用集群做出反向代理
[root@node02 ~]# yum install nginx -y
[root@node02 ~]# rm /etc/nginx/conf.d/*
[root@node02 ~]# vim /etc/nginx/conf.d/wp。conf
server {
listen 80;
server_name _;
location / {
proxy_pass http://10.2.3.17:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 可选:如果你需要处理WebSocket连接
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 其他代理设置...
}
# 其他location块...
# 错误页面处理
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
### 启动nginx
systemctl start nginx
浏览器访问10.0.0.202