502没有Pod的WorkerNode上的错误网关

时间:2019-08-28 01:35:13

标签: kubernetes-ingress

我试图了解K8S集群上的Nginx-Ingress。

我根据说明here

设置了Nginx-ingress控制器

我的集群有3个节点 kubernetes-master,kubernetes-node1,kubernetes-node2

我有一个运行1个副本(kubernetes-node1)的IoTPoD。我已经创建了一个群集IP服务,用于通过休息访问该Pod。下面是清单。

apiVersion: v1
kind: Namespace
metadata:
  name: myiotgarden
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ioteventshandler
  namespace: myiotgarden
  labels:
    app:  ioteventshandler
spec:
  replicas: 2
  selector:
    matchLabels:
      app:  ioteventshandler
  template:
    metadata:
      labels:
        app:  ioteventshandler
    spec:
      containers:
      - name:  ioteventshandler
        image: 192.168.56.105:5000/ioteventshandler:latest
        resources:
          limits:
            memory: "1024M"
          requests:
            memory: "128M"
        imagePullPolicy: "Always"
---
apiVersion: v1
kind: Service
metadata:
  name: iotevents-service
  namespace: myiotgarden
  labels:
    app: iotevents-service
spec:
  selector:
    app: ioteventshandler
  ports:  
  - port: 8080
    protocol: TCP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ioteventshandler-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
  namespace: myiotgarden
spec:
  rules:
  - host: kubernetes-master
    http:
      paths:
      - path: /iotEvents/sonoff
        backend:
          serviceName: iotevents-service
          servicePort: 8080
  - host: kubernetes-node1
    http:
      paths:
      - path: /iotEvents/sonoff
        backend:
          serviceName: iotevents-service
          servicePort: 8080
  - host: kubernetes-node2
    http:
      paths:
      - path: /iotEvents/sonoff
        backend:
          serviceName: iotevents-service
          servicePort: 8080

我在Kmaster节点上运行了一个haproxy。已将knode1和knode2都配置为工作节点。

frontend http_front
  bind *:80
  stats uri /haproxy?stats
  default_backend http_back

backend http_back
  balance roundrobin
  server worker 192.168.56.207:80
  server worker 192.168.56.208:80

当ioteventshandler有2个副本在运行时,以下命令可以正常工作。

curl -kL http://kubernetes-master/iotEvents/sonoff/sonoff11

我完美地得到了答复。

但是,当我将副本减少到1.时,curl命令会间歇性地返回502 Bad Gateway。我假设这是在haproxy将请求转发到ioteventshandler副本未运行的knode2时发生的。

问题: knode2上的入口控制器是否可以将其转发到knode1?以及我们该怎么做?

谢谢。

0 个答案:

没有答案