我的微服务有多个容器,每个容器都需要访问不同的端口。如何使用Hasura CLI和项目配置文件在多个端口上公开此服务?
编辑:添加微服务的k8s.yaml
(根据@iamnat的要求)
假设我有两个容器containerA
和containerB
,我希望分别在端口6379
和8000
上通过HTTP公开。
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: {}
答案 0 :(得分:3)
TL; DR: - 为要公开的每个HTTP端点添加API网关路由[docs]
在kubernetes集群内,给你的k8s规格这就是你的设置:
http://www.default:8000 -> containerA
http://www.default:6379 -> containerB
因此,您需要为conf/routes.yaml
中的每个HTTP路径创建路由。
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