Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes / Minikube Ingress error (301 Moved Permanently)

I am following the Kubernetes tutorials and am using Minikube as my Kubernetes environment on my MacBook. All of the steps in the tutorial work well, with the exception of getting Ingress working (tutorial for Ingress that I am following is at: https://cloud.google.com/container-engine/docs/tutorials/http-balancer). I am getting a "301 Moved Permanently" error when accessing via Ingress.

My environment:

  • MacBook (macOS Sierra, version: 10.12.5 (16F73))
  • xhyve driver recommended for Minikube
  • minikube version: v0.19.0

I am using the default Ingress controller (nginx for minikube) and have successfully enabled ingress:

minikube addons enable ingress

I then followed the steps in the tutorial:

Step 1: Deploy an nginx server (SUCCESSFUL)

kubectl run nginx --image=nginx --port=80

Step 2a: Expose your nginx deployment as a service internally (SUCCESSFUL)

kubectl expose deployment nginx --target-port=80  --type=NodePort

Step 2b: Verify that the service is available:

kubectl get service nginx

Output:

NAME      CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
nginx     10.0.0.170   <nodes>       80:31635/TCP   7s

From the above, I know that the service is created properly...

Step 3: Create an Ingress resource (SUCCESSFUL)

Ingress config YAML (basic-ingress.yaml):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: basic-ingress
spec:
  backend:
    serviceName: nginx
    servicePort: 80

And now applying the YAML:

kubectl apply -f basic-ingress.yaml

Step 4a: Verify the Ingress

kubectl get ingress basic-ingress

Output:

NAME            HOSTS     ADDRESS         PORTS     AGE
basic-ingress   *         192.168.64.37   80        16s

Step 4b: Visit the Application (* UNSUCCESSFUL *)

The tutorial states that I should "point my browser to the external IP address of your application and see the web page titled “Welcome to nginx!”.

When I point my browser to the site (http://192.168.64.37) is tries to convert to https which gives an error "secure connection failed" (from Firefox, but similar error from Chrome)

However, when I curl the site I get the "301" error:

curl 192.168.64.37

Output:

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

I have been trying to debug this but no luck so far, however, I have provided further information below... Perhaps it will be useful in diagnosing the issue:

Full Ingress Description:

kubectl describe ingress

Output:

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

The following are the nginx Ingress pod logs:

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 

One last note... When I added a "host:" tag in the basic-ingress.yaml file, and mapped the hostname used in the basic-ingress.yaml files to an IP address (192.168.64.37) in /etc/hosts, then I was able to make it work. Not sure why Minikube would require a "host" tag where the near-identical tutorial runs on GCE without the host tag.

like image 413
Eric Broda Avatar asked May 26 '17 15:05

Eric Broda


1 Answers

After some experimentation, it appears that the nginx ingress addon incorrectly tries to re-direct to an https protocol (port 443) but if this is not configured (which is my case), then the "301 Moved Permanently" error occurs... so to address this, I set the ssl-redirect flag as follows (see the new annotation tag ingress.kubernetes.io/ssl-redirect which was set to "false") which seemed to fix the issue.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: basic-ingress
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  backend:
    serviceName: nginx
    servicePort: 80
like image 186
Eric Broda Avatar answered Nov 01 '22 17:11

Eric Broda