Kubernetes进入规则

时间:2018-01-08 17:19:44

标签: docker websocket kubernetes kubectl docker-ingress

我有一个k8s 1.9.0群集,以下是我的入口规则。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: my-ingress
 labels:
  app: report
annotations:
  ingress.kubernetes.io/rewrite-target: /
spec:
 rules:
  - host: "gayan.test.com"
    http:
     paths:
      - path: /report
        backend:
         serviceName: qc-report-svc
         servicePort: 80
     - path: /report/*
        backend:
         serviceName: qc-report-svc
         servicePort: 80

所以我有两个请求。

请求一个 - https://gayan.test.com/report/ping此请求点击广告连播并返回响应。 (GET /ping 200 302.079 ms - 63

请求两个 - wss://gayan.test.com/report/socket.io/?EIO=3&transport=websocket。 此请求甚至没有命中服务器。我认为这与入口规则有关。

我的问题是如何将所有/report流量发送到qc-report-svc服务?

1 个答案:

答案 0 :(得分:1)

假设您使用的是Nginx Ingress Controller,则需要添加nginx.org/websocket-services注释以启用WebSocket支持。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: my-ingress
 labels:
   app: report
annotations:
  ingress.kubernetes.io/rewrite-target: /
  nginx.org/websocket-services: "qc-report-svc"
spec:
 rules:
  - host: "gayan.test.com"
    http:
     paths:
      - path: /report
        backend:
         serviceName: qc-report-svc
         servicePort: 80