<p>This is the simplest config straight from the docs, but when I create the service, kubectl lists the target port as something random. Setting the target port to 1337 in the YAML:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: sails-svc
spec:
  selector:
    app: sails
  ports:
    - port: 1337
      targetPort: 1337
  type: LoadBalancer
</code></pre>
<p>And this is what k8s sets up for services:</p>
<pre><code>kubectl get services
NAME           TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
kubernetes     ClusterIP      &lt;X.X.X.X&gt;      &lt;none&gt;          443/TCP          23h
sails          LoadBalancer   &lt;X.X.X.X&gt;      &lt;X.X.X.X&gt;       1337:30203/TCP   3m6s
svc-postgres   ClusterIP      &lt;X.X.X.X&gt;      &lt;none&gt;          5432/TCP         3m7s
</code></pre>
<p>Why is k8s setting the target port to <code>30203</code>, when I'm specifying <code>1337</code>? It does the same thing if I try other port numbers, <code>80</code> gets <code>31887</code>. I've read <a href="https://kubernetes.io/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation" rel="nofollow noreferrer">the docs</a> but disabling those attributes did nothing in GCP. What am I not configuring correctly?</p>

Colby Blair
<p>Kubectl get services output includes <strong>Port:NodePort:Protocol</strong> information.By default and for convenience, the Kubernetes control plane will allocate a port from a range default: <strong>30000-32767</strong>(Refer the example in this <a href="https://kubernetes.io/docs/concepts/services-networking/service/#nodeport" rel="nofollow noreferrer">documentation</a>)</p>
<p>To get the TargetPort information try using</p>
<pre><code>kubectl get service &lt;your service name&gt; --output yaml
</code></pre>
<p>This command shows all ports details and stable external IP address under loadBalancer:ingress:</p>
<p>Refer this <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/exposing-apps#creating_a_service_of_type_loadbalancer" rel="nofollow noreferrer">documentation</a> from more details on creating a service type loadbalancer</p>
