【发布时间】:2021-08-12 13:31:29
【问题描述】:
我有一个在 5000 端口上运行 python 烧瓶应用程序的单副本 pod。下面是我的配置和详细信息。
[ec2-user@ip-172-31-1-120 ~]$ cat tree_management/application/*.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tree-deployment
spec:
selector:
matchLabels:
app: tree-management
replicas: 1
template:
metadata:
labels:
app: tree-management
spec:
containers:
- name: tree-management
image: tree-management
imagePullPolicy: Never
ports:
- containerPort: 5000
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tree-ingress
# annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: local.ec.org
http:
paths:
- path: /tree
pathType: Prefix
backend:
service:
name: tree-service
port:
number: 5000
apiVersion: v1
kind: Service
metadata:
name: tree-service
spec:
# type: NodePort
selector:
app: tree-management
ports:
- protocol: TCP
port: 5000
targetPort: 5000
应用程序在 pod 内运行良好,因为当我在 pod 中执行 kubectl exec 以点击 api url 时,它会给我输出。 下面是一些 kubectl 输出。
[ec2-user@ip-172-31-1-120 ~]$ minikube service list
|----------------------|------------------------------------|--------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|----------------------|------------------------------------|--------------|---------------------------|
| default | kubernetes | No node port |
| default | tree-service | No node port |
| ingress-nginx | ingress-nginx-controller | http/80 | http://192.168.49.2:31893 |
| | | https/443 | http://192.168.49.2:30453 |
| ingress-nginx | ingress-nginx-controller-admission | No node port |
| kube-system | kube-dns | No node port |
| kubernetes-dashboard | dashboard-metrics-scraper | No node port |
| kubernetes-dashboard | kubernetes-dashboard | No node port |
|----------------------|------------------------------------|--------------|---------------------------|
[ec2-user@ip-172-31-1-120 ~]$ kubectl get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 39h
default tree-service ClusterIP 10.99.136.46 <none> 5000/TCP 14m
ingress-nginx ingress-nginx-controller NodePort 10.96.58.167 <none> 80:31893/TCP,443:30453/TCP 21h
ingress-nginx ingress-nginx-controller-admission ClusterIP 10.103.107.214 <none> 443/TCP 21h
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 39h
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.98.246.45 <none> 8000/TCP 39h
kubernetes-dashboard kubernetes-dashboard ClusterIP 10.98.103.55 <none> 80/TCP 39h
[ec2-user@ip-172-31-1-120 ~]$ minikube ip
192.168.49.2
我在本地以及 minikube IP 中添加了主机条目。当我尝试使用 nodeIp 访问我的烧瓶应用程序时,它不起作用。这是我点击 URL 时得到的结果
[ec2-user@ip-172-31-1-120 ~]$ curl http://192.168.49.2/tree
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
下面是来自 nginx 入口的日志
2021/05/24 07:59:44 [error] 298#298: *20007 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: local.ec.org, request: "GET /tree HTTP/1.1", upstream: "http://172.17.0.5:5000/tree", host: "local.ec.org"
2021/05/24 07:59:44 [error] 298#298: *20007 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: local.ec.org, request: "GET /tree HTTP/1.1", upstream: "http://172.17.0.5:5000/tree", host: "local.ec.org"
2021/05/24 07:59:44 [error] 298#298: *20007 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: local.ec.org, request: "GET /tree HTTP/1.1", upstream: "http://172.17.0.5:5000/tree", host: "local.ec.org"
192.168.49.1 - - [24/May/2021:07:59:44 +0000] "GET /tree HTTP/1.1" 502 150 "-" "curl/7.61.1" 84 0.000 [default-tree-service-5000] [] 172.17.0.5:5000, 172.17.0.5:5000, 172.17.0.5:5000 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 bd34da31533e0f3393ff490efe37a90d
也尝试使用以下 CURL 组合,但都失败了。
curl http://local.ec.org:5000
curl http://local.ec.org
curl http://local.ec.org/tree
curl http://local.ec.org/tree -H local.ec.org
curl http://local.ec.org -H local.ec.org
curl http://local.ec.org/ -H local.ec.org
curl http://local.ec.org/tree -H local.ec.org
curl http://192.168.49.2:5000/tree -H Host:local.ec.org
你能帮忙看看这里出了什么问题吗?
更新 1 在进行了一些配置更改后,我可以看到我是否点击了以下 URL,然后请求将发送到 nginx,但不确定为什么它返回 502 bad gateway。
curl http://local.ec.org/tree
Nginx 错误。不知道为什么nginx连接不上上游?
2021/05/24 13:01:58 [error] 447#447: *168693 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: local.ec.org, request: "GET /tree HTTP/1.1", upstream: "http://172.17.0.5:5000/tree", host: "local.ec.org"
192.168.49.1 - - [24/May/2021:13:01:58 +0000] "GET /tree HTTP/1.1" 502 150 "-" "curl/7.61.1" 84 0.001 [default-tree-service-5000] [] 172.17.0.5:5000, 172.17.0.5:5000, 172.17.0.5:5000 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 dff2ca8a83f9d2237300b6d46f978e43
2021/05/24 13:01:58 [error] 447#447: *168693 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: local.ec.org, request: "GET /tree HTTP/1.1", upstream: "http://172.17.0.5:5000/tree", host: "local.ec.org"
2021/05/24 13:01:58 [error] 447#447: *168693 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: local.ec.org, request: "GET /tree HTTP/1.1", upstream: "http://172.17.0.5:5000/tree", host: "local.ec.org"
【问题讨论】:
-
你试过
http://192.168.49.2:31893/tree吗?那是 minikube 实际给你的 URL。 -
@coderanger 是的,刚刚尝试过,但 nginx 给出了 404 ..
-
嗨@AshifNataliya,我可以看到你的
ingress nginx-controller。你用minikube tunnel了吗?如果你想在 Minikube 中有入口控制器,你可以通过命令添加minikube ingress:minikube addons enable ingress。启用入口插件后,特别说明:After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "127.0.0.1"。看类似的问题here。 -
@MikołajGłodziak 是的,我已经启用了入口插件。我以前没有运行过 minikube 隧道。我刚试过,但没有帮助。也尝试使用 127.0.0.1 卷曲,但仍然失败
-
502 表示没有准备好的 pod。检查您的 pod 是否在启动时崩溃。
标签: python nginx flask kubernetes minikube