404找不到入口nginx和400错误请求将纯HTTP请求发送到HTTPS端口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 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!!

我已经将我的主机文件更改为127.0.0.1 ticketing.dev

去路由:https://ticketing.dev/api/users/currentuser给我错误404找不到nginx和卷曲到不同的端口给下面的错误

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 get-svc—所有命名空间

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入口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 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
-------------------------------------------------------------------------------
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:UsersGaurav YadavDocumentsgitLocalnode with react microserviceShopMe> 

首先,您的curl命令没有使用您在ingress规则中配置的主机。

命令应该是:

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

第二:入口类的入口注释需要是:

kubernetes.io/ingress.class: nginx

相关内容

  • 没有找到相关文章

最新更新