Can't create ExternalName type service through command line

7/3/2019

On k8s you can create services either through kubectl expose .. command or kubectl crate service ... right?

So, with both of them I am having an issue that I am not sure why.

k8s allows me to do kubectl expose deploy demo --type ExternalName, but it doesn't allow to pass an --external-name flag to specify the CNAME.

$ kubectl expose deploy demo --type ExternalName --port 80 --external-name google.com

...

unknown flag: --external-name

If I do without the --external-name flag.

$ kubectl expose deploy demo --type ExternalName --port 80

The Service "demo" is invalid: spec.externalName: Required value


k8s also allows me to do kubectl create service externalname demo --external-name example.com --tcp <port>:<target-port>, but when I check the port and target port didn't go through.

$ kubectl get svc
NAME               TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
demo               ExternalName   <none>        google.com    <none>     20m

I tried --tcp=80:80, --tcp 80:80, --tcp=[80:80], etc. Nothing works!

Anyone can point out what's the issue? I think it might be a bug.

I'm on GKE, with a 1.13.7 k8s version.

-- suren
google-kubernetes-engine
kubernetes

1 Answer

7/3/2019

A service of type ExternalName is exactly that: a local DNS CNAME record to an external domain name.

Thus exposing a deployment as ExternalName does not make sense. And since it's only a name, it does not have any ports as well.

This is all it takes:

apiVersion: v1
kind: Service
metadata:
  name: stackoverflow
  namespace: default
spec:
  externalName: stackoverflow.com
  type: ExternalName
-- Markus Dresch
Source: StackOverflow