How to expose k8s cluster using Ingress on local dev env?

9/25/2021

I have created a cluster using minikube. Added deployment and a cluster IP service to it. Now I want to access this resource from outside the cluster, using curl or browser and nginx routing using the nginx ingress controller. I have enabled ingress and applied the following ingrwess-srv.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: my-domain.dev
      http:
        paths:
          - path: /auth
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3003

This is my auth-depl.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: my-image-from-docker-hub
          env:
            - name: MONGO_URI
              value: 'mongodb://auth-mongo-srv:27017/auth'
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3003
      targetPort: 3003

Then I run: kubectl get ingress and thats the result:

NAME              CLASS   HOSTS          ADDRESS        PORTS   AGE
example-ingress   nginx   my-domain.dev  182.138.19.21   80      48m

and then I add in the /etc/hosts using sudo:

182.138.19.21 my-domain.dev

And then run: curl my-domain.dev and no response is comming.

How can I make access the dev cluster in my local env so I can develop on it?

Also tried use skaffold, which actually reflects changes in the src dirs, but I don't find a way to access them via browser.

-- Raz Buchnik
ingress-controller
kubernetes
minikube
nginx-ingress
skaffold

0 Answers