<p>Background:</p>
<ul>
<li><code>kubectl</code> version- 1.24</li>
<li>Docker version- 20.10.17</li>
<li>MacOS Monterey v12.4</li>
</ul>
<p>Question:</p>
<p>I'm following <a href="https://blog.gruntwork.io/a-crash-course-on-kubernetes-a96c3891ad82" rel="nofollow noreferrer">this tutorial</a>, trying to set up a local k8s deployment + service.  I successfully ran the following commands:</p>
<pre><code>$ kubectl config use-context docker-desktop
Switched to context &quot;docker-desktop&quot;.

$ kubectl get nodes
NAME             STATUS   ROLES           AGE    VERSION
docker-desktop   Ready    control-plane   154m   v1.24.1

$ kubectl create deployment simple-webapp \
  --image training/webapp \
  --replicas=2 \
  --port=5000
deployment.apps/simple-webapp created

$ kubectl get deployments
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
simple-webapp   2/2     2            2           3m23s

$ kubectl create service loadbalancer simple-webapp \
  --tcp=80:5000
service/simple-webapp created

$ kubectl get services
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP      10.96.0.1       &lt;none&gt;        443/TCP        156m
simple-webapp   LoadBalancer   10.109.168.49   &lt;pending&gt;     80:30582/TCP   9m34s
</code></pre>
<p>However, when I try to run <code>curl http://localhost</code> as mentioned in the tutorial, instead of getting the expected output (<code>Hello world!</code>), I get:</p>
<pre><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.21.2&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>I'm brand-new to k8s and have no idea where to start diagnosing the problem.  Not sure if this is useful info, but I ran <code>docker ps</code> and it looks like there are two k8s-related docker containers currently running:</p>
<pre><code>$ docker ps
CONTAINER ID   IMAGE             COMMAND           CREATED          STATUS          PORTS     NAMES
411b7110b315   training/webapp   &quot;python app.py&quot;   11 minutes ago   Up 11 minutes             k8s_webapp_simple-webapp-5d47556b5-jkvsc_default_9893ef1a-4bc5-43f3-80ac-151d567a89f6_0
9752c12315cc   training/webapp   &quot;python app.py&quot;   11 minutes ago   Up 11 minutes             k8s_webapp_simple-webapp-5d47556b5-269s8_default_5c50b3f8-57a9-4066-bd66-498cd30c758c_0
</code></pre>
<p>I do see <code>nginx</code> referenced in the <code>curl</code> output, does this mean that the 301 redirect is coming from inside the <code>training/webapp</code> process from the Docker container?  If so, how would I fix this?</p>
<p>EDIT: I tried creating both the deployment and service on a different port (<code>5001</code> instead of <code>5000</code>), since when I followed part 1 of the tutorial I ran into problems with port 5000 already being in use.  That worked for part 1 of the tutorial, however unfortunately it didn't solve my problem for part 2- I ran into the same <code>301 redirect</code> problem when using both port 5000 and 5001.</p>
<p>EDIT 2: When I run <code>kubectl get pods</code>, I see the following:</p>
<pre><code>$ kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
simple-webapp-5d47556b5-sg9h4   1/1     Running   0          32s
simple-webapp-5d47556b5-xw2nh   1/1     Running   0          32s
</code></pre>
<p>I continue to see the <code>301 redirect</code> even after running <code>curl</code> to confirm the pods are up.</p>
<p>EDIT 3: I <em>do</em> notice that when I run <code>kubectl get nodes</code>, the single node has a role of <code>control-plane</code>, <em>not</em> <code>control-plane,master</code> as noted in the tutorial.  I also notice that running <code>kubectl get services</code> shows that the <code>EXTERNAL-IP</code> of the loadbalancer is <code>pending</code>, not <code>localhost</code> as expected from the tutorial.  Are either of these facts relevant?</p>
<p>EDIT 4: Further down in the tutorial, we delete both the deployment and service that were previously created, and we re-create them using <code>deployment.yml</code> and <code>service.yml</code> files, alongside the commands <code>kubectl apply -f deployment.yml</code> and <code>kubectl apply -f service.yml</code>.  When I copy/paste the YAML from the tutorial into new files with the specified filenames, I get the same <code>301 Redirect</code> error.</p>
<p>EDIT 5: In <a href="https://news.ycombinator.com/item?id=32216700" rel="nofollow noreferrer">this Hacker News comment thread</a>, I saw that Kubernetes had removed support for Docker as of v1.24.  I had previously upgraded my <code>kubectl</code> Homebrew version to 1.24 because my prior version didn't support the <code>--replicas</code> flag.  When I read this thread, I downgraded to v1.22 (the previous version), verified the version was correct via <code>kubectl version</code>, deleted/recreated the previously-created deployment and service, and tried <code>curl</code> again.  I still get the <code>301 redirect</code> error.</p>
<p>EDIT 6: Here's the full output of <code>curl -v http://localhost</code>:</p>
<pre><code>curl -v http://localhost 
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
&gt; GET / HTTP/1.1
&gt; Host: localhost
&gt; User-Agent: curl/7.79.1
&gt; Accept: */*
&gt; 
* Mark bundle as not supporting multiuse
&lt; HTTP/1.1 301 Moved Permanently
&lt; Server: nginx/1.21.2
&lt; Date: Mon, 25 Jul 2022 04:53:40 GMT
&lt; Content-Type: text/html
&lt; Content-Length: 169
&lt; Connection: keep-alive
&lt; Location: https://localhost/
&lt; 
&lt;html&gt;
&lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.21.2&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
* Connection #0 to host localhost left intact
</code></pre>
<p>Looks like it's trying to redirect from <code>http</code> to <code>https</code>?  Could this be some setting within the <code>training/webapp</code> Docker image?</p>
<p>Also, here's the result of <code>sudo lsof -i -P | grep LISTEN | grep :80</code>:</p>
<pre><code>$ sudo lsof -i -P | grep LISTEN | grep :80
nginx     3582   richiethomas    6u  IPv4 0x63a69bc74912e747      0t0    TCP *:80 (LISTEN)
nginx     3582   richiethomas    7u  IPv6 0x63a69bbdb3ebcbe7      0t0    TCP *:80 (LISTEN)
nginx     3701   richiethomas    6u  IPv4 0x63a69bc74912e747      0t0    TCP *:80 (LISTEN)
nginx     3701   richiethomas    7u  IPv6 0x63a69bbdb3ebcbe7      0t0    TCP *:80 (LISTEN)
</code></pre>

Richie Thomas
<p>It looks like you already have <code>nginx</code> running on port <code>80</code>(and <code>443</code>) on your system. Likely, another docker container outside kubernetes, or directly on your system. It already has taken port <code>80</code>, hence your LoadBalancer is in pending state.</p>
<p>Either stop that nginx service or use another port like <code>8080</code> for your LoadBalancer:</p>
<pre><code>$ kubectl create service loadbalancer simple-webapp \
       --tcp=8080:5000
</code></pre>
<p>The <code>training/webapp</code> does not use nginx.</p>
