简体   繁体   English

无法在 nodejs 中使用带有 kubernetes 的 ingress-nginx 访问服务器

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

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 :我在根文件夹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 .我创建了一个名为infra的文件夹,并在其中创建了一个名为k8s的文件夹。 in this folder i create two file:在这个文件夹中,我创建了两个文件:

A: auth-depl.yaml答: 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 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:并进入/etc/hosts我写这个:

 # 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.当我想在这条路线https://ticketing.dev/api/user/currentuser中使用 go 时,它不会显示我的任何东西。 i test the server seprate the kubernetes by this https://localhost:4000/api/user/currentuser and it works.我通过这个https://localhost:4000/api/user/currentuser测试服务器分离 kubernetes 并且它可以工作。

whats the prblem?什么问题? how can i solve this problem?我怎么解决这个问题?

Solution : Solution

  1. Go to your terminal Go 到您的终端
  2. Enter minikube ip - you will get minikube ip ( examle: 172.17.0.2)输入minikube ip - 你会得到 minikube ip(例如:172.17.0.2)
  3. Edit /etc/hosts : Edit /etc/hosts

change 127.0.1.1 ticketing.dev to 172.17.0.2 (minikube ip) ticketing.dev127.0.1.1 ticketing.dev更改为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.你不能在这里写本地 ip 地址(127.0.1.1),你应该在这里写 minikube ip 地址(172.17.0.2),因为你使用的是 minikube。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM