2017-05-26 65 views
2

我遵循Kubernetes教程,並在我的MacBook上使用Minikube作爲我的Kubernetes環境。教程中的所有步驟都運行良好,除了使Ingress正常工作(Ingress的教​​程,我遵循的是:https://cloud.google.com/container-engine/docs/tutorials/http-balancer)。通過Ingress訪問時,出現「301 Moved Permanently」錯誤。Kubernetes/Minikube入口錯誤(301永久移動)

我的環境:

  • 的MacBook(MacOS的塞拉利昂,版本:10.12.5(16F73))推薦Minikube
  • xhyve司機
  • minikube版本:v0.19.0

我使用默認的Ingress控制器(用於minikube的nginx),並且已成功啓用 進入:

minikube addons enable ingress 

我再接着在教程中的步驟:

步驟1:部署一個nginx的服務器(成功)

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步:創建一個入口資源(成功)

入口配置YAML(基本-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地址並查看w eb頁面標題爲「Welcome to nginx!」。

當我指出我的瀏覽器的網站(http://192.168.64.37)是試圖轉換到https這給出了一個錯誤「安全連接失敗」(從Firefox,但在Chrome類似的錯誤)

然而,當我捲曲現場我得到的「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> 

我一直在努力,到目前爲止調試這一點,但沒有運氣,但是,我有省下面ided進一步的信息......也許它會在診斷問題有用:

全部入口說明:

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的入口莢日誌:

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 

最後一個註釋......當我在基礎中添加「host:」標記時ress.yaml文件,並將basic-ingress.yaml文件中使用的主機名映射到/ etc/hosts中的IP地址(192.168.64.37),然後我就可以使其工作。不知道爲什麼Minikube需要一個「主機」標籤,其中幾乎相同的教程在沒有主機標籤的GCE上運行。

回答

3

經過一番實驗,似乎nginx入口插件錯誤地嘗試重定向到https協議(端口443),但如果未配置(這是我的情況),那麼「301 Moved Permanently」錯誤發生......因此,爲了解決這個問題,我設置了ssl-redirect標誌,如下所示: (請參閱新註釋標記ingress.kubernetes.io/ssl-redirect,其中 已設置爲「false」),這似乎解決了問題。

apiVersion: extensions/v1beta1 
kind: Ingress 
metadata: 
    name: basic-ingress 
    annotations: 
    ingress.kubernetes.io/ssl-redirect: "false" 
spec: 
    backend: 
    serviceName: nginx 
    servicePort: 80 
-1

如果您使用的是minikube addons enable ingress,則會部署一個入口控制器(無需部署自己的入口控制器)。也許與兩個入口控制器有衝突。我的建議是刪除您創建的控制器並堅持已由minikube入口插件部署。

+1

我不相信Minikube默認啓用Ingress - 除非啓用「minikube addons enable ingress」,否則Ingress功能不起作用 –