Kubernetes Ingress not working on Docker for desktop mac

4/8/2021

When setting up an ingress in my kubernetes project I can't seem to get it to work. I already checked following questions:

But I can't get it to work. When testing the service via NodePort (http://kubernetes.docker.internal:30090/ or localhost:30090) it works without any problem, but when using http://kubernetes.docker.internal/ I get kubernetes.docker.internal didn’t send any data. ERR_EMPTY_RESPONSE.

This is my yaml file:

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: gcr.io/google-samples/hello-app:2.0
          env:
            - name: "PORT"
              value: "3000"

---

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: kubernetes.docker.internal
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name:  webapp-service
                port:
                  number: 3000

I also used following command:

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

The output of kubectl get all -A is as follows (indicating that the ingress controller is running):

NAMESPACE       NAME                                            READY   STATUS      RESTARTS   AGE
default         pod/webapp-78d8b79b4f-7whzf                     1/1     Running     0          13m
ingress-nginx   pod/ingress-nginx-admission-create-gwhbq        0/1     Completed   0          11m
ingress-nginx   pod/ingress-nginx-admission-patch-bxv9v         0/1     Completed   1          11m
ingress-nginx   pod/ingress-nginx-controller-6f5454cbfb-s2w9p   1/1     Running     0          11m
kube-system     pod/coredns-f9fd979d6-6xbxs                     1/1     Running     0          19m
kube-system     pod/coredns-f9fd979d6-frrrv                     1/1     Running     0          19m
kube-system     pod/etcd-docker-desktop                         1/1     Running     0          18m
kube-system     pod/kube-apiserver-docker-desktop               1/1     Running     0          18m
kube-system     pod/kube-controller-manager-docker-desktop      1/1     Running     0          18m
kube-system     pod/kube-proxy-mfwlw                            1/1     Running     0          19m
kube-system     pod/kube-scheduler-docker-desktop               1/1     Running     0          18m
kube-system     pod/storage-provisioner                         1/1     Running     0          18m
kube-system     pod/vpnkit-controller                           1/1     Running     0          18m

NAMESPACE       NAME                                         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
default         service/kubernetes                           ClusterIP      10.96.0.1        <none>        443/TCP                      19m
default         service/webapp-service                       NodePort       10.111.167.112   <none>        3000:30090/TCP               13m
ingress-nginx   service/ingress-nginx-controller             LoadBalancer   10.106.21.69     localhost     80:32737/TCP,443:32675/TCP   11m
ingress-nginx   service/ingress-nginx-controller-admission   ClusterIP      10.105.208.234   <none>        443/TCP                      11m
kube-system     service/kube-dns                             ClusterIP      10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP       19m

NAMESPACE     NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/kube-proxy   1         1         1       1            1           kubernetes.io/os=linux   19m

NAMESPACE       NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
default         deployment.apps/webapp                     1/1     1            1           13m
ingress-nginx   deployment.apps/ingress-nginx-controller   1/1     1            1           11m
kube-system     deployment.apps/coredns                    2/2     2            2           19m

NAMESPACE       NAME                                                  DESIRED   CURRENT   READY   AGE
default         replicaset.apps/webapp-78d8b79b4f                     1         1         1       13m
ingress-nginx   replicaset.apps/ingress-nginx-controller-6f5454cbfb   1         1         1       11m
kube-system     replicaset.apps/coredns-f9fd979d6                     2         2         2       19m

NAMESPACE       NAME                                       COMPLETIONS   DURATION   AGE
ingress-nginx   job.batch/ingress-nginx-admission-create   1/1           1s         11m
ingress-nginx   job.batch/ingress-nginx-admission-patch    1/1           3s         11m

I already tried debugging, and when doing an exec to the nginx service: kubectl exec service/ingress-nginx-controller -n ingress-nginx -it -- sh I can do the following curl: curl -H "host:kubernetes.docker.internal" localhost and it returns the correct content. So to me this seems like my loadbalancer service is not used when opening http://kubernetes.docker.internal via the browser. I also tried using the same curl from my terminal but that had the same 'empty response' result.

-- YFrickx
docker
docker-for-mac
kubernetes

0 Answers