<p>I'm trying to deploy a simple python app to Google Container Engine:</p>
<p>I have created a cluster then run <code>kubectl create -f deployment.yaml</code>
It has been created a deployment pod on my cluster. After that i have created a service as: <code>kubectl create -f deployment.yaml</code></p>
<blockquote>
<p>Here's my Yaml configurations:</p>
<p><strong>pod.yaml</strong>:</p>
</blockquote>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-app
spec:
  containers:
  - name: test-ctr
    image: arycloud/flask-svc
    ports:
    - containerPort: 5000
</code></pre>
<blockquote>
<p>Here's my Dockerfile:</p>
</blockquote>
<pre><code>FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./app.py
</code></pre>
<blockquote>
<p><strong>deployment.yaml:</strong></p>
</blockquote>
<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: test-app
  name: test-app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test-app
      name: test-app
    spec:
      containers:
      - name: test-app
        image: arycloud/flask-svc
        resources:
          requests:
            cpu: &quot;100m&quot;
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
</code></pre>
<blockquote>
<p><strong>service.yaml:</strong></p>
</blockquote>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: test-app
  labels:
    app: test-app
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
    nodePort: 32000
  selector:
    app: test-app
</code></pre>
<blockquote>
<p><strong>Ingress</strong></p>
</blockquote>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: 80
</code></pre>
<p>It creates a LoadBalancer and provides an external IP, when I open the IP it returns <code>Connection Refused error</code></p>
<p>What's going wrong?</p>
<p>Help me, please!</p>
<p>Thank You,
Abdul</p>

Abdul Rehman
<p>First make sure your ingress controller in running, to check that <code>kubectl get pods -n ingress-nginx</code> if you dont find any pods running you need to deploy the kubernetes ingress you can do that by <code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml</code>.</p>
<p>If you have installed ingress controller correctly, then just apply the yaml below, you need to have <strong>selector</strong> in your deployment so that the deployment can manage the replicas, apart from that you dont need to expose a node port as you are going to access your app through load balancer.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: test-app
  labels:
    app: test-app
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: test-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test-app
  name: test-app
spec:
  selector:
    matchLabels:
      app: test-app
  replicas: 1
  template:
    metadata:
      labels:
        app: test-app
    spec:
      containers:
      - name: test-app
        image: arycloud/flask-svc
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: 80
</code></pre>
