繁体   English   中英

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

[英]Kubernetes NGINX Ingress Controller 404 Not found / Object not found

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

404找不到截图

我的快递应用服务器:

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

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

ingress-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

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

skaffold.yaml文件:

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

Dockerfile

FROM node:alpine

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

CMD ["npm", "start"]

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

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.5/deploy/static/provider/cloud/deploy.yaml

我也改了系统中的hosts.file:127.0.0.1 ticketing.com

日志:

kubectl 获取豆荚

NAME                         READY   STATUS    RESTARTS   AGE
auth-depl-5f89899d9f-wtc94   1/1     Running   0          6h33m

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

kubectl 获取 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

kubectl 获取

NAME          CLASS    HOSTS           ADDRESS     PORTS   AGE
ingress-srv   <none>   ticketing.com   localhost   80      23h

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

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

Requested URL      http://ticketing.com:80/api/users/currentuser
Physical Path      C:\inetpub\wwwroot\api\users\currentuser

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

502 Bad Gateway
nginx

C:\\inetpub\\wwwroot 对我来说也很陌生。

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

经过几天的研究,我终于解决了问题,问题出在我在 ASP.NET core 中处理项目时启用的 IIS Web Server,我将其卸载并解决了问题。

如何从 Windows 10 卸载 IIS:

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

暂无
暂无

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

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