<p>I've been tinkering with Kubernetes on and off for the past few years and I am not sure if this has always been the case (maybe this behavior changed recently) but I cannot seem to get Services to publish on the ports I intend - they always publish on a high random port (>30000).</p>

<p>For instance, I'm going through <a href="https://hackernoon.com/setting-up-nginx-ingress-on-kubernetes-2b733d8d2f45" rel="nofollow noreferrer">this walkthrough on Ingress</a> and I create the following Deployment and Service objects per the instructions:</p>

<pre><code>---
apiVersion: apps/v1beta1
kind: Deployment
metadata: 
  name: hello-world-deployment
spec: 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: hello-world
    spec: 
      containers: 
        - image: "gokul93/hello-world:latest"
          imagePullPolicy: Always
          name: hello-world-container
          ports: 
            - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata: 
  name: hello-world-svc
spec: 
  ports: 
     -  port: 9376
        protocol: TCP
        targetPort: 8080
  selector: 
    app: hello-world
  type: NodePort
</code></pre>

<p>According to this, I should have a Service that's listening on port 8080, but instead it's a high, random port:</p>

<pre><code>~$ kubectl describe svc hello-world-svc

Name:                     hello-world-svc
Namespace:                default
Labels:                   &lt;none&gt;
Annotations:              &lt;none&gt;
Selector:                 app=hello-world
Type:                     NodePort
IP:                       10.109.24.16
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  31669/TCP
Endpoints:                10.40.0.4:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>I also verified that none of my nodes are listening on 8080, but they are listening on 31669.</p>

<p>This isn't super ideal - especially considering that the Ingress portion will need to know what <code>servicePort</code> is being used (the walkthrough references this at 8080).</p>

<p>By the way, when I create the Ingress controller, this behavior is the same - rather than listening on 80 and 443 like a good load balancer, it's listening on high random ports.</p>

<p>Am I missing something? Am I doing it all wrong?</p>

<p>Matt,</p>

<p>The reason a random port is being allocated is because you are creating a service of type NodePort. </p>

<p>K8s documentation explains NodePort <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">here</a></p>

<p>Based on your config, the service is exposed on port 9376 (and the backend port is 8080). So hello-word-svc should be available at: 10.109.24.16:9376. Essentially this service can be reached in one of the following means:</p>

<p>Service ip/port :- 10.109.24.16:9376</p>

<p>Node ip/port    :- [your compute node ip]:31669 &lt;-- this is created because your service is of type NodePort</p>

<p>You can also query the pod directly to test that the pod is in-fact exposing a service.</p>

<p>Pod ip/port: 10.40.0.4:8080 </p>

<p>Since your eventual goal is to use ingress controller for external reachability to your service, "type: ClusterIP" might suffice your ask.</p>
