为什么这个Kubernetes Ingress不接受流量?

时间:2019-09-25 20:06:37

标签: ssl kubernetes kubernetes-ingress

我正在尝试在Kubernetes上设置一个简单的HTTP Web服务器,并使用临时外部IP公开它。但是,当启动它并尝试访问位于x.x.x.x/something的URL之一时,我得到:

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

我的配置很简单:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: gcr.io/my-repo-name
        ports:
        - containerPort: 8080
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
        readinessProbe:
          initialDelaySeconds: 10
          httpGet:
            path: /healthz
            port: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: web-balancer-service
spec:
  selector:
    app: web
  type: NodePort
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 32111
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress-app
spec:
  backend:
    serviceName: web-balancer-service
    servicePort: 8080

如果描述 ingress ,我会发现后端是“未知”。我的规格有问题吗?

Name:             my-ingress-app
Namespace:        default
Address:          x.x.x.x
Default backend:  web-balancer-service:8080 (10.60.0.57:32111)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *     *     web-balancer-service:8080 (10.60.0.57:32111)
Annotations:
  ingress.kubernetes.io/backends:         {"k8s-be-30330--f4bbd8cbe40f4567":"Unknown"}
  ingress.kubernetes.io/forwarding-rule:  k8s-fw-default-my-ingress-app--f4bbd8cbe40f4567
  ingress.kubernetes.io/target-proxy:     k8s-tp-default-my-ingress-app--f4bbd8cbe40f4567
  ingress.kubernetes.io/url-map:          k8s-um-default-my-ingress-app--f4bbd8cbe40f4567
Events:
  Type    Reason  Age    From                     Message
  ----    ------  ----   ----                     -------
  Normal  ADD     7m18s  loadbalancer-controller  default/my-ingress-app
  Normal  CREATE  6m12s  loadbalancer-controller  ip: x.x.x.x

1 个答案:

答案 0 :(得分:2)

您收到的错误消息是来自Google Kubernetes Engine(GKE)的错误,因此我假设您正在Google Cloud的GKE中运行。

首先,确保容器(部署的荚)实际上正在侦听端口32111。您将其作为服务上的targetPort,这意味着该服务将在端口8080上接收流量,但会将其发送到与其匹配的Pod的端口32111。看起来像:

--(traffic)---> :8080 (service) ---> :32111 (pods)

我对此表示怀疑,因为在您的广告连播规范中,您有containerPort: 8080,这表明广告连播实际上也在听8080,而不是32111

因此,首先,尝试将服务的targetPort也更改为8080

给它一些时间后,如果它不能开始工作,请检查集群中是否确实启用了HTTP负载平衡。在Google Cloud Console上创建集群时,如下所示: screenshot

在现有群集上,在GCP控制台上转到其详细信息,然后检查插件部分:

addons