Can I set IP instead of dns name?
Somethig like this
kind: Service
apiVersion: v1
metadata:
name: external-grafana
namespace: kube-system
spec:
type: ExternalName
externalName: 207.244.95.62
ports:
- port: 3000
Can I set IP instead of dns name?
Somethig like this
kind: Service
apiVersion: v1
metadata:
name: external-grafana
namespace: kube-system
spec:
type: ExternalName
externalName: 207.244.95.62
ports:
- port: 3000
You can indeed, here is an example I just tested:
apiVersion: v1
kind: Service
metadata:
name: google-dns
spec:
type: ExternalName
externalName: 8.8.8.8
ports:
- port: 53
protocol: UDP
listing services
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
google-dns ExternalName <none> 8.8.8.8 53/UDP 2m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1d
nslookup from within a container
# nslookup google-dns.default.svc.cluster.local
Name: google-dns.default.svc.cluster.local
Address 1: 8.8.8.8 google-public-dns-a.google.com
Oddly I can’t get mine to work. I am using CoreDNS, do you know if that might affect it?
I can get it working if I create a Service with no selectors and manually create the Endpoints.
I tested it with an instance of CoreDNS and it did not seem to impact it, but ExternalName
should not use any selectors or additional endpoints referenced, its meant to point to an external entity whether it be a dns name or ip address – pretty much setting it manually in the service definition.
Below is my exact YAML file for creating the externalName Service, can you see anything wrong with it? Any ideas on what I can check next? Thanks by the way!
apiVersion: v1
kind: Service
metadata:
name: kafka
spec:
type: ExternalName
externalName: 10.59.208.211
ports:
- name: kafka
port: 9092
protocol: TCP
- name: zookeeper
port: 2181
protocol: TCP
At this point my guess is there might be something else afoot. I was able to create the service you posted both in minikube and another cluster (both running 1.10.x)
$ kubectl describe service kafka
apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2018-05-23T17:54:20Z
name: kafka
namespace: default
resourceVersion: "61858"
selfLink: /api/v1/namespaces/default/services/kafka
uid: 51b77866-5eb2-11e8-b3dc-0800279f676b
spec:
externalName: 10.59.208.211
ports:
- name: kafka
port: 9092
protocol: TCP
targetPort: 9092
- name: zookeeper
port: 2181
protocol: TCP
targetPort: 2181
sessionAffinity: None
type: ExternalName
status:
loadBalancer: {}
I have just read this in K8 docs:
Note:
ExternalName accepts an IPv4 address string, but as a DNS name comprised of digits, not as an IP address. ExternalNames that resemble IPv4 addresses are not resolved by CoreDNS or ingress-nginx because ExternalName is intended to specify a canonical DNS name. To hardcode an IP address, consider headless services.
Not sure what your question is. Can you please elaborate?
In any case, think of service external name as a DNS cname. Does that help? If not, please share your question
For those who still comes to this thread, here’s a link with 3 scenarios to map external services:
In short, use a combination of Service
and Endpoints
.
I have successfully tested an externalName
with an IP address on GKE but I prefer to use the correct way to do it.
Terraform documentation for Kubernetes provider on Endpoints
: https://www.terraform.io/docs/providers/kubernetes/r/endpoints.html
The Kubernetes best practices: mapping external services post is redirecting to another one. The original can be read in archive.org.
Inline video is Mapping External Services - YouTube.