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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With