[英]Kubernetes NGINX Ingress Controller 404 Not found / Object not found
I am taking a course in Udemy and I am new to the world of Kubernetes and I am trying to configure ingress nginx controller in Kubernetes but it returns 404 not found when i send a request at specified URL, it has been 10 days that I am trying to fix it, i've looked at similar questions but none of their answers are working for me.我正在 Udemy 学习一门课程,我是Kubernetes世界的新手,我正在尝试在 Kubernetes 中配置入口 nginx 控制器,但是当我在指定的 URL 发送请求时它返回404 not found ,我已经 10 天了试图解决它,我看过类似的问题,但他们的答案都没有对我有用。 I am also using Skaffold to do build/deploy image on docker hub automatically when i change something in files.
当我更改文件中的某些内容时,我还使用Skaffold在docker hub 上自动构建/部署图像。
My express app server:我的快递应用服务器:
app.get('/api/users/currentuser', (req, res) => {
res.send('Hi there');
});
app.listen(3000, () => {
console.log('[Auth] - Listening on port 3000');
});
ingress-srv.yaml 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 (Auth deployment & srv) 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 file: 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 : Dockerfile :
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]
I also executed command from NGINX Ingress Controller docs :我还从NGINX Ingress Controller 文档中执行了命令:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.5/deploy/static/provider/cloud/deploy.yaml
I also changed hosts.file in the system: 127.0.0.1 ticketing.com我也改了系统中的hosts.file:127.0.0.1 ticketing.com
Logs:日志:
kubectl get pods kubectl 获取豆荚
NAME READY STATUS RESTARTS AGE
auth-depl-5f89899d9f-wtc94 1/1 Running 0 6h33m
kubectl get svc 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 get pods --namespace=ingress-nginx 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 get ing kubectl 获取
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-srv <none> ticketing.com localhost 80 23h
kubectl describe ing ingress-srv 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
Could there be a problem with the Windows IIS web server? Windows IIS Web 服务器是否有问题? since I previously configured something for another project, and in the screenshot above I see:
因为我之前为另一个项目配置了一些东西,在上面的截图中我看到:
Requested URL http://ticketing.com:80/api/users/currentuser
Physical Path C:\inetpub\wwwroot\api\users\currentuser
Also the screenshot shows the port :80 at the requested URL but I have the server port 3000?屏幕截图还显示了请求 URL 处的端口:80但我的服务器端口是 3000? + when i request at https it returns:
+ 当我在https 上请求时,它返回:
502 Bad Gateway
nginx
also C:\\inetpub\\wwwroot is strange to me. C:\\inetpub\\wwwroot 对我来说也很陌生。
Any ideas would help me a lot with continuing the course.任何想法都会对我继续学习课程有很大帮助。
After a few days of research I finally solved the problem, the problem was with IIS Web Server which I had enabled when I was working on a project in ASP.NET core, I uninstalled it and the problem was solved.经过几天的研究,我终于解决了问题,问题出在我在 ASP.NET core 中处理项目时启用的 IIS Web Server,我将其卸载并解决了问题。
How to uninstall IIS from Windows 10:如何从 Windows 10 卸载 IIS:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.