kubernetes-nginx+php访问集群外mysql部署wordpress

【kubernetes-nginx+php访问集群外mysql部署wordpress】实践是知识的母亲,知识是生活的明灯。这篇文章主要讲述kubernetes-nginx+php访问集群外mysql部署wordpress相关的知识,希望能为你提供帮助。
一、配置nginx的configmap

apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
default: |
server
listen80;
server_namelocalhost;

location /
root/usr/share/nginx/html;
indexindex.html index.htm index.php;


error_page500 502 503 504/50x.html;
location = /50x.html
root/var/www/html;


location ~ \\.php$
root/usr/share/nginx/html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;


location ~ /\\.ht
denyall;


二、创建nginx+php(nginx和php在同一个pod下)
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-php-deployment
spec:
selector:
matchLabels:
app: nginx-php-deployment
replicas: 1
template:
metadata:
labels:
app: nginx-php-deployment
spec:
containers:
- name: php
image: registry.cn-shenzhen.aliyuncs.com/user-sum/php
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9000
volumeMounts:
- name: nginxpath
#mountPath: /var/www/html/
mountPath: /usr/share/nginx/html
- name: nginx
#image: registry.cn-shenzhen.aliyuncs.com/user-sum/alpine:nginx1.18.0
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: nginxpath
mountPath: /usr/share/nginx/html
- name: nginx-config
mountPath: /etc/nginx/conf.d/
volumes:
- name: nginx-config
configMap:
name: nginx-config
items:
- key: default
path: default.conf
- name: nginxpath
hostPath:
path: /root/nginxpath

三、创建nginx的service
kind: Service
apiVersion: v1
metadata:
name: nginx-php-svc
spec:
type: NodePort
selector:
app: nginx-php-deployment
ports:
- name: http
protocol: TCP
port: 80
#nodePort: 80
targetPort: 80

四、创建endpoint和service连接集群外mysql
apiVersion: v1
kind: Endpoints
metadata:
name: mysql-external
namespace: default
subsets:
- addresses:
- ip: 172.17.138.251
#- ip: 172.29.9.52
ports:
- name: mysql
port: 3306
protocol: TCP
notReadyAddresses:
- ip: 172.17.138.252
---
apiVersion: v1
kind: Service
metadata:
name: mysql-external
namespace: default
spec:
type: ClusterIP
ports:
- name: mysql
port: 3306
targetPort: 3306
protocol: TCP

五、部署wordpress
1、下载wordpress源码
下载,也可wget去网上下载
链接:https://pan.baidu.com/s/1XPL5YOystz7HXlSpt3YpBg
提取码:wxi4

2、部署
cd /root/nginxpath/
tar -zxvf wordpress-5.0.1-zh_CN.tar.gz
mv wordpress/* /root/nginxpath/

3、通过nodeport 20375访问(记得防火墙开放端口)
[root@nginxpath]# kubectl get svc
NAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
demoapp-nodeport-svc123NodePort10.1.69.83< none> 80:30937/TCP2d6h
kubernetesClusterIP10.1.0.1< none> 443/TCP23d
mysql-externalClusterIP10.1.219.34< none> 3306/TCP2d5h
nginx-php-svcNodePort10.1.0.141< none> 80:20375/TCP33h

http://ip:20375/index.php


    推荐阅读