Not able access the application running with skaffold and docker desktop on WSL 2

1/20/2022

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
docker-desktop
kubernetes
skaffold
wsl-2

1 Answer

1/21/2022

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
Source: StackOverflow