Deploying NGINX Image To AKS Using Azure CLI and Advanced Kubectl Commands
Last Updated :
30 Mar, 2023
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)
- Managed Infrastructure: AKS is a fully managed service, meaning that Microsoft handles the maintenance and management of the underlying infrastructure. This frees you up to focus on your applications.
- Integration with Other Azure Services: AKS integrates with other Azure services such as Azure Monitor, Azure Container Registry, and Azure Active Directory, to provide a comprehensive solution for deploying and managing containerized applications.
- Scalability: AKS allows you to scale your applications up or down as needed, making it easy to handle changes in demand.
- High Availability: AKS is designed to be highly available, with multiple replicas of your applications running across multiple availability zones.
- Security: AKS integrates with Azure AD for secure access to your cluster, and offers features such as role-based access control (RBAC) and network security groups to help secure your applications.
- Cost: AKS offers a pay-as-you-go pricing model, so you only pay for what you use. There are also options to bring your own licenses and use Azure Hybrid Benefit, which can help reduce costs.
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>.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...