我试图在kubernates集群AWS EKS上部署一个fastapi应用程序,但是在我部署API之后,当我遇到端点的路径时,我得到了一个494错误,因为它在路径前面添加了一个斜杠
下面是我的示例fastapi代码
@app.get("/ping")
async def ping():
"""Health check"""
response = {
"message": HTTPStatus.OK.phrase,
"status-code": HTTPStatus.OK
}
return response
下面是用于在k8s集群上部署的yaml文件
apiVersion: v1
kind: Service
metadata:
name: fastapi-example
namespace: gpu
labels:
run: fastapi-example
app: fastapi-example
spec:
selector:
app: fastapi-example
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: http
---
apiVersion: getambassador.io/v2
kind: Mapping
name: fastapi-example-mapping
metadata:
name: fastapi-example
namespace: gpu
spec:
prefix: fastapi-example
service: fastapi-example.gpu:8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi-example
namespace: gpu
labels:
app: fastapi-example
spec:
replicas: 1
selector:
matchLabels:
app: fastapi-example
template:
metadata:
labels:
app: fastapi-example
spec:
nodeSelector:
node-type: gpu
containers:
- name: fastapi-example
image: <docker-image-url>
ports:
- containerPort: 8080
protocol: TCP
resources:
requests:
cpu: "0.5"
limits:
cpu: "1"
env:
部署后,当我访问带有端点和路径的URL时,我得到404,当我检查日志时,它在路径前面添加了一个斜杠。例如,当我检查日志时,我得到的是//ping而不是/ping。
另外要注意的是,我已经在同一个集群上部署了一个flask API,具有相同的上述配置,但我能够访问端点和路径-没有得到任何问题,此外,我在集群内测试了api,并能够收到响应,所以我不确定问题出在哪里
1条答案
按热度按时间hfsqlsce1#
您可以使用合并斜杠选项
https://www.getambassador.io/docs/emissary/1.14/topics/running/ambassador#merge-slashes
如果有多余的斜线,它将合并斜线,因此
//ping
为/ping