K8S php+nginx(单pod)
k8s
·
本文内容全由网上整理,如有错误请自行处理
单pod
是将php+nginx都放到一个pod,docker镜像请参考上一篇
ConfigMap
配置文件
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-php-config
labels:
tier: backend
data:
config : |
server {
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Deployment
pod配置
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-php-demo
labels:
app: nginx-php-demo
tier: backend
spec:
replicas: 1
selector:
matchLabels:
app: nginx-php-demo
tier: backend
template:
metadata:
labels:
app: nginx-php-demo
tier: backend
spec:
enableServiceLinks: false
volumes:
- name: nginx-php-vol #直接这里弄个跟随pod的存储卷,不需要单独建存储卷了
emptyDir: {}
- name: nginx-cnfig-vol
configMap:
name: nginx-php-config
items:
- key: config
path: site.conf
containers:
- name: php-demo
image: laravel-php
imagePullPolicy: Never
volumeMounts:
- name: nginx-php-vol
mountPath: /code
lifecycle:
postStart:
exec:
command: [ "/bin/sh", "-c", "cp -r /var/www/html/. /code" ]
- name: nginx
image: nginx:1.21.0
ports:
- containerPort: 80
volumeMounts:
- name: nginx-php-vol
mountPath: /code
- name: nginx-cnfig-vol
mountPath: /etc/nginx/conf.d
Service
配置文件
apiVersion: v1
kind: Service
metadata:
name: php-nginx-service
labels:
app: php-nginx-service
tier: backend
spec:
type: NodePort
selector:
app: nginx-php-demo
tier: backend
ports:
- protocol: TCP
port: 80
相比双pod 简洁了不少,这也是绝大多数推荐的方式,不符合单一原则,但是谁让phpfpm+nginx
本身就不合规矩呢
更多推荐
已为社区贡献4条内容
所有评论(0)