创建通过多个IP地址引用外部服务的Kubernetes服务 [英] Creating Kubernetes service that reference external service by multiple ip addresses

查看:117
本文介绍了创建通过多个IP地址引用外部服务的Kubernetes服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kubernetes中是否有一种方法可以为应该返回多个IP地址的外部服务创建服务?目前,我正在通过在公共DNS提供程序(route53)中创建A记录,然后在Kubernetes中创建服务来解决此问题:

Is there a way in Kubernetes to create a service for an external service that should return multiple IP addresses? Currently I am hacking around this by creating an A record in my public DNS provider (route53) and then in Kubernetes creating a service:

apiVersion: v1
kind: Service
metadata:
  name: rabbitmq
  labels:
    app: rabbitmq
spec:
  type: ExternalName
  externalName: rabbitmq.mydomainhere.dev

是否有一种方法可以在Kubernetes中本地创建服务,该服务返回在Kubernetes集群内部不管理的一组固定IP地址,而无需创建公共DNS记录并使用externalName?

Is there a way to create a service natively in Kubernetes that returns a fixed set of IP addresses that are not managed inside of the Kubernetes cluster without creating a public DNS record and using externalName?

推荐答案

您可以创建没有选择器的无头服务,并将clusterIP设置为None,然后手动创建端点以在端点中设置所有IP.您可以看一下以下示例.

You can create a headless service without selectors and set clusterIP to None, then create an endpoint manually to have all your IPs set in the endpoint. You can take a look at the following example.

kind: Service
apiVersion: v1
metadata:
  name: my-es
spec:
  clusterIP: None

---
kind: Endpoints
apiVersion: v1
metadata:
  name: my-es
subsets:
  - addresses:
      - ip: 172.22.111.250
      - ip: 172.22.149.230
    ports:
      - port: 9200

来自一个Pod的nslookup输出

nslookup output from one Pod

root@curl-66bdcf564-8m6h7:/ ]$ nslookup my-es
Server:    169.254.25.10
Address 1: 169.254.25.10

Name:      my-es
Address 1: 172.22.111.250 172-22-111-250.my-es.default.svc.cluster.local
Address 2: 172.22.149.230 172-22-149-230.my-es.default.svc.cluster.local

这篇关于创建通过多个IP地址引用外部服务的Kubernetes服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