# Introduction to NGINX Ingress Controller ## Create a kubernetes cluster In this guide we we''ll need a Kubernetes cluster for testing. Let's create one using [kind](https://kind.sigs.k8s.io/)
``` kind create cluster --name nginx-ingress --image kindest/node:v1.23.5 ``` See cluster up and running: ``` kubectl get nodes NAME STATUS ROLES AGE VERSION nginx-ingress-control-plane Ready control-plane,master 2m12s v1.23.5 ``` ## Run a container to work in ### run Alpine Linux: ``` docker run -it --rm -v ${HOME}:/root/ -v ${PWD}:/work -w /work --net host alpine sh ``` ### install some tools ``` # install curl apk add --no-cache curl # install kubectl curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl chmod +x ./kubectl mv ./kubectl /usr/local/bin/kubectl # install helm curl -o /tmp/helm.tar.gz -LO https://get.helm.sh/helm-v3.10.1-linux-amd64.tar.gz tar -C /tmp/ -zxvf /tmp/helm.tar.gz mv /tmp/linux-amd64/helm /usr/local/bin/helm chmod +x /usr/local/bin/helm ``` ### test cluster access: ``` /work # kubectl get nodes NAME STATUS ROLES AGE VERSION nginx-ingress-control-plane Ready control-plane,master 3m26s v1.23.5 ``` ## NGINX Ingress Controller We'll start with the documentation as always
You can find the [Kubernetes NGINX documentation here](https://kubernetes.github.io/ingress-nginx/)
First thing we do is check the compatibility matrix to ensure we are deploying a compatible version of NGINX Ingress on our Kubernetes cluster
The Documentation also has a link to the [GitHub Repo](https://github.com/kubernetes/ingress-nginx/) which has a compatibility matrix
### Get the installation YAML The controller ships as a `helm` chart, so we can grab version `v1.5.1` as per the compatibility matrix.
From our container we can do this: ``` helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm search repo ingress-nginx --versions ``` From the app version we select the version that matches the compatibility matrix.
``` NAME CHART VERSION APP VERSION DESCRIPTION ingress-nginx/ingress-nginx 4.4.0 1.5.1 Ingress controller for Kubernetes using NGINX a... ``` Now we can use `helm` to install the chart directly if we want.
Or we can use `helm` to grab the manifest and explore its content.
We can also add that manifest to our git repo if we are using a GitOps workflow to deploy it.
``` CHART_VERSION="4.4.0" APP_VERSION="1.5.1" mkdir ./kubernetes/ingress/controller/nginx/manifests/ helm template ingress-nginx ingress-nginx \ --repo https://kubernetes.github.io/ingress-nginx \ --version ${CHART_VERSION} \ --namespace ingress-nginx \ > ./kubernetes/ingress/controller/nginx/manifests/nginx-ingress.${APP_VERSION}.yaml ``` ### Deploy the Ingress controller ``` kubectl create namespace ingress-nginx kubectl apply -f ./kubernetes/ingress/controller/nginx/manifests/nginx-ingress.${APP_VERSION}.yaml ``` ### Check the installation ``` kubectl -n ingress-nginx get pods ``` The traffic for our cluster will come in over the Ingress service
Note that we dont have load balancer capability in `kind` by default, so our `LoadBalancer` is pending: ``` kubectl -n ingress-nginx get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller LoadBalancer 10.96.130.21 80:31011/TCP,443:31772/TCP 26m ingress-nginx-controller-admission ClusterIP 10.96.125.210 443/TCP 26m ``` For testing purposes, we will simply setup `port-forward`ing
If you are running in the cloud, you will get a real IP address.
``` kubectl -n ingress-nginx port-forward svc/ingress-nginx-controller 443 ``` We can reach our controller on [https://localhost/](https://localhost/) ## Features * Routing DOMAIN * SSL terminating & passthrough * routing URL customization (configmap) * location snippet * log formating