An Ingress is a Kubernetes API object that is used to access the services running inside the Kubernetes cluster from external world. Ingress is not enabled by default in Kubernetes cluster you have to enable Kubernetes cluster using third party ingress controller like Nginx, Istio, HAProxy, etc.,
Enabling Ingress Controller in Kubernetes Cluster
As a prerequisite, we must have a running Kubernetes cluster .You can setup running Kubernetes cluster using minikube or any other cloud services like AWS,GCP.,
Run the following kubectl command to install ingress nginx controller.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/baremetal/deploy.yaml
Verify that ingress controller is running successfully in cluster using the below command
kubectl get all -n ingress-nginx
The above command confirms that ingress is running successfully in our Kubernetes cluster. Next we will deploy a application and try to access that application from external world.
Deploying a Demo Application
For testing ingress, we will deploy a demo application of Nginx.
Create a namespace
Create a namespace called dev to deploy a sample application.
Deploy a Nginx Deployment
- name: nginx
- containerPort: 80
Copy the above code and place it in nginx.yaml file .Run the above code using the following command
All the nginx pod is up and running.
Expose the application using service
Expose the running application using clusterIP service. First create a file called nginx-svc.yaml and copy the below code and run the file using the below command.
- port: 80
Copy the above code and place it in nginx-svc.yaml file. Run the above code using the below command and check whether the service is pointing the application using the command kubectl get ep -n dev. It is showing three endpoints.
Create an ingress object for Application
Now let’s create an ingress object to access our hello world application. An ingress object is nothing but a set of routing rules.
Create a file called ingress-hello.yaml and copy the below code and run it.
- host: "dev.alphabsolutions.com"
- pathType: Prefix
When you type dev.alphabsolutions.com in browser it displays nginx webpage as follows