<p>I have the cluster setup below in AKS</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hpa-example
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hpa-example
  template:
    metadata:
      labels:
        app: hpa-example
    spec:
      containers:
      - name: hpa-example
        image: gcr.io/google_containers/hpa-example
        ports:
        - name: http-port
          containerPort: 80
        resources:
          requests:
            cpu: 200m
---

apiVersion: v1
kind: Service
metadata:
  name: hpa-example
spec:
  ports:
  - port: 31001
    nodePort: 31001
    targetPort: http-port
    protocol: TCP
  selector:
    app: hpa-example
  type: NodePort
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa-example-autoscaler
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: hpa-example
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 50
</code></pre>
<p>The idea of this is to check AutoScaling</p>
<p>I need to have this available externally so I added</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: load-balancer-autoscaler
spec:
  selector:
    app: hpa-example
  ports:
    - port: 31001
      targetPort: 31001
  type: LoadBalancer
</code></pre>
<p>This now gives me an external IP however, I cannot connect to it in Postman or via a browser</p>
<p>What have I missed?</p>
<p>I have tried to change the ports between 80 and 31001 but that makes no difference</p>

Paul
<p>As posted by user @David Maze:</p>
<blockquote>
<p>What's the exact URL you're trying to connect to? What error do you get? (On the load-balancer-autoscaler service, the targetPort needs to match the name or number of a ports: in the pod, or you could just change the hpa-example service to type: LoadBalancer.)</p>
</blockquote>
<p>I reproduced your scenario and found out issue in your configuration that could deny your ability to connect to this <code>Deployment</code>.</p>
<p>From the perspective of <code>Deployment</code> and <code>Service</code> of type <code>NodePort</code> everything seems to work okay.</p>
<p>If it comes to the <code>Service</code> of type <code>LoadBalancer</code> on the other hand:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: load-balancer-autoscaler
spec:
  selector:
    app: hpa-example
  ports:
    - port: 31001
      targetPort: 31001 # &lt;--- CULPRIT
  type: LoadBalancer
</code></pre>
<p>This definition will send your traffic directly to the pods on port <strong><code>31001</code></strong> and <strong>it should send it to the port <code>80</code></strong> (this is the port your app is responding on). You can change it either by:</p>
<ul>
<li><code>targetPort: 80</code></li>
<li><code>targetPort: http-port</code></li>
</ul>
<blockquote>
<p>You could also change the <code>Service</code> of the <code>NodePort</code> (<code>hpa-example</code>) to <code>LoadBalancer</code> as pointed by user @David Maze!</p>
</blockquote>
<p>After changing this definition you will be able to run:</p>
<p><code>$ kubectl get service</code></p>
<pre class="lang-sh prettyprint-override"><code>NAME                       TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)           AGE
load-balancer-autoscaler   LoadBalancer   10.4.32.146   AA.BB.CC.DD     31001:31497/TCP   9m41s
</code></pre>
<ul>
<li><code>curl AA.BB.CC.DD:31001</code> and get the reply of <code>OK!</code></li>
</ul>
<hr />
<p>I encourage you to look on the additional resources regarding Kubernetes services:</p>
<ul>
<li><em><a href="https://learn.microsoft.com/en-us/azure/aks/concepts-network#services" rel="nofollow noreferrer">Docs.microsoft.com: AKS: Network: Services</a></em></li>
<li><em><a href="https://stackoverflow.com/questions/41509439/whats-the-difference-between-clusterip-nodeport-and-loadbalancer-service-types">Stackoverflow.com: Questions: Difference between nodePort and LoadBalancer service types</a></em></li>
<li><em><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Service</a></em></li>
</ul>
