简体   繁体   English

kubernetes (GKE) nginx 入口看起来很好,但不起作用

[英]kubernetes (GKE) nginx ingress looks fine but does not work

I followed this guide to install the nginx ingress controller in the GKE.我按照本指南在 GKE 中安装 nginx 入口 controller。

Afterwards I followed this guide to create the ingress resource for my service.之后,我按照本指南为我的服务创建了入口资源。

I already setup my test app and service succesfully.我已经成功设置了我的测试应用程序和服务。 Tested this by port-forwarding to the container.通过端口转发到容器对此进行了测试。

Setting up the ingress seemed fine but I can't get access to it.设置入口似乎很好,但我无法访问它。 When opening the external ip the following 502 error is print:打开外部 ip时打印以下 502 错误:

Error: Server Error错误:服务器错误

The server encountered a temporary error and could not complete your request.服务器遇到临时错误,无法完成您的请求。

Please try again in 30 seconds.请在 30 秒后重试。

Please see the describe of the ingress:请参阅入口的describe

│Name:         teamcity                                                                                                                           │
│Namespace:    default                                                                                                                            │
│Labels:       <none>                                                                                                                             │
│Annotations:  ingress.kubernetes.io/backends: {"k8s-be-31984--b5c10175cf4f125b":"UNHEALTHY"}                                                     │
│              ingress.kubernetes.io/forwarding-rule: k8s-fw-default-teamcity--b5c10175cf4f125b                                                   │
│              ingress.kubernetes.io/target-proxy: k8s-tp-default-teamcity--b5c10175cf4f125b                                                      │
│              ingress.kubernetes.io/url-map: k8s-um-default-teamcity--b5c10175cf4f125b                                                           │
│              kubectl.kubernetes.io/last-applied-configuration:                                                                                  │
│                {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"teamcity","namespace":"default"},"spec":│
│{"backend...                                                                                                                                     │
│API Version:  extensions/v1beta1                                                                                                                 │
│Kind:         Ingress                                                                                                                            │
│Metadata:                                                                                                                                        │
│  Creation Timestamp:  2019-11-02T12:49:21Z                                                                                                      │
│  Generation:          1                                                                                                                         │
│  Resource Version:    553521                                                                                                                    │
│  Self Link:           /apis/extensions/v1beta1/namespaces/default/ingresses/teamcity                                                            │
│  UID:                 312aa230-fd6f-11e9-ad91-42010a84009d                                                                                      │
│Spec:                                                                                                                                            │
│  Backend:                                                                                                                                       │
│    Service Name:  teamcity                                                                                                                      │
│    Service Port:  8111                                                                                                                          │
│Status:                                                                                                                                          │
│  Load Balancer:                                                                                                                                 │
│    Ingress:                                                                                                                                     │
│      Ip:  35.190.86.15                                                                                                                          │
│Events:                                                                                                                                          │
│  Type    Reason  Age   From                     Message                                                                                         │
│  ----    ------  ----  ----                     -------                                                                                         │
│  Normal  ADD     18m   loadbalancer-controller  default/teamcity                                                                                │
│  Normal  CREATE  17m   loadbalancer-controller  ip: 35.190.86.15   

Additionally here is my yaml file for the whole mashup:此外,这里是我的整个混搭的 yaml 文件:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: teamcity
  labels:
    app: teamcity
spec:
  replicas: 1
  selector:
    matchLabels:
      app: teamcity
  template:
    metadata:
      labels:
        app: teamcity
    spec:
      containers:
      - name: teamcity-server
        image: jetbrains/teamcity-server:latest
        ports:
        - containerPort: 8111
---
apiVersion: v1
kind: Service
metadata:
  name: teamcity
  labels:
    app: teamcity
spec:
  type: NodePort
  ports:
  - port: 8111
    targetPort: 8111
    protocol: TCP
  selector:
    app: teamcity
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: teamcity
spec:
  backend:
    serviceName: teamcity
    servicePort: 8111

I'd like to know what I did wrong here.我想知道我在这里做错了什么。

You are using GKE ingress controller with that Ingress resource, not Nginx.您将 GKE 入口 controller 与该入口资源一起使用,而不是 Nginx。 And the prove is that it is creating all the resources to create a HTTP load balancer;证明是它正在创建所有资源来创建 HTTP 负载均衡器; forwarding rule, target proxy, url map, backend service.转发规则,目标代理,url map,后端服务。

You need to pass the annotation kubernetes.io/ingress.class: "nginx" to your Ingress resource to let it know it shouod use Nginx Ingress Controller. You need to pass the annotation kubernetes.io/ingress.class: "nginx" to your Ingress resource to let it know it shouod use Nginx Ingress Controller.

Now, you are getting 503 for while because GCP load balancers do not start working right away.现在,由于 GCP 负载均衡器不会立即开始工作,您会得到 503。 Probably after about 3-4 minutes you will get 200.大约 3-4 分钟后,您可能会得到 200 个。

As you are using ingress, the nginx service will be exposed to LoadBalancer, and others can be kept on clusterIPs only.当您使用入口时,nginx 服务将暴露给 LoadBalancer,而其他服务只能保留在 clusterIP 上。

You can change the service to ClusterIP type instead of Nodeport here and try framing your ingress rule this way -您可以在此处将服务更改为 ClusterIP 类型而不是 Nodeport 并尝试以这种方式构建您的入口规则 -

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: rule-name
  namespace: default
spec:
  rules:
  - host: hostname
    http:
      paths:
      - backend:
          serviceName: teamcity
          servicePort: 8111

In the current scenario,you have not mapped any hostname to your ingress rule and if you don't have one specifically, you can just use the DNS name mapped against your publicIP/ ExternalIP of nginx.在当前场景中,您没有将任何主机名映射到您的入口规则,如果您没有专门的主机名,您可以使用 DNS 名称映射到 nginx 的公共IP/外部IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM