6

Setting up Ingress using Ingress Controller in Kubernetes

 2 years ago
source link: https://www.journaldev.com/53608/ingress-controller-in-kubernetes
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Hello, readers! This article talks about Setting up Ingress using NGINX Ingress Controller in Kubernetes with a detailed demonstration.

So, let us begin!! 🙂


Understanding Ingress and an Ingress Controller in Kubernetes

An ingress is an API object that enables us to expose the HTTP as well as HTTPS routes of the applications from outside the cluster boundary to the services within the cluster boundary.

Have a look at the below diagram-

Ingress Routing
  1. At first, when we hit the host URL (client), it reaches the Ingress load-balancer set for the cluster.
  2. From the load balancer, the request gets routed to the Ingress resource.
  3. Within the Ingress resource, we need to define the routing rules that will help the application be browsed according to the specific services set in the architecture of the application.
  4. Through the routes, the request gets re-routed to the Service specific to the application namespace.
  5. Upon reaching the service, it delivers the request to the Application pod that matches the labels.

For the Ingress resources to work successfully, we need to have an Ingress Controller set within the Kubernetes Cluster.

The Ingress controller enables to fulfill and satisfy the request through some load-balancers at the back end. It enables us to satisfy the rule routing within the cluster till the end application point.


Pre-requisites for Setting up Ingress in Kubernetes

Before getting started with the Deployment and Implementation of Ingress in Kubernetes, we need to be clear with the below requirements:

  1. A fully running Kubernetes Cluster. For the purpose of demonstration, we have made use of minikube cluster.
  2. The kubectl command line tool must be configured to communicate with the components of the cluster.
  3. Try running the cluster with atleast two worker nodes i.e. two nodes that do not act as a control plane host.

1. Enable the Ingress Controller in Minikube

In order to deploy the Ingress resources on the Kubernetes (if using Minikube), we will need to enable the addon plugin for Ingress Controller.

Have a look at the below command-

minikube addons enable ingress

To verify if the Ingress controller is running, we can get the list of pods for the Ingress controller resource-

kubectl get pods -n ingress-nginx

Output-

NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-123def        0/1     Completed   0         28s
ingress-nginx-admission-patch-68b98         0/1     Completed   0          28s
ingress-nginx-controller-59b45fb494-lzmw2   1/1     Running     0          28s

2. Deploy an Application A1

In order to have the functionality of Ingress controller in place, we will be deploying an application in the cluster.

At first, let us deploy a sample application A1 using the below command-

kubectl create deployment A1 --image=gcr.io/google-samples/hello-app:1.0

Once the deployment is up and running, let us expose it to a service over port 8080 of type NodePort-

kubectl expose deployment A1 --type=NodePort --port=8080

Let us now verify if the service has been created and exposed as expected-

kubectl get service A1

Output:

NAME      TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
A1        NodePort   10.102.123.149   <none>        8080:31636/TCP   2m

We can now access this A1 application using the cluster IP address and the Nodeport. But, instead, let us now find a way to access it using Ingress Controller.


3. Creation of Ingress resource

Now, let us at first create a YAML file to set up Ingress rules for our application.

Ingress-app.YAML

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-app
spec:
rules:
- host: hello-world.info
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: A1
port:
number: 8080

This Ingress YAML file sets up rules that enables the host hello-world.info to have a HTTP routing for any child url with the path set to root (/) directory and to point to the backend service A1 over port 8080.

Thus, at first, the moment we hit the host URL on the browser, it sends the request to the Ingress controller, which in turn routes the traffic to the service A1 and then the service would internally point it to the respective application pod.

As soon as we create this Ingress file, the ingress resource with a specific IP gets created.

kubectl get ingress

Output-

NAME              CLASS    HOSTS              ADDRESS        PORTS   AGE
ingress-app       <none>   hello-world.info   172.15.0.14    80      12s

The application would thus be pointing to the IP 172.15.0.14. You can store the below line in the /etc/hosts file for a quick check-

172.15.0.14 hello-world.info

Now, the moment we curl the application host from our local system, it should give the desired output.

curl hello-world.info

Output-

Hello, world!
Version: 1.0.0
Hostname: web-55b8c6998d-8k564

By this, we have tested the functioning and routing of the application internally through Ingress controller and resource.


Conclusion

This makes us reach the end of this topic. Feel free to comment below, in case you come across any questions.

For more such posts related to Docker and Kubernetes, Stay tuned with us.

Till then, Happy Learning! 🙂


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK