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: 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 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.
6 Answers
Finally I found the way to fix. I have to deploy ingress Nginx by command:
kubectl apply -f (Follows the instruction at . It works just fine for Docker for Windows)
Now I can access successfully.
5You 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 Using kubectl (see documentation):
kubectl apply -f 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 :
- 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
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 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 .
Example you can see here: wsl2-docker-for-desktop.
2I used the Docker-Desktop version to install the nginx-ingress controller 
Offcourse I've not installed any workload yet but the default ingress controller works just fine.
With Kustomize you can simply use
helmCharts: - name: ingress-nginx releaseName: ingress-nginx repo: This is just to point out that Amel Mahmuzićs comment is still valid with a recent (I used the ingress-nginx Helm Chart 4.4.2) ingress deployment.
I could not get this to work for far too long (I tried to follow the Strapi fodadvisor example with Docker Desktop build in Kubernetes instead of minikube) and always received a 404 from the ingress.
However, after using this yaml with the added annotation
apiVersion: kind: Ingress metadata: name: main-ingress annotations: "nginx" spec: rules: - host: foodadvisor.backend http: paths: - path: / pathType: Prefix backend: service: name: foodadvisor-backend port: number: 1337 - host: foodadvisor.client http: paths: - path: / pathType: Prefix backend: service: name: foodadvisor-frontend port: number: 3000 it worked immediately. The K82 docs mention, that this annotation is deprecated.
1
