<p>I am deploying nginx image using following deployment files in Google Cloud.</p>

<p>For Replicationcontroller :</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-web
  labels:
    name: nginx-web
    app: demo
spec:
  replicas: 2
  template:
    metadata:
      labels:
        name: nginx-web
    spec:
      containers:
        - name: nginx-web
          image: nginx
          ports:
            - containerPort: 5000
              name: http
              protocol: TCP
</code></pre>

<p>For Service Deployment</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-web
  labels:
    name: nginx-web
    app: demo
spec:
  selector:
    name: nginx-web
  type: LoadBalancer
  ports:
   - port: 84
     targetPort: 5000
     protocol: TCP
</code></pre>

<p>But when I do curl on external_IP (I got from loadbalancer) on port 84, I get connection refused error. What might be the issue?</p>

rishi007bansod
<p>The nginx image you are using in your replication controller is listening on port 80 (that's how the image is build).</p>

<p>You need to fix your replication controller spec like this:</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-web
  labels:
    name: nginx-web
    app: demo
spec:
  replicas: 2
  template:
    metadata:
      labels:
        name: nginx-web
    spec:
      containers:
        - name: nginx-web
          image: nginx
          ports:
            - containerPort: 80
              name: http
              protocol: TCP
</code></pre>

<p>And also adjust your service like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-web
  labels:
    name: nginx-web
    app: demo
spec:
  selector:
    name: nginx-web
  type: LoadBalancer
  ports:
   - port: 84
     targetPort: 80
     protocol: TCP
</code></pre>
