0

Not able to access the node js application I am running inside the K8s cluster with docker desktop. Below are the Objects Skaffold Config:

apiVersion: skaffold/v2beta26
kind: Config
deploy:
  kubectl:
    manifests:
      - ./objects/*
build:
  local:
    push: false
  artifacts:
    - image: sq/accounts-backend
      context: ../accounts-backend
      docker:
        dockerfile: Dockerfile.dev
      sync:
        manual:
          - src: "**/*.js"
            dest: .
          - src: "public/**/*.css"
            dest: .

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: accounts-backend-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      component: accounts-backend
  template:
    metadata:
      labels:
        component: accounts-backend
    spec:
      containers:
        - name: accounts-backend
          image: sq/accounts-backend
          ports:
            - containerPort: 5000
          env:

Cluster IP:

apiVersion: v1
kind: Service
metadata:
  name: accounts-backend-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: accounts-backend
  ports:
    - port: 5000
      targetPort: 5000

Ingress:

apiVersion: networking.k8s.io/v1
# UPDATE API
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/use-regex: "true"
    # ADD ANNOTATION
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    # UPDATE ANNOTATION
spec:
  rules:
    - http:
        paths:
          - path: /api/?(.*)
            # UPDATE PATH
            pathType: Prefix
            # ADD PATHTYPE
            backend:
              service:
                # UPDATE SERVICE FIELDS
                name: accounts-backend-cluster-ip-service
                port:
                  number: 5000

I was able to verify that the Deployment is up and the application is running by executing skaffold dev. I have tried accessing localhost, 127.0.0.1, and the internal IP of the docker but not able to access the application. I am getting Connection took too long and connection refused when trying inside the browser.

Output from the ingress describe:

Name:             ingress-service
Namespace:        default
Address:
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /api/?(.*)   accounts-backend-cluster-ip-service:5000 (10.1.0.50:5000,10.1.0.51:5000)
Annotations:  kubernetes.io/ingress.class: nginx
              nginx.ingress.kubernetes.io/rewrite-target: /$1
              nginx.ingress.kubernetes.io/use-regex: true
Events:       <none>
harish durga
  • 494
  • 4
  • 12
  • try curl `localhost/api/` or `localhost/api/abc` – Harsh Manvar Jan 20 '22 at 07:05
  • Did that. Localhost refused to connect. – harish durga Jan 20 '22 at 07:23
  • Which version of Kubernetes did you use? Could you add logs to the question from your ingress? – Mikołaj Głodziak Jan 20 '22 at 15:03
  • Here is the output: Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:38:33Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:42:41Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"} – harish durga Jan 20 '22 at 15:11
  • Please add logs to the question from your ingress. – Mikołaj Głodziak Jan 21 '22 at 14:18
  • I have added the describe command's output to the question. – harish durga Jan 21 '22 at 17:03

1 Answers1

1

By default, skaffold dev only port-forwards user-defined port-forwards, those that are explicitly defined in the skaffold.yaml. For example:

portForward:
- resourceType: deployment
  resourceName: accounts-backend-deployment
  port: 5000
  localPort: 8080

You can use skaffold dev --port-forward=user,services to also port-forward services as well as any user-defined port-forwards.

Skaffold port-forwarding does not include ingress: that's currently cluster-specific. For example, with minikube, you'll need to run minikube tunnel separately, or alternatively minikube service -n ingress-nginx --url ingress-nginx-controller if using nginx-ingress.

Brian de Alwis
  • 2,814
  • 2
  • 18
  • 32
  • Thank you for the answer, but what if I want to test the ingress controller service ? – harish durga Jan 22 '22 at 11:44
  • From this [other question](https://stackoverflow.com/a/65200951/600339), it seems that Docker Desktop will already expose the cluster as `kubernetes.docker.internal` You just need to ensure you’ve installed the nginx-ingress controller. – Brian de Alwis Jan 23 '22 at 17:06