【问题标题】:Service with both selector and explicit endpoints?具有选择器和显式端点的服务?
【发布时间】:2019-02-26 18:51:01
【问题描述】:

作为从遗留服务发现框架迁移到 kube/CoreDNS 的一部分,我想创建一个知道如何自动发布 Endpoints 的服务,但手动创建了端点。

基本上我认为我想要以下内容:

---
kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80
---
kind: Endpoints
apiVersion: v1
metadata:
  name: my-service
  annotations:
    transition: legacy
subsets:
- addresses:
  - ip: 1.2.3.4
  ports:
  - port: 9376
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-discovery-backend
  labels:
    app: MyApp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: MyApp
  template:
    metadata:
      labels:
        app: MyApp
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

不过,正如 the docs imply 一样,像这样明确设置会导致只有一个 Endpoints 对象与服务相关联——无论是服务的自动创建的对象还是我手动指定的对象似乎有所不同。

对于知道如何自行发布的服务和外部服务手动控制端点直到我们 100% 迁移,然后切换到基于选择器的方法,最合理的方法是使用 CoreDNS 作为服务发现吗?

【问题讨论】:

    标签: kubernetes service-discovery


    【解决方案1】:

    仅使用 Kubernetes 服务无法完成,但我在这里看到了一种解决方法。

    我相信,您可以使用由 Nginx Pod(或部署)支持的附加服务,手动配置(通过 config-map)作为两个后端的反向代理:Kubernetes 服务名称(带有选择器,用于新后端)和手册端点(fqdn 或 IP,用于旧式后端)。

    ingress -> Service1 -> Nginx--> Service2 -> Deployments/Pods
                              | 
                               ---> Endpoint -> Legacy Servers
    

    如何在它们之间进行balance 流量取决于您。

    【讨论】:

      猜你喜欢
      • 2010-09-16
      • 2021-09-25
      • 2015-09-08
      • 2016-01-21
      • 1970-01-01
      • 2018-12-06
      • 2012-12-03
      • 1970-01-01
      • 2012-02-20
      相关资源
      最近更新 更多