kubernetes / ingress-nginx

Ingress-NGINX Controller for Kubernetes
https://kubernetes.github.io/ingress-nginx/
Apache License 2.0
17.26k stars 8.2k forks source link

404 Not found ngnix #6582

Closed DVGY closed 3 years ago

DVGY commented 3 years ago

Host OS: Windows 10. Docker version 19.03.13, build 4484c46d9d (WSL 2 Backend) kubectl version Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"windows/amd64"}

Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:41:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}

I ran this command: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/cloud/deploy.yaml

My Code Running skaffold dev cmd

skaffold dev
Listing files to watch...
 - dvgy/auth
Generating tags...
 - dvgy/auth -> dvgy/auth:e63ddf4-dirty
Checking cache...
 - dvgy/auth: Found. Tagging
Tags used in deployment:
 - dvgy/auth -> dvgy/auth:9029b37d0e6a3bf1b5cc8cb4c5ce596d61e4ef5869bc0e34decb13586494cd93
Starting deploy...
 - deployment.apps/auth-depl configured
 - service/auth-srv configured
 - Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
 - ingress.extensions/ingress-service configured
Waiting for deployments to stabilize...
 - deployment/auth-depl: creating container auth
    - pod/auth-depl-6d7c7594b8-t2859: creating container auth
 - deployment/auth-depl is ready.
Deployments stabilized in 7.5991142s
Press Ctrl+C to exit
Watching for changes...
[auth]
[auth] > shopme@1.0.0 start
[auth] > ts-node-dev src/index.ts
[auth]
[auth] [INFO] 12:52:04 ts-node-dev ver. 1.0.0 (using ts-node ver. 9.1.0, typescript ver. 4.1.2)
[auth] Listeninig on port 3000!!

I have made change to my hosts file as 127.0.0.1 ticketing.dev

Going to route: https://ticketing.dev/api/users/currentuser give the error image

@DVGY please post the ingress definition.

From the screenshots, you should just use /api/users and remove the use-regex annotation

ingress-srv.yaml

apiVersion: extensions/v1beta1
# apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: ngnix
    ngnix.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: ticketing.dev
      http:
        paths:
          - path: /api/users/?(.*)
            backend:
              serviceName: auth-srv
              servicePort: 3000

auth-depl.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1 # tells how many pods to create
  selector: # tells deployment how to find the pods it's going to create
    matchLabels:
      app: auth
  template: # how to create the pods
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: dvgy/auth
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

scaffold.yaml

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

Running kubectl get svc --all-namespaces and kubectl get ing and kubectl describe ing ingress-service cmd

image

Running kubectl get pods and kubectl get services and kubectl get deployments cmd image

Can you tell me what i am doing wrong, I tried port forwarding and installing the whole kubernetes again. But it did not worked for me.

If you need any information let me know

Thanks

/triage support

k8s-ci-robot commented 3 years ago

@DVGY: The label(s) triage/support cannot be applied, because the repository doesn't have them

