簡體   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