Enable Ingress controller on Docker Desktop with WLS2

12/8/2020

Currently, I'm using Docker Desktop with WSL2 integration. I found that Docker Desktop automatically had created a cluster for me. It means I don't have to install and use Minikube or Kind to create cluster. The problem is that, how could I enable Ingress Controller if I use "built-in" cluster from Docker Desktop? I tried to create an Ingress to check if this work or not, but as my guess, it didn't work.

The YAML file I created as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp
spec:
  minReadySeconds: 30
  selector:
    matchLabels:
      app: webapp
  replicas: 1
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        image: nodejs-helloworld:v1

--- 

apiVersion: v1
kind: Service
metadata:
  name: webapp-service

spec:
  selector: 
    app: webapp
  
  ports:
    - name: http
      port: 3000
      nodePort: 30090 # only for NotPort > 30,000
    
  type: NodePort #ClusterIP inside cluster

---

apiVersion: networking.k8s.io/v1
kind: Ingress 
metadata:
  name: webapp-ingress
spec:
  defaultBackend:
    service:
      name: webapp-service
      port:
        number: 3000
  rules:
  - host: ingress.local
    http:
      paths:
      - path: / 
        pathType: Prefix
        backend:
          service:
            name:  webapp-service
            port: 
              number: 3000
    

I tried to access ingress.local/ but it was not successful. (I added ingress.local to point to 127.0.0.1 in host file. And the webapp worked fine at kubernetes.docker.internal:30090 )

Could you please help me to know the root cause? Thank you.

-- tuq
docker
kubernetes
windows-subsystem-for-linux
wsl-2

4 Answers

12/9/2020

Finally I found the way to fix. I have to deploy ingress Nginx by command:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/cloud/deploy.yaml

(Follows the instruction at https://kubernetes.github.io/ingress-nginx/deploy/#docker-for-mac. It works just fine for Docker for Windows)

Now I can access http://ingress.local successfully.

-- tuq
Source: StackOverflow

1/18/2021

You have to install an ingress-nginx controller on your cluster, so that your nodes will have an opened port 80/443.

Using helm (v3 - see documentation):

helm install --namespace kube-system nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx

Using kubectl (see documentation):

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.43.0/deploy/static/provider/cloud/deploy.yaml

Then manually adding your ingresses' hostnames to /etc/hosts:

127.0.0.1     ingress.local
127.0.0.1     my.other.service.local
# ...

Then if you make a request on http://ingress.local:

  • the DNS resolution will route to your cluster node
  • then the ingress controller will serve the request on port 80
  • then ingress will route the request to the configured backend service
  • and the service will route to an available pod
-- Donatello
Source: StackOverflow

12/8/2020

The newest version of Docker Desktop for Windows already adds a hosts file entry: 127.0.0.1 kubernetes.docker.internal.

You had to do use kubernetes.docker.internal URL as a hostname in Ingress definition if you want to point to 127.0.0.1. This should be in the docs on this page kubernetes.github.io/ingress-nginx/deploy but there is no Docker Desktop for Windows section there. Your files should look like this:

apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  type: NodePort
  selector:
    app: webapp
  ports:
  - name: http
    protocol: TCP
    port: 3000
    nodePort: 30090

Your Ingress file should look like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: webapp-ingress 
spec:
  rules:
  - host: kubernetes.docker.internal
    http:
      paths:
      - path: /
        backend:
          serviceName: webapp-service 
          servicePort: http

Then you are able to connect to app using http://kubernetes.docker.internal/.

Example you can see here: wsl2-docker-for-desktop.

-- Malgorzata
Source: StackOverflow

8/25/2021

I used the Docker-Desktop version to install the nginx-ingress controller https://kubernetes.github.io/ingress-nginx/deploy/#docker-desktop Installing Kubernetes Ingress Controller Docker Desktop Windows

curl http://kubernetes.docker.internal/

enter image description here

Offcourse I've not installed any workload yet but the default ingress controller works just fine.

-- Rohit Salecha
Source: StackOverflow