Revise task for practising NGINX Ingress controller

This commit is contained in:
Tim Bannister 2021-08-03 14:33:43 +01:00
parent 85d3fb9900
commit 9d77a6bf22
1 changed files with 135 additions and 150 deletions

View File

@ -2,6 +2,7 @@
title: Set up Ingress on Minikube with the NGINX Ingress Controller
content_type: task
weight: 100
min-kubernetes-server-version: 1.19
---
<!-- overview -->
@ -17,23 +18,21 @@ This page shows you how to set up a simple Ingress which routes requests to Serv
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
If you are using an older Kubernetes version, switch to the documentation
for that version.
### Create a Minikube cluster
Using Katacoda
: {{< kat-button >}}
Locally
: If you already [installed Minikube](/docs/tasks/tools/#minikube)
locally, run `minikube start` to create a cluster.
<!-- steps -->
## Create a Minikube cluster
1. Click **Launch Terminal**
{{< kat-button >}}
1. (Optional) If you installed Minikube locally, run the following command:
```shell
minikube start
```
## Enable the Ingress controller
1. To enable the NGINX Ingress controller, run the following command:
@ -50,9 +49,9 @@ This page shows you how to set up a simple Ingress which routes requests to Serv
```shell
kubectl get pods -n ingress-nginx
```
{{< note >}}This can take up to a minute.{{< /note >}}
{{< note >}}It can take up to a minute before you see these pods running OK.{{< /note >}}
Output:
The output is similar to:
```
NAME READY STATUS RESTARTS AGE
@ -61,14 +60,13 @@ ingress-nginx-admission-patch-rqp78 0/1 Completed 1 11m
ingress-nginx-controller-59b45fb494-26npt 1/1 Running 0 11m
```
{{% /tab %}}
{{% tab name="minikube v1.18.1 or earlier" %}}
```shell
kubectl get pods -n kube-system
```
{{< note >}}This can take up to a minute.{{< /note >}}
{{< note >}}It can take up to a minute before you see these pods running OK.{{< /note >}}
Output:
The output is similar to:
```
NAME READY STATUS RESTARTS AGE
@ -79,27 +77,11 @@ kubernetes-dashboard-5498ccf677-b8p5h 1/1 Running 0 2m
nginx-ingress-controller-5984b97644-rnkrg 1/1 Running 0 1m
storage-provisioner 1/1 Running 0 2m
```
Make sure that you see a Pod with a name that starts with `nginx-ingress-controller-`.
{{% /tab %}}
{{< /tabs >}}
```shell
kubectl get pods -n ingress-nginx
```
{{< note >}}This can take up to a minute.{{< /note >}}
Output:
```shell
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-2tgrf 0/1 Completed 0 3m28s
ingress-nginx-admission-patch-68b98 0/1 Completed 0 3m28s
ingress-nginx-controller-59b45fb494-lzmw2 1/1 Running 0 3m28s
```
## Deploy a hello, world app
1. Create a Deployment using the following command:
@ -108,9 +90,9 @@ storage-provisioner 1/1 Running 0 2m
kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
```
Output:
The output should be:
```shell
```
deployment.apps/web created
```
@ -120,9 +102,9 @@ storage-provisioner 1/1 Running 0 2m
kubectl expose deployment web --type=NodePort --port=8080
```
Output:
The output should be:
```shell
```
service/web exposed
```
@ -132,30 +114,30 @@ storage-provisioner 1/1 Running 0 2m
kubectl get service web
```
Output:
The output is similar to:
```shell
```
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web NodePort 10.104.133.249 <none> 8080:31637/TCP 12m
```
1. Visit the service via NodePort:
1. Visit the Service via NodePort:
```shell
minikube service web --url
```
Output:
The output is similar to:
```shell
```
http://172.17.0.15:31637
```
{{< note >}}Katacoda environment only: at the top of the terminal panel, click the plus sign, and then click **Select port to view on Host 1**. Enter the NodePort, in this case `31637`, and then click **Display Port**.{{< /note >}}
Output:
The output is similar to:
```shell
```
Hello, world!
Version: 1.0.0
Hostname: web-55b8c6998d-8k564
@ -164,23 +146,23 @@ storage-provisioner 1/1 Running 0 2m
You can now access the sample app via the Minikube IP address and NodePort. The next step lets you access
the app using the Ingress resource.
## Create an Ingress resource
## Create an Ingress
The following file is an Ingress resource that sends traffic to your Service via hello-world.info.
The following manifest defines an Ingress that sends traffic to your Service via hello-world.info.
1. Create `example-ingress.yaml` from the following file:
{{< codenew file="service/networking/example-ingress.yaml" >}}
1. Create the Ingress resource by running the following command:
1. Create the Ingress object by running the following command:
```shell
kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml
```
Output:
The output should be:
```shell
```
ingress.networking.k8s.io/example-ingress created
```
@ -192,20 +174,24 @@ The following file is an Ingress resource that sends traffic to your Service via
{{< note >}}This can take a couple of minutes.{{< /note >}}
```shell
You should see an IPv4 address in the ADDRESS column; for example:
```
NAME CLASS HOSTS ADDRESS PORTS AGE
example-ingress <none> hello-world.info 172.17.0.15 80 38s
```
1. Add the following line to the bottom of the `/etc/hosts` file.
{{< note >}}If you are running Minikube locally, use `minikube ip` to get the external IP. The IP address displayed within the ingress list will be the internal IP.{{< /note >}}
1. Add the following line to the bottom of the `/etc/hosts` file on
your computer (you will need adminstrator access):
```
172.17.0.15 hello-world.info
```
This sends requests from hello-world.info to Minikube.
{{< note >}}If you are running Minikube locally, use `minikube ip` to get the external IP. The IP address displayed within the ingress list will be the internal IP.{{< /note >}}
After you make this change, your web browser sends requests for
hello-world.info URLs to Minikube.
1. Verify that the Ingress controller is directing traffic:
@ -213,9 +199,9 @@ The following file is an Ingress resource that sends traffic to your Service via
curl hello-world.info
```
Output:
You should see:
```shell
```
Hello, world!
Version: 1.0.0
Hostname: web-55b8c6998d-8k564
@ -223,34 +209,35 @@ The following file is an Ingress resource that sends traffic to your Service via
{{< note >}}If you are running Minikube locally, you can visit hello-world.info from your browser.{{< /note >}}
## Create Second Deployment
## Create a second Deployment
1. Create a v2 Deployment using the following command:
1. Create another Deployment using the following command:
```shell
kubectl create deployment web2 --image=gcr.io/google-samples/hello-app:2.0
```
Output:
The output should be:
```shell
```
deployment.apps/web2 created
```
1. Expose the Deployment:
1. Expose the second Deployment:
```shell
kubectl expose deployment web2 --port=8080 --type=NodePort
```
Output:
The output should be:
```shell
```
service/web2 exposed
```
## Edit Ingress
## Edit the existing Ingress {#edit-ingress}
1. Edit the existing `example-ingress.yaml` and add the following lines:
1. Edit the existing `example-ingress.yaml` manifest, and add the
following lines at the end:
```yaml
- path: /v2
@ -268,13 +255,13 @@ The following file is an Ingress resource that sends traffic to your Service via
kubectl apply -f example-ingress.yaml
```
Output:
You should see:
```shell
```
ingress.networking/example-ingress configured
```
## Test Your Ingress
## Test your Ingress
1. Access the 1st version of the Hello World app.
@ -282,9 +269,9 @@ The following file is an Ingress resource that sends traffic to your Service via
curl hello-world.info
```
Output:
The output is similar to:
```shell
```
Hello, world!
Version: 1.0.0
Hostname: web-55b8c6998d-8k564
@ -296,9 +283,9 @@ The following file is an Ingress resource that sends traffic to your Service via
curl hello-world.info/v2
```
Output:
The output is similar to:
```shell
```
Hello, world!
Version: 2.0.0
Hostname: web2-75cd47646f-t8cjk
@ -315,5 +302,3 @@ The following file is an Ingress resource that sends traffic to your Service via
* Read more about [Ingress Controllers](/docs/concepts/services-networking/ingress-controllers/)
* Read more about [Services](/docs/concepts/services-networking/service/)