在kubernetes上通过入口inginx公开服务时,请求时唯一的http响应代码是200。
web应用程序基本上是一个表单,上传图像,将它们存储在某个地方,并根据代码进行响应(例如,错误的请求,或在标题中使用URI位置创建)。它期望在接口地址上有一个包含multipart/form-data的请求,如下所示:"http://{anyAddress}/api/images?directory={whereToStore}?processing={someProcessingTags}“
web应用程序在本地的工作方式与预期相同,并且作为docker上的单个容器。
因此,当通过入口访问服务时,它首先按照预期使用表单进行响应。您可以指定设置和要上传的图像。在发送请求时,文件被正确上传到web应用程序并进行处理,然后web应用程序发送预期创建的201,但返回给浏览器的响应始终为200 OK。我不知道为什么。
这是在本地运行的桌面+ kubernetes服务器的docker上。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/proxy-body-size: 25m
spec:
rules:
- http:
paths:
- path: /image-upload
backend:
serviceName: image-upload-service
servicePort: http
---
apiVersion: v1
kind: Service
metadata:
name: image-upload-service
spec:
type: LoadBalancer
selector:
run: image-upload
ports:
- name: http
port: 80
targetPort: api
protocol: TCP
- name: https
port: 443
targetPort: api
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: image-upload-cluster
labels:
run: image-upload
spec:
selector:
matchLabels:
run: image-upload
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 0
template:
metadata:
labels:
run: image-upload
spec:
volumes:
- name: shared-volume
hostPath:
path: /exports
containers:
- name: image-upload
image: calyxa/image-service
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /exports
name: shared-volume
resources:
requests:
cpu: 10m
ports:
- containerPort: 3000
name: api
readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1我希望在发送带有图像文件的请求时,根据状态代码得到响应,即400个错误请求或201个已创建(在标头中有一个位置)。
响应总是200OK,即使web应用程序因为请求而崩溃。
如果web应用程序本身没有运行(例如,因为它崩溃了),我得到一个503服务不可用,正如预期的那样。
发布于 2019-05-17 22:56:15
天哪,我整天都在试着解决这个问题,并在发布了我的问题后找到了解决方案。因此,为了传递api调用中的参数(在http地址中),确实需要这样设置入口重写目标规则:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/proxy-body-size: 25m
#nginx.ingress.kubernetes.io/ingress.class: public
spec:
rules:
- http:
paths:
- path: /image-upload/?(.*)
backend:
serviceName: image-upload-service
servicePort: http有趣的是
rewrite-target: /$1和
path: /image-upload/?(.*)希望这对其他人有帮助。干杯!
https://stackoverflow.com/questions/56188598
复制相似问题