<p>I am trying to expose my service from k8s on the internet and using microk8s with an enabled ingress addon. my container is serving on port 19001 and I am casting the container port 19001 into port 8050. and after there is my ingress that makes this service accessible on the internet using the Nginx ingress controller.</p>
<p>these are my manifests to create the environment.</p>
<pre><code># service manifest
apiVersion: v1
kind: Service
metadata:
  name: test-revad
  labels:
    helm.sh/chart: revad-1.4.0
    app.kubernetes.io/name: revad
    app.kubernetes.io/instance: test
    app.kubernetes.io/version: &quot;v1.18.0&quot;
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 19001
      targetPort: 8050
      protocol: TCP
      name: http
    - port: 19000
      targetPort: 8053
      protocol: TCP
      name: grpc
  selector:
    app.kubernetes.io/name: revad
    app.kubernetes.io/instance: test


    #deployment manifest
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test-revad
      labels:
        helm.sh/chart: revad-1.4.0
        app.kubernetes.io/name: revad
        app.kubernetes.io/instance: test
        app.kubernetes.io/version: &quot;v1.18.0&quot;
        app.kubernetes.io/managed-by: Helm
    spec:
      replicas: 1
      selector:
        matchLabels:
          app.kubernetes.io/name: revad
          app.kubernetes.io/instance: test
      template:
        metadata:
          annotations:
            checksum/config: fbd4445121479c3490773ef31cee48e52be0975871037c78f37860ffe5bd1c64
          labels:
            app.kubernetes.io/name: revad
            app.kubernetes.io/instance: test
        spec:
          containers:
            - name: revad
              image: &quot;cs3org/revad:v1.18.0&quot;
              imagePullPolicy: Always
              ports:
                - name: http
                  containerPort: 19001
                  protocol: TCP
                - name: grpc
                  containerPort: 19000
                  protocol: TCP
              command:
                - /usr/bin/revad
              args:
                  - &quot;-c&quot;
                  - /etc/revad/oc.revad.toml
                    
                  - &quot;-p&quot;
                  - &quot;/var/run/revad.pid&quot;
              volumeMounts:
                - name: test-revad-configfiles
                  mountPath: /etc/revad/
                - name: test-revad-datadir
                  mountPath: /var/tmp/reva
                  subPath: &quot;&quot;
          volumes:
            - name: test-revad-configfiles
              configMap:
                name: test-revad-config
            - name: test-revad-datadir
              emptyDir:
                {}

# ingress manifest
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-revad-http
  labels:
    helm.sh/chart: revad-1.4.0
    app.kubernetes.io/name: revad
    app.kubernetes.io/instance: test
    app.kubernetes.io/version: &quot;v1.18.0&quot;
    app.kubernetes.io/managed-by: Helm
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              service:
                name: test-revad
                port:
                  number: 8050
            pathType: Prefix
  tls:
    - hosts:
      - myservice.mysite.com
      secretName: http-revad-tls
</code></pre>
<p>when I am sending a request from my client to the server I am getting this log on my ingress controller pod:</p>
<pre><code>70.34.197.50 - - [19/Aug/2022:07:54:30 +0000] &quot;GET / HTTP/2.0&quot; 502 150 &quot;-&quot; &quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0&quot; 25 0.001 [default-ponder-revad-8050] [] 10.1.86.215:8050, 10.1.86.215:8050, 10.1.86.215:8050 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 a6caf1d407fb1afc6d85f02f870656c9
2022/08/19 07:54:30 [error] 998#998: *1308192 connect() failed (111: Connection refused) while connecting to upstream, client: 70.34.197.50, server: _, request: &quot;GET / HTTP/2.0&quot;, upstream: &quot;http://10.1.86.215:8050/&quot;, host: &quot;myservice.mysite.com&quot;
2022/08/19 07:54:30 [error] 998#998: *1308192 connect() failed (111: Connection refused) while connecting to upstream, client: 70.34.197.50, server: _, request: &quot;GET / HTTP/2.0&quot;, upstream: &quot;http://10.1.86.215:8050/&quot;, host: &quot;myservice.mysite.com&quot;
2022/08/19 07:54:30 [error] 998#998: *1308192 connect() failed (111: Connection refused) while connecting to upstream, client: 70.34.197.50, server: _, request: &quot;GET / HTTP/2.0&quot;, upstream: &quot;http://10.1.86.215:8050/&quot;, host: &quot;myservice.mysite.com&quot;
2022/08/19 07:55:27 [error] 998#998: *1308192 connect() failed (111: Connection refused) while connecting to upstream, client: 70.34.197.50, server: _, request: &quot;GET /invites/generate HTTP/2.0&quot;, upstream: &quot;http://10.1.86.215:8050/invites/generate&quot;, host: &quot;myservice.mysite.com&quot;
2022/08/19 07:55:27 [error] 998#998: *1308192 connect() failed (111: Connection refused) while connecting to upstream, client: 70.34.197.50, server: _, request: &quot;GET /invites/generate HTTP/2.0&quot;, upstream: &quot;http://10.1.86.215:8050/invites/generate&quot;, host: &quot;myservice.mysite.com&quot;
2022/08/19 07:55:27 [error] 998#998: *1308192 connect() failed (111: Connection refused) while connecting to upstream, client: 70.34.197.50, server: _, request: &quot;GET /invites/generate HTTP/2.0&quot;, upstream: &quot;http://10.1.86.215:8050/invites/generate&quot;, host: &quot;myservice.mysite.com&quot;
</code></pre>

Navid_pdp11
<p>In your deployment, the containers ports are <code>19001</code> and <code>19000</code> whereas in the service the <code>targetPort</code>s are <code>8050</code> and <code>8053</code> respectively. Container ports in deployment and targetPorts in service be same.</p>
