【问题标题】:Bad Service/502 Bad Gateway in minikubeminikube 中的错误服务/502 错误网关
【发布时间】:2019-12-01 21:39:40
【问题描述】:

鉴于以下 K8s 资源(部署/pod、服务、入口),我希望在浏览器中访问 https://staging-micro.local/ 时看到请求回显给我。我得到的是502 Bad Gateway

# describe deployment (trunc. to show only containers)
Containers:
   cloudsql-proxy:
    Image:      gcr.io/cloudsql-docker/gce-proxy:1.11
    Port:       <none>
    Host Port:  <none>
    Command:
      /cloud_sql_proxy
      -instances=myproject:us-central1:project-staging=tcp:5432
      -credential_file=/secrets/cloudsql/credentials.json
    Environment:  <none>
    Mounts:
      /secrets/cloudsql from cloudsql-instance-credentials-volume (ro)
   adv-api-django:
    Image:      gcr.io/google_containers/echoserver:1.9
    Port:       8000/TCP
    Host Port:  0/TCP
    Environment:


# describe service
Name:                     staging-adv-api-service
Namespace:                staging
Labels:                   app=adv-api
                          platformRole=api
                          tier=backend
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"adv-api","platformRole":"api","tie...
Selector:                 app=adv-api-backend,platformRole=api,tier=backend
Type:                     LoadBalancer
IP:                       10.103.67.61
Port:                     http  80/TCP
TargetPort:               8000/TCP
NodePort:                 http  32689/TCP
Endpoints:                172.17.0.14:8000,172.17.0.6:8000,172.17.0.7:8000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>


# describe ingress
Name:             staging-api-ingress
Namespace:        staging
Address:          10.0.2.15
Default backend:  default-http-backend:80 (172.17.0.12:8080)
Rules:
  Host                 Path  Backends
  ----                 ----  --------
  staging-micro.local  
                       /   staging-adv-api-service:http (172.17.0.14:8000,172.17.0.6:8000,172.17.0.7:8000)

请注意,我在主机(运行 minikube)上的 /etc/hosts 中有条目 192.168.99.100 staging-micro.local,这是正确的 minikube ip。如果我删除该服务,点击staging-micro.local/ 会给出默认后端的404 Not Found 响应。

我的期望是 Ingress 将主机名 staging-micro.local 和路径 / 映射到正在侦听端口 80 的服务。然后该服务将请求转发到端口 8000 上的 3 个选定容器之一。 echoserver 容器正在侦听端口 8000,并返回一个 HTTP 响应,其中请求作为其主体。当然,实际情况并非如此。

最后,cloudsql-proxy 容器:此时不应涉及此内容,但我将其包括在内,因为我想在存在 sidecar 容器时验证服务是否正常工作。然后我可以将echoserver 换成我的主应用程序容器。我已经删除了echoserver 进行了测试,并得到了相同的结果。

日志显示echoserver 正在正常启动。

我无法找到任何更全面的 echoserver 文档,所以我不是 100% 了解它正在侦听的端口。

【问题讨论】:

    标签: kubernetes containers minikube kubernetes-ingress kubernetes-service


    【解决方案1】:

    我猜你使用了错误的echoserver:1.9 目标容器端口,因为它默认响应8080 端口。看看这个example

    我已经在我的环境中对其进行了测试,在8080 端口上成功地响应了容器。

    【讨论】:

    • 这似乎是正确的。我猜我对容器的行为持乐观态度
    猜你喜欢
    • 1970-01-01
    • 2019-06-07
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多