<p>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: <a href="https://cloud.google.com/container-engine/docs/tutorials/http-balancer" rel="noreferrer">https://cloud.google.com/container-engine/docs/tutorials/http-balancer</a>).  I am getting a "301 Moved Permanently" error when accessing via Ingress.</p>

<p>My environment:</p>

<ul>
<li>MacBook (macOS Sierra, version: 10.12.5 (16F73))</li>
<li>xhyve driver recommended for Minikube</li>
<li>minikube version: v0.19.0</li>
</ul>

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

<pre><code>minikube addons enable ingress
</code></pre>

<p>I then followed the steps in the tutorial:</p>

<p>Step 1:  Deploy an nginx server (SUCCESSFUL)</p>

<pre><code>kubectl run nginx --image=nginx --port=80
</code></pre>

<p>Step 2a:  Expose your nginx deployment as a service internally (SUCCESSFUL)</p>

<pre><code>kubectl expose deployment nginx --target-port=80  --type=NodePort
</code></pre>

<p>Step 2b:   Verify that the service is available:</p>

<pre><code>kubectl get service nginx
</code></pre>

<p>Output:</p>

<pre><code>NAME      CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
nginx     10.0.0.170   &lt;nodes&gt;       80:31635/TCP   7s
</code></pre>

<p>From the above, I know that the service is created properly...</p>

<p>Step 3: Create an Ingress resource (SUCCESSFUL)</p>

<p>Ingress config YAML (basic-ingress.yaml):</p>

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

<p>And now applying the YAML:</p>

<pre><code>kubectl apply -f basic-ingress.yaml
</code></pre>

<p>Step 4a: Verify the Ingress</p>

<pre><code>kubectl get ingress basic-ingress
</code></pre>

<p>Output:</p>

<pre><code>NAME            HOSTS     ADDRESS         PORTS     AGE
basic-ingress   *         192.168.64.37   80        16s
</code></pre>

<p>Step 4b: Visit the Application (<strong>* UNSUCCESSFUL *</strong>)</p>

<p>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!”.</p>

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

<p>However, when I curl the site I get the "301" error:</p>

<pre><code>curl 192.168.64.37
</code></pre>

<p>Output:</p>

<pre><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor="white"&gt;
&lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.11.12&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>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:</p>

<p>Full Ingress Description:</p>

<pre><code>kubectl describe ingress
</code></pre>

<p>Output:</p>

<pre><code>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
</code></pre>

<p>The following are the nginx Ingress pod logs:</p>

<pre><code>2017-05-26T16:08:27.142309346Z I0526 16:08:27.142156       1 launch.go:101] &amp;{NGINX 0.9.0-beta.4 git-72bb2222 git@github.com: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 
</code></pre>

<p>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.</p>

<p>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.</p>

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