In this tutorial we will deploy the ingress-nginx controller on kubernetes.
Pre-Requisites
I will be using kind to run a kubernetes cluster locally, if you want to follow along, have a look at my previous post on how to install kubectl and kind and the basic usage of kind:
You will also need helm to deploy the ingress-nginx release from their helm charts, you can see their documentation on how to install it:
Create the Kubernetes Cluster
First we will define the kind configuration which will expose port 80 locally in a file name kind-config.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Then go ahead and create the kubernetes cluster:
1
|
|
Install ingress-nginx using Helm
Install the ingress-nginx helm chart, by first adding the repository:
1
|
|
Then update your local repositories:
1
|
|
Then install the helm release, and set a couple of overrides.
The reason we use NodePort is because our kubernetes cluster runs on docker containers, and from our kind config we have exposed port 80 locally, we are using the NodePort service so that we can make an HTTP request to port 80 to traverse to the port of the service:
1 2 3 4 5 |
|
You can view all the default values from their GitHub repository where the chart is hosted:
Once the release has been deployed, you should see the ingress-nginx pod running under the ingress-nginx
namespace:
1
|
|
Deploy a Web Application
We will create 3 files:
example/deployment.yaml
example/service.yaml
example/ingress.yaml
Create the example directory:
1
|
|
Our example/deployment.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Our example/service.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Our example/ingress.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
In summary, we are creating a deployment with a pod that listens on port 5000, and then we are creating a service with port 80 that will forward its connections to the container port of 5000.
Then we define our ingress that will match our hostname and forward its connections to our service on port 80, and also notice that we are defining our ingress class name, which we have set in our helm values.
Deploy this example with kubectl:
1
|
|
Now you can access the web application at http://example.127.0.0.1.nip.io
Teardown
You can delete the resources that we’ve created using:
1
|
|
Delete the cluster using:
1
|
|
Thank You
Thanks for reading, if you enjoy my content please feel free to follow me on Twitter - @ruanbekker or visit me on my website - ruan.dev