为了在minikube中的k8s上运行php-fpm应用,我在这里缺少一些kubernetes ingress-nginx配置。
k8s配置文件:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: server-cluster-ip-service
servicePort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: server-cluster-ip-service
spec:
type: ClusterIP
selector:
component: server
ports:
- port: 5000
targetPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 3
selector:
matchLabels:
component: server
template:
metadata:
labels:
component: server
spec:
containers:
- name: server
image: xxx/phpfpm
ports:
- containerPort: 5000
env:
- name: APP_ENV
value: dev
- name: APP_DEBUG
value: '1'
- name: APP_SECRET
value: 74bd83726749616f29166ef53c5f0557
- name: MYSQL_HOST
value: mysql-cluster-ip-service
- name: MYSQL_ROOT_PASSWORD
value: root
- name: MYSQL_DATABASE
value: db
- name: MYSQL_DATABASE_TEST
value: test
- name: MYSQL_USER
value: user
- name: MYSQL_PASSWORD
value: secret
---
apiVersion: v1
kind: Service
metadata:
name: mysql-cluster-ip-service
spec:
type: ClusterIP
selector:
component: mysql
ports:
- port: 3306
targetPort: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
spec:
replicas: 1
selector:
matchLabels:
component: mysql
template:
metadata:
labels:
component: mysql
spec:
volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: database-persistent-volume-claim
containers:
- name: mysql
image: mysql:5.7.22
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-storage
mountPath: /var/lib/mysql
subPath: mysql
env:
- name: MYSQL_HOST
value: mysql-cluster-ip-service
- name: MYSQL_ROOT_PASSWORD
value: root
- name: MYSQL_DATABASE
value: db
- name: MYSQL_USER
value: user
- name: MYSQL_PASSWORD
value: secret
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-persistent-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
在以前的docker开发环境的docker nginx映像上使用的
server {
listen 443 default_server ssl;
root /opt/app/public;
index index.php;
...
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /healthcheck {
return 200 'ok';
add_header Content-Type text/plain;
}
error_page 404 /index.php;
location ~ ^/(index)\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
在浏览器上访问minikube ip时出现502错误。
我已安装 ingress-nginx 并运行以下命令(如其installation guide中所述)
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
$ minikube addons enable ingress
$ make dev-env
我假设我需要以某种方式将根(nginx conf)映射到/ opt / app / public,并以某种方式在ingress-nginx中配置fastcgi_pass,老实说,我仍然对所有的工作方式有些迷惑。
答案 0 :(得分:1)
这可能是以下问题之一。您的进入似乎很好。
您是要在与php容器相同的pod中运行nginx容器吗?在同一容器中运行nginx之后,您必须将fastci_pass
中的“ php”替换为“ 127.0.0.1”。
检查您的pod日志,如果您收到connection refused
,则说明您的php容器有问题,它没有正确暴露端口。尝试对您的php pod进行port-forward
ing操作,看看是否可以通过localhost访问5000。
我看到您在php:9000上有fastcgi_pass
,应该是5000吗?