In response to [this](https://github.com/kubernetes/ingress-nginx/issues/6582): >Host OS: Windows 10. >Docker version 19.03.13, build 4484c46d9d (WSL 2 Backend) >kubectl version >Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"windows/amd64"} > >Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:41:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"} > >I ran this command: >kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/cloud/deploy.yaml > >Running `skaffold dev` cmd >``` >skaffold dev >Listing files to watch... > - dvgy/auth >Generating tags... > - dvgy/auth -> dvgy/auth:e63ddf4-dirty >Checking cache... > - dvgy/auth: Found. Tagging >Tags used in deployment: > - dvgy/auth -> dvgy/auth:9029b37d0e6a3bf1b5cc8cb4c5ce596d61e4ef5869bc0e34decb13586494cd93 >Starting deploy... > - deployment.apps/auth-depl configured > - service/auth-srv configured > - Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress > - ingress.extensions/ingress-service configured >Waiting for deployments to stabilize... > - deployment/auth-depl: creating container auth > - pod/auth-depl-6d7c7594b8-t2859: creating container auth > - deployment/auth-depl is ready. >Deployments stabilized in 7.5991142s >Press Ctrl+C to exit >Watching for changes... >[auth] >[auth] > shopme@1.0.0 start >[auth] > ts-node-dev src/index.ts >[auth] >[auth] [INFO] 12:52:04 ts-node-dev ver. 1.0.0 (using ts-node ver. 9.1.0, typescript ver. 4.1.2) >[auth] Listeninig on port 3000!! >``` >I have made change to my hosts file as `127.0.0.1 ticketing.dev` > >Going to route: https://ticketing.dev/api/users/currentuser give the error >![image](https://user-images.githubusercontent.com/46158826/101355089-1b6bf880-38bc-11eb-865b-82ad2dba1414.png) > >Running `kubectl get svc --all-namespaces` and `kubectl get ing` and `kubectl describe ing ingress-service` cmd > >![image](https://user-images.githubusercontent.com/46158826/101355291-5ec66700-38bc-11eb-8c31-c29bd5b06703.png) > >Running `kubectl get pods` and `kubectl get services` and `kubectl get deployments` cmd >![image](https://user-images.githubusercontent.com/46158826/101355409-87e6f780-38bc-11eb-887a-e20ab88b4eb5.png) > >Can you tell me what i am doing wrong, I tried port forwarding and installing the whole kubernetes again. But it did not worked for me. > >If you need any information let me know > >Thanks > >/triage support > Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
aledbf commented 3 years ago

@DVGY please post the ingress definition.

From the screenshots, you should just use /api/users and remove the use-regex annotation

DVGY commented 3 years ago

@DVGY please post the ingress definition.

From the screenshots, you should just use /api/users and remove the use-regex annotation

ingress-srv.yaml

apiVersion: extensions/v1beta1
# apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: ngnix
    ngnix.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: ticketing.dev
      http:
        paths:
          - path: /api/users/?(.*)
            backend:
              serviceName: auth-srv
              servicePort: 3000

auth-depl.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1 # tells how many pods to create
  selector: # tells deployment how to find the pods it's going to create
    matchLabels:
      app: auth
  template: # how to create the pods
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: dvgy/auth
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

scaffold.yaml

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

@aledbf i am using /api/users/currentuser end point inside my index.ts file

aledbf commented 3 years ago

You should use something like this:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: ngnix
spec:
  rules:
    - host: ticketing.dev
      http:
        paths:
          - path: /api/users
            backend:
              serviceName: auth-srv
              servicePort: 3000
DVGY commented 3 years ago
/api/users

I still get a deprecated warning when I run scaffold dev image

I also get 404 Not found error

ingress-srv.yaml

apiVersion: networking.k8s.io/v1beta1
# apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: ngnix
    # kubernetes.io/ingress.class: ngnix
    # ngnix.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: ticketing.dev
      http:
        paths:
          #- path: /api/users/?(.*)
          - path: /api/users
            backend:
              serviceName: auth-srv
              servicePort: 3000
aledbf commented 3 years ago

I still get a deprecated warning when I run scaffold dev

That is expected. The warning disappears if you use networking.k8s.io/v1 but that requires a k8s v1.19 cluster.

Please post the ingress-nginx pod log

aledbf commented 3 years ago

Just in case, your application is expecting /api/users right?

DVGY commented 3 years ago

Just in case, your application is expecting /api/users right?

In my case my app in listening at /api/users/currentuser, if i change my -path: /api/users to - path: /api/users/currentuser, still it is showing 404.

app.get("/api/users/currentuser", (req, res) => {
  console.log("I am hit");
  res.send("Hi there");
});

Ingress-ngnix Pod Log: I think there is no pod that runs ingress-service. I tried this command. I am using right command? kubectl get pods

NAME                         READY   STATUS    RESTARTS   AGE
auth-depl-797b7f9dcb-qnw8k   1/1     Running   0          16m

kubectl get pods -n ingress-service

No resources found in ingress-service namespace.

kubectl logs -f ingress-service

Error from server (NotFound): pods "ingress-service" not found

kubectl get pods -n ingress-nginx

No resources found in ingress-nginx namespace.

kubectl logs -f ingress-nginx

Error from server (NotFound): pods "ingress-nginx" not found
DVGY commented 3 years ago

Is there any change that skaffold is not applying kubectl apply properly or there is something off

aledbf commented 3 years ago

Is there any change that skaffold is not applying kubectl apply properly or there is something off

I cannot help you with that.

kubectl get pods -n ingress-nginx

This is strange. You should have pods running in the namespace. Are you sure you installed the ingress controller?

Going to route: https://ticketing.dev/api/users/currentuser give the error

Did you installed metallb or something else? There is no cloud balancer in bare-metal.

DVGY commented 3 years ago

Did you installed metallb or something else? There is no cloud balancer in bare-metal. No, I used this command to install ingress-ngnix: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/cloud/deploy.yaml Website

This is strange. You should have pods running in the namespace. Are you sure you installed the ingress controller? Apart from the above command I did not installed ingress-nginx-controller seperately.

DVGY commented 3 years ago

Is there any change that skaffold is not applying kubectl apply properly or there is something off

I cannot help you with that.

kubectl get pods -n ingress-nginx

This is strange. You should have pods running in the namespace. Are you sure you installed the ingress controller?

Going to route: https://ticketing.dev/api/users/currentuser give the error

Did you installed metallb or something else? There is no cloud balancer in bare-metal.

image Here is something I can see running as ingress-controller. Is this what you are talking about?

DVGY commented 3 years ago

@aledbf kubectl krew install ingress-nginx I ran this command, but then i deleted .krew folder. When i had this plugin installed, it was showing 404 error not found, since i have removed it, by deleting folder, it's still showing same 404.

DVGY commented 3 years ago

@aledbf Found. I think pod is here. So today I started docker desktop and found these pods Capture 2020-12-09 21_24_49-Image instance 2020-12-09 21_24_07-Container instance

Running cmd kubectl get pods -n ingress-nginx image

Running cmd kubectl logs -n ingress-nginx ingress-nginx-controller-c4f944d4d-jb4pb

-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       v0.41.2
  Build:         d8a93551e6e5798fc4af3eb910cef62ecddc8938
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.19.4

-------------------------------------------------------------------------------

I1209 15:36:14.264925       6 flags.go:205] "Watching for Ingress" class="nginx"
W1209 15:36:14.265414       6 flags.go:210] Ingresses with an empty class will also be processed by this Ingress controller
W1209 15:36:14.282961       6 client_config.go:608] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I1209 15:36:14.361776       6 main.go:241] "Creating API client" host="https://10.96.0.1:443"
I1209 15:36:14.729581       6 main.go:285] "Running in Kubernetes cluster" major="1" minor="19" git="v1.19.3" state="clean" commit="1e11e4a2108024935ecfcb2912226cedeafd99df" platform="linux/amd64"
I1209 15:36:16.133366       6 main.go:105] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I1209 15:36:16.136393       6 main.go:115] "Enabling new Ingress features available since Kubernetes v1.18"
W1209 15:36:16.146241       6 main.go:127] No IngressClass resource with name nginx found. Only annotation will be used.
I1209 15:36:16.612526       6 ssl.go:528] "loading tls certificate" path="/usr/local/certificates/cert" key="/usr/local/certificates/key"
I1209 15:36:16.800163       6 nginx.go:249] "Starting NGINX Ingress controller"
I1209 15:36:16.857108       6 event.go:282] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"ingress-nginx", Name:"ingress-nginx-controller", UID:"3a9fee6c-798c-4d54-bd50-9ca5ebadaf50", APIVersion:"v1", ResourceVersion:"1906", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap ingress-nginx/ingress-nginx-controller
I1209 15:36:18.026521       6 store.go:352] "Ignoring ingress" ingress="default/ingress-service" kubernetes.io/ingress.class="" ingressClassName=""
I1209 15:36:18.102456       6 nginx.go:291] "Starting NGINX process"
I1209 15:36:18.102594       6 leaderelection.go:243] attempting to acquire leader lease  ingress-nginx/ingress-controller-leader-nginx...
I1209 15:36:18.104705       6 nginx.go:311] "Starting validation webhook" address=":8443" certPath="/usr/local/certificates/cert" keyPath="/usr/local/certificates/key"
I1209 15:36:18.151056       6 leaderelection.go:253] successfully acquired lease ingress-nginx/ingress-controller-leader-nginx
I1209 15:36:18.153091       6 status.go:84] "New leader elected" identity="ingress-nginx-controller-c4f944d4d-jb4pb"
I1209 15:36:18.157399       6 controller.go:144] "Configuration changes detected, backend reload required"
I1209 15:36:19.512505       6 controller.go:161] "Backend successfully reloaded"
I1209 15:36:19.512941       6 controller.go:172] "Initial sync, sleeping for 1 second"
I1209 15:36:19.513216       6 event.go:282] Event(v1.ObjectReference{Kind:"Pod", Namespace:"ingress-nginx", Name:"ingress-nginx-controller-c4f944d4d-jb4pb", UID:"27e3172f-31bb-4c99-91a5-7276f2323473", APIVersion:"v1", ResourceVersion:"59700", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
E1209 15:44:17.780662       6 leaderelection.go:357] Failed to update lock: Put "https://10.96.0.1:443/api/v1/namespaces/ingress-nginx/configmaps/ingress-controller-leader-nginx": context deadline exceeded
I1209 15:44:17.781029       6 leaderelection.go:278] failed to renew lease ingress-nginx/ingress-controller-leader-nginx: timed out waiting for the condition
I1209 15:44:17.781509       6 leaderelection.go:243] attempting to acquire leader lease  ingress-nginx/ingress-controller-leader-nginx...
I1209 15:44:20.437507       6 leaderelection.go:253] successfully acquired lease ingress-nginx/ingress-controller-leader-nginx
PS C:\Users\Gaurav Yadav\Documents\gitLocal\node with react microservice\ShopMe>

So this is logs after i ran skaffold dev, all of the above command i ran is before i ran skaffold dev

kubectl logs -n ingress-nginx ingress-nginx-controller-c4f944d4d-jb4pb

-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       v0.41.2
  Build:         d8a93551e6e5798fc4af3eb910cef62ecddc8938
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.19.4

------------------------------------------------------------------------------- 

I1209 15:36:14.264925       6 flags.go:205] "Watching for Ingress" class="nginx"
W1209 15:36:14.265414       6 flags.go:210] Ingresses with an empty class will also be processed by this Ingress controller
W1209 15:36:14.282961       6 client_config.go:608] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I1209 15:36:14.361776       6 main.go:241] "Creating API client" host="https://10.96.0.1:443"
I1209 15:36:14.729581       6 main.go:285] "Running in Kubernetes cluster" major="1" minor="19" git="v1.19.3" state="clean" commit="1e11e4a2108024935ecfcb2912226cedeafd99df" platform="linux/amd64"
I1209 15:36:16.133366       6 main.go:105] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I1209 15:36:16.136393       6 main.go:115] "Enabling new Ingress features available since Kubernetes v1.18"
W1209 15:36:16.146241       6 main.go:127] No IngressClass resource with name nginx found. Only annotation will be used.
I1209 15:36:16.612526       6 ssl.go:528] "loading tls certificate" path="/usr/local/certificates/cert" key="/usr/local/certificates/key"
I1209 15:36:16.800163       6 nginx.go:249] "Starting NGINX Ingress controller"
I1209 15:36:16.857108       6 event.go:282] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"ingress-nginx", Name:"ingress-nginx-controller", UID:"3a9fee6c-798c-4d54-bd50-9ca5ebadaf50", APIVersion:"v1", ResourceVersion:"1906", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap ingress-nginx/ingress-nginx-controller
I1209 15:36:18.026521       6 store.go:352] "Ignoring ingress" ingress="default/ingress-service" kubernetes.io/ingress.class="" ingressClassName=""
I1209 15:36:18.102456       6 nginx.go:291] "Starting NGINX process"
I1209 15:36:18.102594       6 leaderelection.go:243] attempting to acquire leader lease  ingress-nginx/ingress-controller-leader-nginx...
I1209 15:36:18.104705       6 nginx.go:311] "Starting validation webhook" address=":8443" certPath="/usr/local/certificates/cert" keyPath="/usr/local/certificates/key"
I1209 15:36:18.151056       6 leaderelection.go:253] successfully acquired lease ingress-nginx/ingress-controller-leader-nginx
I1209 15:36:18.153091       6 status.go:84] "New leader elected" identity="ingress-nginx-controller-c4f944d4d-jb4pb"
I1209 15:36:18.157399       6 controller.go:144] "Configuration changes detected, backend reload required"
I1209 15:36:19.512505       6 controller.go:161] "Backend successfully reloaded"
I1209 15:36:19.512941       6 controller.go:172] "Initial sync, sleeping for 1 second"
I1209 15:36:19.513216       6 event.go:282] Event(v1.ObjectReference{Kind:"Pod", Namespace:"ingress-nginx", Name:"ingress-nginx-controller-c4f944d4d-jb4pb", UID:"27e3172f-31bb-4c99-91a5-7276f2323473", APIVersion:"v1", ResourceVersion:"59700", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
E1209 15:44:17.780662       6 leaderelection.go:357] Failed to update lock: Put "https://10.96.0.1:443/api/v1/namespaces/ingress-nginx/configmaps/ingress-controller-leader-nginx": context deadline exceeded
I1209 15:44:17.781029       6 leaderelection.go:278] failed to renew lease ingress-nginx/ingress-controller-leader-nginx: timed out waiting for the condition
I1209 15:44:17.781509       6 leaderelection.go:243] attempting to acquire leader lease  ingress-nginx/ingress-controller-leader-nginx...
I1209 15:44:20.437507       6 leaderelection.go:253] successfully acquired lease ingress-nginx/ingress-controller-leader-nginx
192.168.65.3 - - [09/Dec/2020:16:08:35 +0000] "GET /api/users/currentuser HTTP/1.1" 400 650 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" 550 0.000 [] [] - - - - 4f8af15ceca151d0182ac60cae4e40a5
192.168.65.3 - - [09/Dec/2020:16:08:36 +0000] "GET /favicon.ico HTTP/1.1" 400 650 "http://127.0.0.1:443/api/users/currentuser" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" 461 0.000 [] [] - - - - b6cb325621c03502373cf653aceefa91
W1209 16:11:45.160120       6 controller.go:216] ignoring ingress ingress-service in default based on annotation kubernetes.io/ingress.class
I1209 16:11:45.160458       6 main.go:112] "successfully validated configuration, accepting" ingress="ingress-service/default"
PS C:\Users\Gaurav Yadav\Documents\gitLocal\node with react microservice\ShopMe>