kubernetes-nginx+php访问集群外mysql部署wordpress
Posted 南北二斗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubernetes-nginx+php访问集群外mysql部署wordpress相关的知识,希望对你有一定的参考价值。
一、配置nginx的configmap
apiVersion v1
kind ConfigMap
metadata
name nginx-config
data
default
server
listen 80;
server_name localhost;
location /
root /usr/share/nginx/html;
index index.html index.htm index.php;
error_page 500 502 503 504 /50x.html;
location = /50x.html
root /var/www/html;
location ~ \\.php$
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
location ~ /\\.ht
deny all;
二、创建nginx+php(nginx和php在同一个pod下)
apiVersion apps/v1
kind Deployment
metadata
name nginx-php-deployment
spec
selector
matchLabels
app nginx-php-deployment
replicas1
template
metadata
labels
app nginx-php-deployment
spec
containers
name php
image registry.cn-shenzhen.aliyuncs.com/user-sum/php
imagePullPolicy IfNotPresent
ports
containerPort9000
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
containerPort80
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
port80
# nodePort: 80
targetPort80
四、创建endpoint和service连接集群外mysql
apiVersion v1
kind Endpoints
metadata
name mysql-external
namespace default
subsets
addresses
ip172.17.138.251
# - ip: 172.29.9.52
ports
name mysql
port3306
protocol TCP
notReadyAddresses
ip172.17.138.252
---
apiVersion v1
kind Service
metadata
name mysql-external
namespace default
spec
type ClusterIP
ports
name mysql
port3306
targetPort3306
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
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demoapp-nodeport-svc123 NodePort 10.1.69.83 <none> 80:30937/TCP 2d6h
kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 23d
mysql-external ClusterIP 10.1.219.34 <none> 3306/TCP 2d5h
nginx-php-svc NodePort 10.1.0.141 <none> 80:20375/TCP 33h
http://ip:20375/index.php
以上是关于kubernetes-nginx+php访问集群外mysql部署wordpress的主要内容,如果未能解决你的问题,请参考以下文章
关于Kubernetes中如何优雅的访问集群外服务的一些笔记
访问 k8 minikube 集群外的 kafka broker
Hadoop集群以外的机器如何访问Hadoop集群,进行提交文件,下载文件?