Once you start using Kubernetes, there's a strong desire to run everything on it. I'm not saying this is not possible, but for one reason or another it is not always practical. ExternalName services are a type of Service which allow you to map an arbitrary service name to another, resolvable, DNS name.

An example

Let's try it out with tcpbin.com.

Here is a minimal ExternalName manifest, note that the ports do not have to be indicated as the ExternalName service works at the DNS level:

---

kind: Service
apiVersion: v1
metadata:
  name: tcpbin
spec:
  type: ExternalName
  externalName: tcpbin.com

However, for documentation purposes, or default port binding purposes, the available port(s) can be listed, as with other types of services:

---

kind: Service
apiVersion: v1
metadata:
  name: tcpbin
spec:
  type: ExternalName
  externalName: tcpbin.com
  ports:
    - name: echo
      port: 4242
      protocol: TCP
      targetPort: 4242
    - name: echo-tls
      port: 4243
      protocol: TCP
      targetPort: 4243
    - name: echo-mtls
      port: 4244
      protocol: TCP
      targetPort: 4244

Try It Out

Save one of the 2 examples as tcpbin-svc.yaml and apply in your cluster:

$ kubectl apply -f tcpbin-svc.yaml

In order to try it out, we can netshoot into our cluster:

$ kubectl run tmp-shell --rm -i --tty --image nicolaka/netshoot -- /bin/bash

And execute, for example:

bash-5.0# nc tcpbin 4242

Type in anthing you'd like and it will be echo'ed back at you:

bash-5.0# nc tcpbin 4242
atorico.com ExternalName
atorico.com ExternalName
try again
try again

Final Thoughts

A nice thing about ExternalName services is that they do not suffer from the downsides of ExternalIP services, or VIP services in general:

  • no proxying will be done with ExternalName services
  • ExternalName services will not use up IP's in the Cluster IP pool