Home > Software design >  Ingress - Connection refused
Ingress - Connection refused

Time:04-22

I know that they are tons of similar problem but after I have read all of them I am not able to figure it out... :/

First of all I am not using minikube, I am using kubernetes docker desktop.

I have simple express.js server like:

app.get('/test', async (_, res) => {
  console.log("Sth happened")
  res.json({ status: 200 });
});

I am trying to deploy it and use ingress to expose it to my localhost.

What I have done: In etc/hosts I have added:

127.0.0.1 123test.mydomain.com

The ingress looks like:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mytestservice
  namespace: mytestservice
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: 123test.mydomain.com
      http:
        paths:
          - pathType: ImplementationSpecific
            path: /
            backend:
              service:
                name: mytestservice
                port:
                  number: 80

Service:

apiVersion: v1
kind: Service
metadata:
  name: mytestservice
spec:
  ports:
  - name: http
    port: 80
    targetPort: 3000
  selector:
    name: mytestservice

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mytestservice
spec:
  replicas: 1
  selector:
    matchLabels:
      name: mytestservice
  template:
    metadata:
      labels:
        name: mytestservice
    spec:
      containers:
        - name: mytestservice
          image: myimagename
          imagePullPolicy: IfNotPresent 
          ports:
            - containerPort: 3000
          env:
              ...my envs, doesnt matter

When I deploy it the pod is up and running because I am able to see startup logs The ingress description

kubectl get ingress mytestservice
NAME        CLASS    HOSTS                     ADDRESS   PORTS     AGE
mytestservice   <none>   123test.mydomain.com             80, 443   53s

kubectl describe ingress mytestservice
Name:             mytestservice
Namespace:        mytestservice
Address:
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                     Path  Backends
  ----                     ----  --------
  123test.mydomain.com
                           /   mytestservice:80 (10.1.0.16:3000)
Annotations:               kubernetes.io/ingress.class: nginx
                           meta.helm.sh/release-name: mytestservice
                           meta.helm.sh/release-namespace: mytestservice
Events:                    <none>

When i CURL it I receive:

curl 123test.mydomain.com/test
curl: (7) Failed to connect to 123test.mydomain.com port 80: Connection refused 

CodePudding user response:

did you create all the resources in the same namespace? I see your ingress is defined as:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mytestservice
  namespace: mytestservice

so it will be created in the mytestservice namespace. Whereas your deployment and service doesn't have the namespace: mytestservice in metadata. So they will be created in the default namespace.

check if all your resources are in the same namespace:

kubectl get deployments --namespace mytestservice
kubectl get service --namespace mytestservice
kubectl get ingress --namespace mytestservice

a hint to the error is in the describe of the ingress:

Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)

CodePudding user response:

The problem is DNS. With your local /etc/hosts you are pointing to localhost instead to the IP of your Kubernetes host.

  • Related