Creating Kubernetes service that reference external service by multiple ip addresses

柔情痞子 提交于 2019-12-25 01:46:13

问题


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

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?


回答1:


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

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



回答2:


An ExternalIP service uses an IP address from the predefined pool of external IP addresses routed to the cluster’s nodes. These external IP addresses are not managed by Kubernetes; they are the responsibility of the cluster administrator.

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

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

Documentation: service-selectors. Useful article: exposing-pods.



来源:https://stackoverflow.com/questions/57618606/creating-kubernetes-service-that-reference-external-service-by-multiple-ip-addre

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!