我正在关注Kubernetes教程,并将Minikube用作MacBook上的Kubernetes环境。除使Ingress正常工作外,本教程中的所有步骤均正常运行(我关注的Ingress教程位于:https://cloud.google.com/container-engine/docs/tutorials/http-balancer)。通过Ingress访问时出现“301永久移动”错误。
我的环境:
我正在使用默认的Ingress Controller (用于minikube的nginx),并具有
成功启用入口:
minikube addons enable ingress
然后,我按照教程中的步骤进行操作:
步骤1:部署Nginx服务器(SUCCESSFUL)
kubectl run nginx --image=nginx --port=80
步骤2a:在内部将您的Nginx部署公开为服务(成功)
kubectl expose deployment nginx --target-port=80 --type=NodePort
步骤2b:验证服务是否可用:
kubectl get service nginx
输出:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx 10.0.0.170 <nodes> 80:31635/TCP 7s
从上面的内容,我知道该服务已正确创建...
步骤3:建立Ingress资源(SUCCESSFUL)
入口配置YAML(basic-ingress.yaml):
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
spec:
backend:
serviceName: nginx
servicePort: 80
现在应用YAML:
kubectl apply -f basic-ingress.yaml
步骤4a:验证入口
kubectl get ingress basic-ingress
输出:
NAME HOSTS ADDRESS PORTS AGE
basic-ingress * 192.168.64.37 80 16s
步骤4b:访问应用程序( * UNSUCCESSFUL * )
本教程指出,我应该“将浏览器指向您的应用程序的外部IP地址,并查看标题为“Welcome to nginx!”的网页。
当我将浏览器指向站点(http://192.168.64.37)尝试转换为https时,该错误给出了“安全连接失败”错误(来自Firefox,但来自Chrome的类似错误)
但是,当我 curl 站点时,出现“301”错误:
curl 192.168.64.37
输出:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.11.12</center>
</body>
</html>
我一直在尝试调试此问题,但到目前为止还没有运气,但是,我在下面提供了更多信息...也许对诊断问题很有用:
完整入口说明:
kubectl describe ingress
输出:
Name: basic-ingress
Namespace: default
Address: 192.168.64.38
Default backend: nginx:80 (172.17.0.3:80)
Rules:
Host Path Backends
---- ---- --------
* * nginx:80 (172.17.0.3:80)
Annotations:
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
3m 3m 1 {ingress-controller } Normal CREATE Ingress default/basic-ingress
3m 3m 1 {ingress-controller } Normal UPDATE Ingress default/basic-ingress
以下是Nginx Ingress Pod日志:
2017-05-26T16:08:27.142309346Z I0526 16:08:27.142156 1 launch.go:101] &{NGINX 0.9.0-beta.4 git-72bb2222 [email protected]:ixdy/kubernetes-ingress.git}
2017-05-26T16:08:27.142345769Z I0526 16:08:27.142218 1 launch.go:104] Watching for ingress class: nginx
2017-05-26T16:08:27.142350322Z I0526 16:08:27.141160 1 nginx.go:180] starting NGINX process...
2017-05-26T16:08:27.142834005Z I0526 16:08:27.142764 1 launch.go:257] Creating API server client for https://10.0.0.1:443
2017-05-26T16:08:27.166946862Z I0526 16:08:27.166808 1 launch.go:120] validated kube-system/default-http-backend as the default backend
2017-05-26T16:08:27.174640373Z I0526 16:08:27.174527 1 controller.go:1184] starting Ingress controller
2017-05-26T16:08:27.175954273Z I0526 16:08:27.175092 1 leaderelection.go:203] attempting to acquire leader lease...
2017-05-26T16:08:27.183187824Z I0526 16:08:27.183085 1 leaderelection.go:213] successfully acquired lease kube-system/ingress-controller-leader-nginx
2017-05-26T16:08:28.175881543Z W0526 16:08:28.175472 1 backend_ssl.go:42] deferring sync till endpoints controller has synced
2017-05-26T16:08:28.179906454Z W0526 16:08:28.179769 1 queue.go:94] requeuing kube-system/default-http-backend, err deferring sync till endpoints controller has synced
2017-05-26T16:08:31.207329775Z I0526 16:08:31.206860 1 event.go:217] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"basic-ingress", UID:"8fd367b9-422d-11e7-9dd4-d68827e778d4", APIVersion:"extensions", ResourceVersion:"278", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/basic-ingress
2017-05-26T16:08:37.353651374Z I0526 16:08:37.353525 1 metrics.go:34] changing prometheus collector from to default
2017-05-26T16:08:37.416440774Z I0526 16:08:37.416333 1 controller.go:421] ingress backend successfully reloaded...
2017-05-26T16:08:57.183350506Z I0526 16:08:57.183046 1 status.go:302] updating Ingress default/basic-ingress status to [{192.168.64.38 }]
2017-05-26T16:08:57.186454653Z I0526 16:08:57.186366 1 event.go:217] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"basic-ingress", UID:"8fd367b9-422d-11e7-9dd4-d68827e778d4", APIVersion:"extensions", ResourceVersion:"327", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress default/basic-ingress
2017-05-26T16:08:57.471160018Z W0526 16:08:57.471017 1 queue.go:94] requeuing kube-system/ingress-controller-leader-nginx, err
2017-05-26T16:08:57.471182113Z -------------------------------------------------------------------------------
2017-05-26T16:08:57.471185648Z Error: exit status 1
2017-05-26T16:08:57.471188375Z nginx: the configuration file /tmp/nginx-cfg585054790 syntax is ok
2017-05-26T16:08:57.47119123Z 2017/05/26 16:08:57 [emerg] 164#164: no "events" section in configuration
2017-05-26T16:08:57.471194521Z nginx: [emerg] no "events" section in configuration
2017-05-26T16:08:57.471197512Z nginx: configuration file /tmp/nginx-cfg585054790 test failed
2017-05-26T16:08:57.471200655Z
2017-05-26T16:08:57.471203144Z -------------------------------------------------------------------------------
2017-05-26T16:09:37.260238379Z E0526 16:09:37.260068 1 controller.go:417] unexpected failure restarting the backend:
2017-05-26T16:09:37.260266173Z 2017/05/26 16:09:37 [emerg] 182#182: no "events" section in configuration
2017-05-26T16:09:37.260271749Z nginx: [emerg] no "events" section in configuration
2017-05-26T16:09:37.260276045Z W0526 16:09:37.260095 1 queue.go:94] requeuing kube-system/kube-dns, err exit status 1
2017-05-26T16:09:47.20646199Z I0526 16:09:47.206349 1 controller.go:421] ingress backend successfully reloaded...
2017-05-26T16:10:22.518854138Z 192.168.64.1 - [192.168.64.1] - - [26/May/2017:16:10:22 +0000] "GET / HTTP/1.1" 404 21 "-" "curl/7.51.0" 77 0.001 [upstream-default-backend] 172.17.0.4:8080 21 0.001 404
2017-05-26T16:10:30.797507654Z 192.168.64.1 - [192.168.64.1] - - [26/May/2017:16:10:30 +0000] "GET / HTTP/1.1" 404 21 "-" "curl/7.51.0" 77 0.000 [upstream-default-backend] 172.17.0.4:8080 21 0.000 404
最后一点...当我在basic-ingress.yaml文件中添加“host:”标签,并将basic-ingress.yaml文件中使用的主机名映射到/etc/中的IP地址(192.168.64.37)时主机,那么我能够使其工作。不确定Minikube为什么需要“主机”标签,而几乎完全相同的教程在没有主机标签的情况下在GCE上运行。
最佳答案
经过一些实验后,似乎nginx入口插件错误地尝试重定向到https协议(protocol)(端口443),但是如果未配置(这是我的情况),则会发生“301永久移动”错误...为了解决这个问题,我将ssl-redirect标志设置如下
(请参见新的注释标签ingress.kubernetes.io/ssl-redirect
设置为“假”),这似乎可以解决该问题。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
spec:
backend:
serviceName: nginx
servicePort: 80
关于nginx - Kubernetes/Minikube入口错误(永久移动了301),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44205593/