Home > Mobile >  ingress controller connection refused error
ingress controller connection refused error

Time:08-21

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.

these are my manifests to create the environment.

# 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: "v1.18.0"
    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: "v1.18.0"
        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: "cs3org/revad:v1.18.0"
              imagePullPolicy: Always
              ports:
                - name: http
                  containerPort: 19001
                  protocol: TCP
                - name: grpc
                  containerPort: 19000
                  protocol: TCP
              command:
                - /usr/bin/revad
              args:
                  - "-c"
                  - /etc/revad/oc.revad.toml
                    
                  - "-p"
                  - "/var/run/revad.pid"
              volumeMounts:
                - name: test-revad-configfiles
                  mountPath: /etc/revad/
                - name: test-revad-datadir
                  mountPath: /var/tmp/reva
                  subPath: ""
          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: "v1.18.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              service:
                name: test-revad
                port:
                  number: 8050
            pathType: Prefix
  tls:
    - hosts:
      - myservice.mysite.com
      secretName: http-revad-tls

when I am sending a request from my client to the server I am getting this log on my ingress controller pod:

70.34.197.50 - - [19/Aug/2022:07:54:30  0000] "GET / HTTP/2.0" 502 150 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0" 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: "GET / HTTP/2.0", upstream: "http://10.1.86.215:8050/", host: "myservice.mysite.com"
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: "GET / HTTP/2.0", upstream: "http://10.1.86.215:8050/", host: "myservice.mysite.com"
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: "GET / HTTP/2.0", upstream: "http://10.1.86.215:8050/", host: "myservice.mysite.com"
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: "GET /invites/generate HTTP/2.0", upstream: "http://10.1.86.215:8050/invites/generate", host: "myservice.mysite.com"
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: "GET /invites/generate HTTP/2.0", upstream: "http://10.1.86.215:8050/invites/generate", host: "myservice.mysite.com"
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: "GET /invites/generate HTTP/2.0", upstream: "http://10.1.86.215:8050/invites/generate", host: "myservice.mysite.com"

CodePudding user response:

In your deployment, the containers ports are 19001 and 19000 whereas in the service the targetPorts are 8050 and 8053 respectively. Container ports in deployment and targetPorts in service be same.

  • Related