can not access to server with ingress-nginx with kubernetes in nodejs

12/15/2020

i want to access to the server with this route but not worked . https://ticketing.dev/api/user/currentuser

i craete in the root folder skaffold.yaml:

apiVersion: skaffold/v2beta11
kind: Config
deploy:
  kubectl:
    manifests:
      - ./infra/k8s/*
build:
  local:
    push: false
  artifacts:
    - image: kia9372/auth
      context: auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .

and i crate a folder by name infra and in that i create a folder by name k8s . in this folder i create two file :

A : 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: kia9372/auth
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 4000
      targetPort: 4000

B : ingress-srv.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: ticketing.dev
  - http:
      paths:
      - path: /api/user/?(.*)
        backend:
          service:
            name: auth-srv
            port:
              number: 4000

and into the /etc/hosts i writeing this :

 # The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


127.0.0.1	localhost
127.0.1.1	mr-programmer
127.0.1.1	ticketing.dev

but now i have a problem . when i want to go in this route https://ticketing.dev/api/user/currentuser it not show my any things . i test the server seprate the kubernetes by this https://localhost:4000/api/user/currentuser and it works .

whats the prblem ? how can i solve this problem ?

-- Mr-Programer
kubernetes
nginx
nginx-ingress
node.js

1 Answer

12/15/2020

Solution : 1. Go to your terminal 2. Enter minikube ip - you will get minikube ip ( examle : 172.17.0.2) 3. Edit /etc/hosts :

change 127.0.1.1 ticketing.dev to 172.17.0.2 (minikube ip) ticketing.dev

You can not write here local ip address(127.0.1.1), you should write here minikube ip address(172.17.0.2), because you are using minikube.

-- Debasis Das
Source: StackOverflow