我们进行了部署,一切正常,但是当我们试图获取名为index.php的“helloword”php文件时,我们从NGINX服务接收到一个错误403禁止。
所以我尝试进入NGINX pod并手动添加index.php到php项目的根目录(/var/www/html/symfony/public)。当我这样做时,神奇地NGINX返回PHP-FPM脚本,而不是pod中创建的文件。
为了让您理解,我附加了NGINX配置
server {
index index.php index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/symfony/public;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass symfony:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
NGINX服务器使用kubernetes DNS将请求重定向到PHP-FPM服务器
symfony:9000
[编辑]
apiVersion: apps/v1
kind: Deployment
metadata:
name: symfony
namespace: default
labels:
app: symfony
spec:
selector:
matchLabels:
app: symfony
replicas: 1
template:
metadata:
labels:
app: symfony
tier: back
spec:
containers:
- name: symfony
image: gcr.io/myphone-mmpk/symfony:v.80
#TODO: REMOVE THIS
imagePullPolicy: Always
ports:
- containerPort: 9000
resources:
requests:
memory: 16Mi
cpu: 1m
limits:
memory: 128Mi
cpu: 20m
---
kind: Service
apiVersion: v1
metadata:
name: symfony
namespace: default
spec:
selector:
app: symfony
type: NodePort
ports:
- protocol: TCP
port: 9000
targetPort: 9000
这是古8的恩吉恩的显化:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
volumes:
- name: html
emptyDir: {}
- name: nginx
configMap:
name: nginx-configmap
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: nginx
- mountPath: /var/www/html/symfony/public
name: html
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-configmap
namespace: default
data:
default.conf: |
server {
index index.php index.html;
server_name php-docker.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/symfony/public;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass symfony:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
namespace: default
labels:
app: nginx
spec:
scaleTargetRef:
kind: Deployment
name: nginx
apiVersion: apps/v1
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: default
labels:
app: nginx
spec:
ports:
- protocol: TCP
port: 80
selector:
app: nginx
type: LoadBalancer
loadBalancerIP: ~