0

I have Mac OS and local Docker Desktop with Kubernetes enabled. I want to have a service in local Kubernetes connected to my local java app running on port 8087.

Here is what I have so far:

  1. Service
    apiVersion: v1
    kind: Service
    metadata:
      name: auth
    spec:
      selector:
        app: app-auth
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8087
    ---
    kind: Endpoints
    apiVersion: v1
    metadata:
      name: auth
    subsets:
      - addresses:
          - ip: <127.0.0.1 outside of cluster>
        ports:
          - port: 8087
  1. Ingress
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: router
      annotations:
        kubernetes.io/ingress.class: nginx
    spec:
      rules:
      - host: localhost
        http:
          paths:
          - path: /api/user
            pathType: Prefix
            backend:
              service:
                name: auth
                port:
                  number: 80

I already checked this, but without success since I am not using either minikube either virtual box access-mysql-running-on-localhost-from-minikube how-to-access-hosts-localhost-from-inside-kubernetes-cluster

The Question: what IP should I use for my to-os-localhost-service? Thank you

rgolovakha
  • 518
  • 2
  • 5
  • 17

1 Answers1

0

you can connect to the special DNS name host.docker.internal which resolves to the internal IP address used by your host machine.

The reason is that your service is running in the kubernetes cluster, and not locally on your machine, so it cannot know the existence of 127.0.0.1:8087

Instead of using 127.0.0.1 as this refers to a different address from inside the cluster use host.docker.internal. This is for development purpose and will not work in production.

I hope this helps.

Sanim16
  • 151
  • 3
  • 6