将 google kubernetes 引擎 (GKE) 公开为服务后无法访问该 IP

Cannot access the IP create by google kubernetes engine (GKE) after exposing it as service

我有一个应用程序,它将在 127.0.0.1:8080 启动服务器并使用 Dockerfile 创建一个映像以将其托管在 GKE 上。我在 kubernetes 集群的 port 8080 上部署了这个应用程序。然后我将服务暴露为 LoadBalancer 相同的端口 8080,但它不允许从外部访问它。所以我为外部访问创建了一个入口,但仍然不起作用。 当我点击 ingress 提供的 IP 时,我得到这个错误:

Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.

请问我在执行过程中有没有遗漏或做错的地方

我的 YAML 文件:

---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "app"
  namespace: "default"
  labels:
    app: "app"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: "app"
  template:
    metadata:
      labels:
        app: "app"
    spec:
      containers:
      - name: "app-sha256-1"
        image: "gcr.io/project-1234/github.com/user/app@sha256:b17b8159668d44fec3d"
---
apiVersion: "autoscaling/v2beta1"
kind: "HorizontalPodAutoscaler"
metadata:
  name: "app-hpa-y3ay"
  namespace: "default"
  labels:
    app: "app"
spec:
  scaleTargetRef:
    kind: "Deployment"
    name: "app"
    apiVersion: "apps/v1"
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: "Resource"
    resource:
      name: "cpu"
      targetAverageUtilization: 80

---
apiVersion: "v1"
kind: "Service"
metadata:
  name: "app-service"
  namespace: "default"
  labels:
    app: "app"
spec:
  ports:
  - protocol: "TCP"
    port: 8080
  selector:
    app: "app"
  type: "LoadBalancer"
  loadBalancerIP: ""

---
apiVersion: "extensions/v1beta1"
kind: "Ingress"
metadata:
  name: "ingress"
  namespace: "default"
spec:
  backend:
    serviceName: "app-service"
    servicePort: 8080

谢谢!期待建议。

start a server at 127.0.0.1:8080 这将允许您的应用仅接受 pod 内的连接。而是绑定到 0.0.0.0

还有你的部署:

...
containers:
  - name: "app-sha256-1"
    image: "gcr.io/project-1234/github.com/user/app@sha256:b17b8159668d44fec3d"
    ports:
    - containerPort: <the port# that your container serves>

您的服务:

...
ports:
- protocol: "TCP"
  port: 8080
  targetPort: <the port that your container serves>