1

我的微服务有多个容器,每个容器都需要访问不同的端口。如何使用 Hasura CLI 和项目配置文件在多个端口上公开此服务?

编辑:添加微服务k8s.yaml(根据@iamnat 的要求)假设我有两个容器,containerAcontainerB,我想分别在端口6379和端口上通过 HTTP 公开8000

apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    creationTimestamp: null
    labels:
      app: www
      hasuraService: custom
    name: www
    namespace: '{{ cluster.metadata.namespaces.user }}'
  spec:
    replicas: 1
    strategy: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          app: www
      spec:
        containers:
        - name: containerA
          image: imageA
          ports:
          - containerPort: 6379
        - name: containerB
          image: imageB
          ports:
          - containerPort: 8000
        securityContext: {}
        terminationGracePeriodSeconds: 0
  status: {}
- apiVersion: v1
  kind: Service
  metadata:
    creationTimestamp: null
    labels:
      app: www
      hasuraService: custom
    name: www
    namespace: '{{ cluster.metadata.namespaces.user }}'
  spec:
    ports:
    - port: 6379
      name: containerA
      protocol: HTTP
      targetPort: 6379

    - port: 8000
      name: containerB
      protocol: HTTP
      targetPort: 8000

    selector:
      app: www
    type: ClusterIP
  status:
    loadBalancer: {}
kind: List
metadata: {}
4

1 回答 1

3

TL;DR: - 为您要公开的每个 HTTP 端点添加一个 API 网关路由[docs]


在 kubernetes 集群中,给你的 k8s 规范,这就是你的设置的样子:

http://www.default:8000  -> containerA
http://www.default:6379  -> containerB

因此,您需要为conf/routes.yaml.

www-a:
  /:
    upstreamService:
      name: www
      namespace: {{ cluster.metadata.namespaces.user }}
    upstreamServicePath: /
    upstreamServicePort: 8000
    corsPolicy: allow_all
www-b:
  /:
    upstreamService:
      name: www
      namespace: {{ cluster.metadata.namespaces.user }}
    upstreamServicePath: /
    upstreamServicePort: 6379
    corsPolicy: allow_all

这意味着,您将获得以下信息:

https://www-a.domain.com -> containerA
https://www-a.domain.com -> containerB
于 2018-01-08T10:03:32.970 回答