Cloud Computing, Docker, Kubernetes

5 Mins Read

Introduction to Containerization of .NET Applications

Introduction to AKS With Ingress

Azure Kubernetes Service (AKS) is a managed Kubernetes service that enables us to rapidly deploy and manage Kubernetes clusters. To run windows workloads, a windows server node pool needs to be added to the AKS Cluster, which is created with a Linux node pool.

Azure Kubernetes cluster can leverage an ingress controller to facilitate the usage of a single Azure Load Balancer to forward traffic to multiple domains. The NGINX Ingress controller will listen to all the ingress events from all the namespaces and add corresponding directives and rules into the NGINX configuration file. It makes it possible to use a centralized routing file that includes all the ingress rules, hosts, and paths.

Scope

  • Introduction to GrandNode E-Commerce Application
  • Containerizing MongoDB and grandnode (.NET based e-commerce application)
  • Running application locally
  • Creating ACR repo and pushing container images to ACR
  • Setting up Azure Kubernetes Service with Windows worker nodes
  • Deploying Nginx Ingress Controller on AKS
  • Deploying GrandNode E-commerce Application on EKS with persistent storage
  • Configuring ingress for the applications and verification.

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

Technologies Used

  • Azure Kubernetes Service
  • Nginx Ingress Controller
  • Grandnode
  • MongoDB
  • Azure LoadBalancer
  • Azure Container Registry
  • Azure Disk Storage

Pre-requisites

  1. Azure account
  2. GitHub account
  3. Azure CLI
  4. Windows Server 2019 / Windows 10 (If you use a different operating system, use corresponding source code and make required changes to the entire setup.)
  5. Docker

Application Overview

GrandNode is an a free and open-source e-Commerce platform based on the modern MongoDB database that enables the flexible development of online stores.

GrandNode requires .NET Core 6.0, MongoDB 4.0+, and OS-specific dependency tools.

Preparing MongoDB docker image

  1. Clone the GitHub repo at “https://github.com/aneez004/mongo-windows.git”. Switch to the git folder.
  2. Modify the mongodbuser.ps1 file
  3. Add database username and password of your choice or keep the defaults. Here we are adding the user “grandadmin” with a password “grand” to the database admin. In the Dockerfile, we are using mongo windows image as the base image, and we copy over the PowerShell script to create the db user.
  4. Build and tag the docker image with a preferred tag name

Preparing Grandnode docker image

  1. Clone the Github repo at “https://github.com/aneez004/grandnode2.git”. Navigate to the “grandnode2” folder.
  2. Verify the Dockerfile
  3. Build and tag the image

Running the E-Commerce Application Locally

  1. Run the mongodb docker container
  2. Run the grandnode docker container by linking to the MongoDB container
  3. Verify both containers are up and running
  4. Access the application from a browser at http://localhost:8080
  5. Enter company information. Under ‘Store Information’, provide admin email username and password.
  6. Under ‘Database Information,’ enter the following details:
    1. MongoDB Server Name: MongoDB (the same name you provide using –name option during docker run)
    2. Database name: admin
    3. Username: grandadmin (replace with what you have given in the mongodbuser.ps1 file)
    4. Password: grand (replace with what you have given in the mongodbuser.ps1 file)
      Click on Install
  7. Restart the grandnode container
  8. Access the application at http://localhost:8080
  9. Access the admin page to modify your E-Commerce site. Enter the admin username and password provided during grandnode installation

Creating Container Registry for Application Container Images

  1. Login to Azure portal. If you don’t have an account, create a free account at https://azure.microsoft.com/en-us/free/ 
  2. Search and select ‘Container Registries’
  3. Click on Create container registry
  4. Select your subscription, create a new resource group and select it
  5. Enter a unique ‘Registry Name’. Note down this name for future requirements.
  6. Accept default values for the remaining settings. Then select Review + create. After reviewing the settings, select Create
  7. Note down the registry name and login server

Pushing Images to the Registry

  1. Install chocolatey (if not installed) using instructions from the link https://chocolatey.org/install.
  2. Install Azure CLI using the following command
  3. Log into your Azure account using azure cli using the following command
  4. Enter your credentials from the browser pop up window
  5. Log in to the Azure Container registry before pushing container images to the registry.
  6. Tag the docker images built in the previous sections in the Azure container registry name format. Replace the required values
  7. Push the application container images to the Azure container registry
  8. Verify the images are pushed

Creating AKS Cluster with Windows Worker Nodes

  1. Create a resource group for the AKS cluster. Use the same location used for creating container registry
  2. Create the cluster. Replace resource group name, windows admin username and password.
  3. If you are using a different Kubernetes version, make sure that version is supported in that region using the command
  4. Add a Windows Server node pool. An AKS cluster is created with a node pool that can run Linux containers by default. Add node pool that can run Windows Server containers alongside the Linux node pool
  5. Install kubectl locally using the command. Alternatively, you may install it using binaries or chocolatey
  6. Execute the following command to Get access credentials for the Kubernetes cluster
  7. Verify if the node pools are added and cluster is up and running

NGINX Ingress Controller Deployment on AKS Cluster

  1. Use the following command to deploy nginx ingress controller on the cluster
  2. Verify that the controller is deployed as intended by checking the pods and service in the namespace ingress-nginx
  3. Note down the external ip against the service ingress-nginx-controller. Access the ip from a browser
    This confirms that the ingress controller is installed as intended
  4. Integrate Azure Container Registry with the AKS cluster using the following command. Provide valid values for acr registry, cluster name and rg name

Deploying GrandNode E-commerce Application on AKS

  1. Navigate to the grandnode2 directory that you have earlier downloaded using git. Navigate to the directory manifests under grandnode2. List the files.
  2. Create namespace
  3. Create ‘azuredisk’ storage class with ‘Immediate’ volume binding mode
  4. Create persistent storage for both grandnode and mongodb in us region
  5. Create deployments and service files for mongodb and grandnode e-commerce application for us region. Verify all resources are created
  6. Set up ingress resource for the grandnode US application
  7. Repeat the steps to create Kubernetes resources for Canada region also.
    Configure persistent storage for grandnode and mongo in Canada region
  8. Create deployment and service resources
  9. Set up ingress resource for the grandnode US application
  10. Configure dns locally. Ideally it is required to add CNAME entries for your domain name at your domain registrar or where you have configured the dns server. For this demo, we are configuring dns locally.Open command prompt or powershell in Administrative mode. Execute the following command to edit the hosts file to set up temporary dns to point the hostnames to the external ip of nginx ingress loadbalancer.
    Get the external ip associated with the nginx ingress controller using the following commandEdit the host file (C:\Windows\System32\drivers\etc\hosts) and add entries for us and Canada grandnode sites pointed against the nginx ingress loadbalancer ip address
  11. Access the us site at http://us.grandnode.com (Replace with the values that you have used). Complete the installation by providing company information, store information and database information. Provide the mongodb server name as the service name corresponding to the mongo service in the us namespace (mongo-us-service).
  12. Provide db details and click on “Install”. Wait for the installation to complete
  13. Restart the grandnode deployment to complete the installation
  14. Access the site at http://us.grandnode.com
  15. Access the admin page for us grandnode application at http://us.grandnode.com/admin
  16. Repeat the steps for Canada grandnode deployment.Access the canada site at http://canada.grandnode.com (Replace with the values that you have used). Complete the installation by providing company information, store information and database information. Provide the mongodb server name as the service name corresponding to the mongo service in the canada namespace (mongo-canada-service).
  17. Restart the grandnode deployment to complete the installation
  18. Access the application at http://canada.grandnode.com
  19. Access the admin page at http://canada.grandnode.com/admin

Conclusion

Migration of windows workloads to Kubernetes is gaining acceptance as it offers increased flexibility, security, high availability and portability for their applications. Microsoft .NET applications can be now easily containerized and deployed on existing AKS Cluster by adding windows worker nodes to the existing cluster. Leveraging the functionalities of nginx as web-server, reverse-proxy and loadbalancer on the Kubernetes cluster facilitates usage of a single cloud Loadbalancer to forward traffic to large number of clients.

Drop a query if you have any questions regarding Containerization and we will get back to you quickly.

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery PartnerAWS Microsoft Workload PartnersAmazon EC2 Service Delivery Partner, and many more.

To get started, go through our Consultancy page and Managed Services PackageCloudThat’s offerings.

FAQs

1. What are the limitations of running multiple node pools on AKS?

ANS: –

  • First node pool can’t be deleted.
  • Windows server node pool name has a limit of 6 characters.
  • AKS Cluster can have a maximum of 10 node pools.

2. What are the guidelines for selecting windows base images for containerization?

ANS: –

  • Use ‘Windows server core’ if your application requires full .NET framework
  • Use ‘Nano Server’ if building an application based on the .NET core
If your application requires more dependencies and core windows libraries, use the’ Windows’ image.

WRITTEN BY Nisarg Desai

Nisarg Desai is a certified Lead Full Stack Developer and is heading the Consulting- Development vertical at CloudThat. With over 5 years of industry experience, Nisarg has led many successful development projects for both internal and external clients. He has led the team for development of Intelligent Quarterly Remuneration System (iQRS), Intelligent Training Execution and Analytics System (iTEAs), and Cloud Cleaner projects among many others.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!