Kubernetes NGINX 入口控制器 404 未找到/未找到对象

syc*_*e55 3 nginx kubernetes kubernetes-ingress nginx-config nginx-ingress

我正在 Udemy 学习课程,我是Kubernetes世界的新手,我正在尝试在 Kubernetes 中配置入口 nginx 控制器,但当我在指定的 URL 发送请求时,它返回404 未找到,我已经 10 天了试图解决这个问题,我看过类似的问题,但他们的答案都不适合我。当我更改文件中的某些内容时,我还使用Skaffold自动在 docker hub 上构建/部署映像。

404未找到截图

我的快递应用服务器:

app.get('/api/users/currentuser', (req, res) => {
  res.send('Hi there');
});

app.listen(3000, () => {
  console.log('[Auth] - Listening on port 3000');
});
Run Code Online (Sandbox Code Playgroud)

入口-srv.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-srv
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: ticketing.com
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Prefix
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000
Run Code Online (Sandbox Code Playgroud)

auth-depl.yaml(身份验证部署和 srv)

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: myusername/auth:latest
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  type: ClusterIP
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000
Run Code Online (Sandbox Code Playgroud)

skaffold.yaml文件:

apiVersion: skaffold/v2beta25
kind: Config
deploy:
  kubectl:
    manifests:
      - ./infra/k8s/*
build:
  local:
    push: false
  artifacts:
    - image: username/auth
      context: auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
Run Code Online (Sandbox Code Playgroud)

Dockerfile

FROM node:alpine

WORKDIR /app
COPY package.json .
RUN npm install
COPY . . 

CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)

我还执行了NGINX Ingress Controller 文档中的命令:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.5/deploy/static/provider/cloud/deploy.yaml
Run Code Online (Sandbox Code Playgroud)

我还更改了系统中的hosts.file:127.0.0.1 Ticketing.com

日志:

kubectl 获取 Pod

NAME                         READY   STATUS    RESTARTS   AGE
auth-depl-5f89899d9f-wtc94   1/1     Running   0          6h33m
Run Code Online (Sandbox Code Playgroud)

kubectl 获取 svc

NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
auth-srv     ClusterIP   10.96.23.71   <none>        3000/TCP   23h
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP    25h
Run Code Online (Sandbox Code Playgroud)

kubectl get pods --namespace=ingress-nginx

NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-7fm56        0/1     Completed   0          23h
ingress-nginx-admission-patch-5vflr         0/1     Completed   1          23h
ingress-nginx-controller-5c8d66c76d-89zhp   1/1     Running     0          23h
Run Code Online (Sandbox Code Playgroud)

kubectl 获取

NAME          CLASS    HOSTS           ADDRESS     PORTS   AGE
ingress-srv   <none>   ticketing.com   localhost   80      23h
Run Code Online (Sandbox Code Playgroud)

kubectl 描述 ingress-srv

Name:             ingress-srv
Namespace:        default
Address:          localhost
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host           Path  Backends
  ----           ----  --------
  ticketing.com
                 /api/users/?(.*)   auth-srv:3000 (10.1.0.10:3000)
Annotations:     kubernetes.io/ingress.class: nginx
                 nginx.ingress.kubernetes.io/use-regex: true
Events:
  Type    Reason  Age                 From                      Message
  ----    ------  ----                ----                      -------
  Normal  Sync    22m (x18 over 23h)  nginx-ingress-controller  Scheduled for sync
Run Code Online (Sandbox Code Playgroud)

Windows IIS Web 服务器是否存在问题?因为我之前为另一个项目配置了一些东西,在上面的屏幕截图中我看到:

Requested URL      http://ticketing.com:80/api/users/currentuser
Physical Path      C:\inetpub\wwwroot\api\users\currentuser
Run Code Online (Sandbox Code Playgroud)

屏幕截图还显示请求的 URL 处的端口:80,但我有服务器端口 3000?+ 当我在https请求时它返回:

502 Bad Gateway
nginx
Run Code Online (Sandbox Code Playgroud)

C:\inetpub\wwwroot 对我来说也很奇怪。

任何想法都会对我继续课程有很大帮​​助。

syc*_*e55 5

经过几天的研究,我终于解决了这个问题,问题出在我在 ASP.NET core 项目中启用的 IIS Web Server 上,我卸载了它,问题就解决了。

如何从 Windows 10 卸载 IIS:

  • 转至控制面板 > 程序和功能
  • 单击打开或关闭 Windows 功能
  • 向下滚动至互联网信息服务
  • 单击“Internet 信息服务”旁边的方框,使其变为空
  • 单击“确定”并重新启动 PC(必需)。