
When an Azure kubernetes service up and running, we have to expose its service to the real world if we want to broadcast our public service. All request will be routed from your end-users to the application inside AKS cluster though a completed model. In this article, we are going to explore How to create a hostname to your Kubernetes application and manage it.
What is a Kubernetes ingress ?
Based on Kubernetes official document, an Ingress is “An API object that manages external access to the services in a cluster, typically HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.” – see full documentation in Kubernetes/doc/ingress

What is an Ingress Controller ?
In order for the Ingress resource to work, the cluster must have an ingress controller running. Unlike other types of controllers which run as part of the kube-controller-manager
binary, Ingress controllers are not started automatically with a cluster. Kubernetes as a project supports and maintains AWS, GCE, AGIC and nginx ingress controllers
In this article, we’re going to public our simple-nodejs application into real-world service using AGIC (Azure Application Gateway Ingress Controller) which is installed into our AKS cluster during setup. If you haven’t install AGIC, please follow AKS #2: Install AGIC add-ons for AKS
Prerequisites
- AzureCLI, ArgoCD CLI, Helm CLI, KubeCTL installed on your working machine
- Make sure you have an AKS cluster up and running. See AKS #1: Create Azure Kubernetes Service cluster
- AGIC add-ons installed on your Azure Kubernetes Cluster. See How to Install AGIC add-ons for AKS
- ArgoCD server installed on your Azure Kubernetes Cluster up and running. See How to Install ArgoCD on AKS cluster
How to config AKS ingress and domain with AGIC
1. Create Ingress definition file
Before started, make sure your simple-express deployment and service are working properly, let’s get the pods and its status by kubectl get pods --namespace default
command:
# get the pods deployments kubectl get pods --namespace default # Output NAME READY STATUS RESTARTS AGE nodejs-deployment-5779894959-c2k46 1/1 Running 0 105s nodejs-deployment-5779894959-cp5dc 1/1 Running 0 105s nodejs-deployment-5779894959-t74d4 1/1 Running 0 105s # # get the k8s service of your application kubectl get service --namespace default # Output NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nodejs-service ClusterIP 10.0.117.29 <none> 8000/TCP 2m31s
As you can see in above output, we have one service called nodejs-service
which is running and exposed on 8000 container port. We are going to create an Ingress object which will be handler its deployment by AGIC.
Create a new file called ingress.yaml
and paste following content:
# create a k8s ingress for nodejs application apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: nodejs-service-ingress namespace: default annotations: kubernetes.io/ingress.class: azure/application-gateway appgw.ingress.kubernetes.io/backend-protocol: "http" appgw.ingress.kubernetes.io/request-timeout: "300" spec: rules: - http: paths: - path: /nodejs pathType: Prefix backend: service: name: nodejs-service port: number: 8000
2. Deploy an ingress to Azure Kubernetes Service
Using kubeCTL command
Make sure you’re connected to AKS cluster within your kubectl config and set it to active context. Run following command to apply above ingress to current AKS cluster:
# apply ingress to k8s cluster kubectl apply -f ingress.yaml --namespace default # Output nodejs-service-ingress was configured.
Using ArgoCD
If you have deployed application and deployment using ArgoCD sync from a repository, make sure you uploaded file ingress.yaml
to the same folder of deployment.yaml
and service.yaml
, then you will have ArgoCD synced and deployed your Ingress.
Using domain and hostname for AKS services
After your ingress deployed successfully to the AKS cluster, AGIC will create some Azure resources which necessary for the ingress routing such as IP Table, Listener, Routing Rules, ….
We also configured a Public IP address which is connected to the AKS cluster and stand for a front-end address.
Let’s create a DNS record (A) pointing to that IP address and after DNS resolved, you can easily access your nodejs application though domain and hostname like
http://{your domain}/nodejs
Leave a Reply