我已经按照文档(安装指南(设置了Nginx-Ingress
控制器,并使用提供的示例按照步骤进行操作。当我尝试使用curl
命令访问服务时,我收到400
错误请求。当我查看nginx-ingress
pod 的日志时,我没有看到任何错误。我附上了日志以供参考。我发现很难解决问题。哪里
fetch the pods from the nginx-ingress namespace
$ kubectl get po -n nginx-ingress
NAME READY STATUS RESTARTS AGE
coffee-7c45f487fd-965dq 1/1 Running 0 46m
coffee-7c45f487fd-bncz5 1/1 Running 0 46m
nginx-ingress-7f4b784f79-7k4q6 1/1 Running 0 48m
tea-7769bdf646-g559m 1/1 Running 0 46m
tea-7769bdf646-hlr5j 1/1 Running 0 46m
tea-7769bdf646-p5hp8 1/1 Running 0 46m
making the request. I have set up the DNS record in the /etc/hosts file
$ curl -vv http://cafe.example.com/coffee
GET /coffee HTTP/1.1
> Host: cafe.example.com
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Server: nginx/1.17.10
< Date: Mon, 11 May 2020 17:36:31 GMT
< Content-Type: text/html
< Content-Length: 158
< Connection: close
checking the logs after the curl request
$ kubectl logs -n nginx-ingress nginx-ingress-7f 4b784f79-7k4q6
100.96.1.1 - - [11/May/2020:17:31:48 +0000] "PROXY TCP4 172.20.61.112 172.20.61.112 8340 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:31:51 +0000] "PROXY TCP4 172.20.81.142 172.20.81.142 40392 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:31:58 +0000] "PROXY TCP4 172.20.61.112 172.20.61.112 8348 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:32:01 +0000] "PROXY TCP4 172.20.81.142 172.20.81.142 40408 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:32:08 +0000] "PROXY TCP4 172.20.61.112 172.20.61.112 8360 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:32:11 +0000] "PROXY TCP4 172.20.81.142 172.20.81.142 40414 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:32:18 +0000] "PROXY TCP4 3.6.94.242 172.20.81.142 35790 80" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:32:18 +0000] "PROXY TCP4 172.20.61.112 172.20.61.112 8366 32579" 400 158 "-" "-" "-"
100.96.1.1 - - [11/May/2020:17:32:21 +0000] "PROXY TCP4 172.20.81.142 172.20.81.142 40422 32579" 400 158 "-" "-" "-"
添加以下注释后,我能够解决问题。
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/ssl-redirect: true
nginx.ingress.kubernetes.io/force-ssl-redirect: true