在Kubernetes中路由WebSocket的大使

时间:2018-11-06 10:22:19

标签: websocket kubernetes api-gateway

我正在尝试使用Ambassador和DO LoadBalancer在DigitalOcean Kubernetes上使用WebSockets公开某些服务。

直接使用LoadBalancer公开WebSocket服务时,它可以工作(我可以连接到它)。

但是当尝试通过大使路线时,却没有。此时,我不知道是否配置错误或大使中有错误。

在使用Ambassdor示例进行HTTP路由测试时,它可以工作,但是关于使用WebSocket的文档零。

这是所有重整块的配置:

RBAC大使:

---
apiVersion: v1
kind: Service
metadata:
  labels:
    service: ambassador-admin
  name: ambassador-admin
spec:
  type: NodePort
  ports:
  - name: ambassador-admin
    port: 8877
    targetPort: 8877
  selector:
    service: ambassador
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: ambassador
rules:
- apiGroups: [""]
  resources:
 - services
  verbs: ["get", "list", "watch"]
- apiGroups: [""]
  resources:
 - configmaps
  verbs: ["create", "update", "patch", "get", "list", "watch"]
- apiGroups: [""]
  resources:
 - secrets
  verbs: ["get", "list", "watch"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: ambassador
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: ambassador
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: ambassador
subjects:
- kind: ServiceAccount
  name: ambassador
  namespace: default
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ambassador
spec:
  replicas: 3
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        service: ambassador
    spec:
      serviceAccountName: ambassador
      containers:
      - name: ambassador
        image: quay.io/datawire/ambassador:0.40.0
        resources:
          limits:
            cpu: 1
            memory: 400Mi
          requests:
            cpu: 200m
            memory: 100Mi
        env:
        - name: AMBASSADOR_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        ports:
        - name: http
          containerPort: 80
        - name: https
          containerPort: 443
        - name: admin
          containerPort: 8877
        - name: websocket1
          containerPort: 8010
        - name: websocket2
          containerPort: 8011
        livenessProbe:
          httpGet:
            path: /ambassador/v0/check_alive
            port: 8877
          initialDelaySeconds: 30
          periodSeconds: 3
        readinessProbe:
          httpGet:
            path: /ambassador/v0/check_ready
            port: 8877
          initialDelaySeconds: 30
          periodSeconds: 3
      restartPolicy: Always

大使服务:

---
apiVersion: v1
kind: Service
metadata:
  name: ambassador
spec:
  type: LoadBalancer
  ports:
   - port: 80
     name: http
   - port: 8010
     name: websocket1
   - port: 8011
     name: websocket2
  selector:
    service: ambassador

Websocket Pod:

---
 apiVersion: v1
 kind: Pod
 metadata:
   name: web-socket-test
   labels:
     app: web-socket-test
 spec:
   containers:
     - name: web-socket-test
       image: ksdn117/web-socket-test
       ports:
         - containerPort: 8010
         - containerPort: 31448
         - containerPort: 8011
         - containerPort: 31057

websocket服务:

---
apiVersion: v1
kind: Service
metadata:
  name: web-socket-test
  annotations:
    getambassador.io/config: |
     ---
      apiVersion: ambassador/v0
      kind:  Mapping
      name:  web-socket-test_mapping
      prefix: /web-socket-test/
      service: web-socket-test
      use_websocket: True
spec:
  selector:
    app: web-socket-test
  ports:
  - protocol: TCP
    port: 8011
    targetPort: 31057
    name: websocket1
  - protocol: TCP
    port: 31057
    targetPort: 8010
    name: websocket2

0 个答案:

没有答案