<p>On k8s you can create services either through <code>kubectl expose ..</code> command or <code>kubectl crate service ...</code> right?</p>

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

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

<pre><code>$ kubectl expose deploy demo --type ExternalName --port 80 --external-name google.com
</code></pre>

<blockquote>
  <p>...</p>
  
  <p>unknown flag: --external-name</p>
</blockquote>

<p>If I do without the <code>--external-name</code> flag.</p>

<pre><code>$ kubectl expose deploy demo --type ExternalName --port 80
</code></pre>

<blockquote>
  <p>The Service "demo" is invalid: spec.externalName: Required value</p>
</blockquote>

<hr>

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

<pre><code>$ kubectl get svc
NAME               TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
demo               ExternalName   &lt;none&gt;        google.com    &lt;none&gt;     20m
</code></pre>

<p>I tried <code>--tcp=80:80</code>, <code>--tcp 80:80</code>, --tcp=[80:80], etc. Nothing works!</p>

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

<p>I'm on GKE, with a 1.13.7 k8s version.</p>

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

<p>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.</p>

<p>This is all it takes:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: stackoverflow
  namespace: default
spec:
  externalName: stackoverflow.com
  type: ExternalName
</code></pre>
