Effortless Kubernetes App Ingress Setup With Devtron

2 years ago   •   6 min read

By Ajay Kumar Yadav

What is Ingress?

An ingress is a Kubernetes API object that provides a simple way of describing HTTP and HTTPS routes from outside the cluster to services within the cluster and configure to give services externally reachable URLs.

Ingress manages the traffic in two routing methods over the k8s service.

  1. Host Based routing
  2. Path Based routing

Host based routing

It provides the facilities to send traffic based on respective hosts definition and performs routing by name and supports routing HTTP traffic to multiple host names at the same IP address but different domain names.

For example -

Hostname Service Name
frontend.devtron.com frontend
backend.devtron.com backend
nodeapi.devtron.com node-service

Path based routing

Here we don't have multiple domain names, all the URI is distinguished and routed from the PATH prefix under a single domain, for example the above applications can be accessed through the single URI.

For example -

Endpoints Service Name
app.devtron.com/frontend frontend
app.devtron.com/backend backend
app.devtron.com/nodeapi node-service

In this case, we have a single domain app.devtron.com and an ingress controller check the paths and according to that traffic sent to respective services and /frontend, /backend, /nodeapi are known as paths in ingress objects.

Why do we need an Ingress ?

Let’s assume, we have deployed a web application over k8s and want to access the application. For that, we can use the pod’s IP address or access it by its name like http://172.x.x.1/home or http://name_of_pod/home within the k8s cluster. Now what if I want to access the application out of the cluster. To solve this challenge, Kubernetes has a component called service which does the traffic load balancing over replicas of your deployment and provides a single accessible endpoint for your application.

To access an application, there are 3 most commonly used service types, i.e. ClusterIP, NodePort and LoadBalancer. Each provides a different way of exposing the service and is useful in different situations.

  • ClusterIP: Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable within the cluster and it is the default service type.
  • NodePort: Client is going to use the IP of nodes at certain port number at which the pod's service is running but this is not best practice to expose the application to the public world because here we might have security issues, loopholes and sometimes accessing the web application through an IP address can be annoying.
  • LoadBalancer:  When we use the service type as LoadBalancer, behind the scenes this managed k8s service connects to the load balancer service of the respective cloud provider and creates a Load balancer and maps to the k8s service. GKE and AKE provide the public IP of Load Balancer as service endpoint but in the case of EKS, provide the non customize DNS name.

If we want to access k8s service by custom host name or host path  in that case, the role of  Ingress, a k8s component comes into play.

Implementing an ingress for an application is a tedious job using the command line. In this blog we will walk through the steps to set up an ingress for an application over Kubernetes just in a few steps and all thanks to Devtron.

Prerequisites to setup ingress for an application

  • Must have a k8s cluster - In our case, we have an AKS cluster
  • Devtron installed on cluster - Feel free to checkout its well managed documentation for installing Devtron
  • The source repo of application must have Dockerfile for the application.

Note: Setup the Global Configuration of Devtron after its installation.

Now before setting up an ingress we have to deploy the ingress controller to control the ingress rule. For that, we will be using Devtron to deploy the controller helm chart.

Deploy ingress controller helm chart

To deploy an ingress controller helm chart, you can follow the same steps mentioned in this blog. Click on Charts store --> Select your chart nginx-ingress/ingress-nginx, click on Deploy. It will open the chart configs where you need give details of you chart and change the configs accordingly. Here are the configuration in chart we did in our case -

fullnameOverride: ingress-prod
IngressClassResource:
    name: nginx-prod
    enables: true
    default: false
    controllervalues: "k8s.io/ingress-nginx-prod"
IngressClass: nginx-prod
ingress-controller chart changes

Once the chart is successfully deployed, you can see the Healthy status of the ingress controller as shown below along with all other Kubernetes objects deployed with the chart.

Resources of ingress Controller
Note: Here we have created a route 53 record which is pointing to Load Balancer, created by AKS and assigned to ingress-controller service.
DNS record

Let's create an application with ingress and set up CI/CD using Devtron.

Click on Create New >> Click on Custom App

Give the details of application

Enter the App Name, Project and select the Template if you have deployed any application before. Selecting a template allows us to copy the same configurations of an existing app but in our case we will create it from scratch.

Devtron create-new-app

After you click on Create App, it will redirect you to the App Configuration tab where you need to provide a few configurations to set up your application’s CI/CD.

Configure Git Repository

In Git Repository, select the Git Account (public is by default or for private repos, select the account added) and provide the git repo url of your application which needs to be deployed.

Git Account

Configure Docker Build Config

In Docker Build Config select the container registry from drop down, provide the repository name and give a path to the Dockerfile of your application.

Docker build configuration

Configure Deployment Template

Devtron provides a pre installed deployment template consisting of all the important configuration required to deploy an application. Just change the configs as per your requirements and save the deployment template as shown below.  

In our case we have changed the container port to 80 and configured the ingress as shown below -  

Deployment Template

Configure Workflow

Now after saving the deployment template, we need to create a CI-CD workflow. Devtron provides an awesome feature to configure the CI & CD pipeline of our applications which makes our life easy. For more details and advance configuration for creating workflow, please refer to its documentation

Workflow
Workflow

After all the Application configurations are done, we need to trigger our CI pipeline which would build an image and then trigger the CD pipeline, which would deploy the application. Navigate to the Build & Deploy tab, click on Select Material and select the commit for which you want to create an image. Once the CI part is done, click on Select Image and select the image you want to deploy.

Note:- We have 2 options to trigger our pipeline (manual and automatic).

Once your CI and CD succeed so you can see the status of pipeline as below

Devtron CICD status
CI and CD status

Now navigate to the App Details tab and you can see the status as Healthy and all the k8s workload in the dashboard. Devtron provides resource grouping of workloads which makes it really easy to check out the resources and debug in case of any issues.

Devtron's App Details tab
App Details

To check out whether ingress has been created or not, you can see an ingress object under Networking → Ingress, and open the manifest as shown below to get the complete yaml of ingress object. Clearly we can see, it has created an ingress and added our host and path.

ingress

Open another tab and access the application by domain (myapp.devtron.info) with /app path you can see in the image below.

Deployed Application
Deployed Application

Hurray! Finally We have set up the ingress for an application through Devtron’s intuitive dashboard. Hope you get a better understanding on how to setup ingress and deploy applications as well as helm charts through Devtron and how easy it is. If you have any doubts, feel free to let us know through comments.

Spread the word

Keep reading