簡體   English   中英

404 Not Found Ingress-nginx 和 400 Bad Request 普通的 HTTP 請求被發送到 HTTPS 端口 nginx

[英]404 Not Found Ingress-nginx and 400 Bad Request The plain HTTP request was sent to HTTPS port nginx

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"}

我運行這個命令來安裝 kubernetes ingress-nginx:

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

https://github.com/DVGY/basic-docker-kuber

運行 skaffold 開發 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!!

我已將主機文件更改為 127.0.0.1 ticketing.dev

要去路由: https://ticketing.dev/api/users/currentuser給我錯誤 404 Not Found nginx 和curl 給不同的端口

curl http://127.0.0.1:443/api/users/currentuser
curl : 400 Bad Request
The plain HTTP request was sent to HTTPS port
nginx


# All YAML Files are here

#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: .

kubectl 獲取 svc --all-namespaces

NAMESPACE       NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
default         auth-srv                             ClusterIP      10.108.121.124   <none>        3000/TCP                     6d2h
default         kubernetes                           ClusterIP      10.96.0.1        <none>        443/TCP                      6d3h
ingress-nginx   ingress-nginx-controller             LoadBalancer   10.110.140.13    localhost     80:31147/TCP,443:32303/TCP   6d2h
ingress-nginx   ingress-nginx-controller-admission   ClusterIP      10.104.133.178   <none>        443/TCP                      6d2h
kube-system     kube-dns                             ClusterIP      10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP       6d3h

kubectl 獲取 pods -n ingress-nginx

NAME                                       READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-fghgd       0/1     Completed   0          6d2h
ingress-nginx-admission-patch-lr2sr        0/1     Completed   0          6d2h
ingress-nginx-controller-c4f944d4d-jb4pb   1/1     Running     7          6d2h

kubectl 日志 -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

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

I1211 15:15:29.155918       7 flags.go:205] "Watching for Ingress" class="nginx"
W1211 15:15:29.156218       7 flags.go:210] Ingresses with an empty class will also be processed by this Ingress controller
W1211 15:15:29.171113       7 client_config.go:608] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I1211 15:15:29.352539       7 main.go:241] "Creating API client" host="https://10.96.0.1:443"
W1211 15:15:52.326223       7 main.go:282] Initial connection to the Kubernetes API server was retried 1 times.
I1211 15:15:52.326410       7 main.go:285] "Running in Kubernetes cluster" major="1" minor="19" git="v1.19.3" state="clean" commit="1e11e4a2108024935ecfcb2912226cedeafd99df" platform="linux/amd64"
I1211 15:15:53.297134       7 main.go:105] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I1211 15:15:53.301436       7 main.go:115] "Enabling new Ingress features available since Kubernetes v1.18"
W1211 15:15:53.312577       7 main.go:127] No IngressClass resource with name nginx found. Only annotation will be used.
I1211 15:15:53.525197       7 ssl.go:528] "loading tls certificate" path="/usr/local/certificates/cert" key="/usr/local/certificates/key"
I1211 15:15:53.762574       7 nginx.go:249] "Starting NGINX Ingress controller"
I1211 15:15:53.832694       7 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    
I1211 15:15:55.138894       7 store.go:352] "Ignoring ingress" ingress="default/ingress-service" kubernetes.io/ingress.class="" ingressClassName=""
I1211 15:15:55.164305       7 nginx.go:291] "Starting NGINX process"
I1211 15:15:55.164376       7 leaderelection.go:243] attempting to acquire leader lease  ingress-nginx/ingress-controller-leader-nginx...
I1211 15:15:55.165971       7 nginx.go:311] "Starting validation webhook" address=":8443" certPath="/usr/local/certificates/cert" keyPath="/usr/local/certificates/key"
I1211 15:15:55.168921       7 controller.go:144] "Configuration changes detected, backend reload required"
I1211 15:15:55.235125       7 leaderelection.go:253] successfully acquired lease ingress-nginx/ingress-controller-leader-nginx
I1211 15:15:55.235473       7 status.go:84] "New leader elected" identity="ingress-nginx-controller-c4f944d4d-jb4pb"
I1211 15:15:56.955152       7 controller.go:161] "Backend successfully reloaded"
I1211 15:15:56.955507       7 controller.go:172] "Initial sync, sleeping for 1 second"
I1211 15:15:56.955751       7 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:"64697", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
W1211 15:15:57.958746       7 controller.go:190] Dynamic reconfiguration failed: Post "http://127.0.0.1:10246/configuration/backends": dial tcp 127.0.0.1:10246: connect: connection refused
E1211 15:15:57.958862       7 controller.go:194] Unexpected failure reconfiguring NGINX:
Post "http://127.0.0.1:10246/configuration/backends": dial tcp 127.0.0.1:10246: connect: connection refused
E1211 15:15:57.958971       7 queue.go:130] "requeuing" err="Post \"http://127.0.0.1:10246/configuration/backends\": dial tcp 127.0.0.1:10246: connect: connection refused" key="initial-sync"
I1211 15:15:58.500927       7 controller.go:144] "Configuration changes detected, backend reload required"
I1211 15:15:58.849780       7 controller.go:161] "Backend successfully reloaded"
I1211 15:15:58.850465       7 controller.go:172] "Initial sync, sleeping for 1 second"
I1211 15:15:58.851686       7 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:"64697", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
W1211 15:23:30.757190       7 controller.go:216] ignoring ingress ingress-service in default based on annotation kubernetes.io/ingress.class
I1211 15:23:30.757399       7 main.go:112] "successfully validated configuration, accepting" ingress="ingress-service/default"
192.168.65.3 - - [11/Dec/2020:15:34:03 +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 [] [] - - - - 6589292b718e14361d4f46f913262ba1
192.168.65.3 - - [11/Dec/2020:15:34:04 +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 [] [] - - - - ce351cc06eb3e5eb5a58a5d288491468
192.168.65.3 - - [11/Dec/2020:15:48:09 +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" 576 0.000 [] [] - - - - 204ee27fe4fbd78d3846754f19572e67
192.168.65.3 - - [11/Dec/2020:15:48:10 +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 [] [] - - - - be6d5396e3b87e8861b44be7dc6b69a1
W1211 16:00:18.493662       7 controller.go:216] ignoring ingress rewrite in default based on annotation kubernetes.io/ingress.class
I1211 16:00:18.494592       7 main.go:112] "successfully validated configuration, accepting" ingress="rewrite/default"
I1211 16:00:18.556281       7 store.go:352] "Ignoring ingress" ingress="default/rewrite" kubernetes.io/ingress.class="" ingressClassName=""
W1211 16:02:34.780388       7 controller.go:216] ignoring ingress ingress-service in default based on annotation kubernetes.io/ingress.class
I1211 16:02:34.780444       7 main.go:112] "successfully validated configuration, accepting" ingress="ingress-service/default"
192.168.65.3 - - [11/Dec/2020:16:06:36 +0000] "GET /api/users/currentuser HTTP/1.1" 400 248 "-" "Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.610" 178 0.000 [] [] - - - - e1d7de4a83d59b24f3f657584891d508
PS C:\Users\Gaurav Yadav\Documents\gitLocal\node with react microservice\ShopMe> 

首先,您的 curl 命令沒有使用您在入口規則中配置的主機。

命令應該是:

curl -H 'Host: ticketing.dev' http://127.0.0.1:443/api/users/currentuser

第二:入口 class 的入口注釋需要是:

kubernetes.io/ingress.class: nginx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM