Open In App

Deploying NGINX Image To AKS Using Azure CLI and Advanced Kubectl Commands

Pre-requisite: AKS Features

Azure Kubernetes Service (AKS) is a managed Kubernetes service that enables you to quickly deploy and manage clusters. AKS makes it easy to deploy and manage containerized applications without having to worry about the underlying infrastructure. It is a fully managed service, meaning that Microsoft handles the maintenance and management of the infrastructure, allowing you to focus on your applications. AKS also integrates with other Azure services, such as Azure Monitor and Azure Container Registry, to provide a comprehensive solution for deploying and managing containerized applications.



Advantages of Azure Kubernetes Service(AKS)

Steps for Deployment 

Step 1: Create a resource group to keep all the resources under one folder.

Resource group

Step 2: Open your terminal and type az login



 

Step 3: Create an Azure Container Registry (ACR) instance. This is a private registry where you can store and manage your container images.

$ az acr create --resource-group 
kubernetes-hosting --name 
kubernetesrepo --sku Basic

 

Step 4: Create an AKS Cluster. You can use the AZ AKS create command to create an AKS cluster.

$ az aks create -g kubernetes-hosting
 -n myAKSCluster --enable-managed
 -identity --node-count 1 
--enable-addons monitoring 
--enable-msi-auth-for-monitoring  
--attach-acr kubernetesrepo 
--generate-ssh-keys

 

Step 5: Connect to the AKS cluster. Use the az aks get-credentials command to download the kubeconfig file and set the correct context in the kubeconfig file.

$ az aks get-credentials 
--resource-group kubernetes
-hosting --name myAKSCluster

 

Step 6: Create a deployment. Use the kubectl create deployment command to create a deployment in the AKS cluster.

$ kubectl create deployment 
nginx-deployment --
replicas=3 --image=nginx 
--port=80

This deployment file defines a deployment called nginx-deployment that consists of three replicas of an NGINX container. The containers will be labeled with the app: nginx and will be running the nginx: latest image. The container will be listening on port 80.

Step 7: Expose the deployment. Use the kubectl expose deployment command to expose the deployment as a service.

$ kubectl expose deployment 
nginx-deployment --name=nginx
-service --type=LoadBalancer 
--port=80 --protocol=TCP

Step 8: Verify the deployment. Use the kubectl get all command to verify that the deployment and service have been created successfully.

$ kubectl  get all

 

Step 9: Copy the external IP generated by nginx-service and paste it in the browser to access nginx webpage or do curl < external-IP>.

 


Article Tags :