AKS Cluster : Step by Step guide to create AKS cluster AZ CLI

Creating a Kubernetes cluster involves several steps, and you can choose between different platforms like Google Kubernetes Engine (GKE), Amazon EKS, Azure AKS, or using tools like kubeadm for on-premises clusters.

Creating an Azure Kubernetes Service (AKS) cluster involves a series of steps, from setting up the Azure environment to deploying and managing your Kubernetes resources. Here's a step-by-step guide to help you create and manage an AKS cluster on Azure.
Prerequisites

    Azure Account: Ensure you have an Azure account. You can sign up for a free account here.
    Azure CLI: Install the Azure CLI on your local machine. You can download it here.
    Kubernetes CLI (kubectl): Install kubectl to interact with your Kubernetes cluster. Installation instructions are here.
    
    Step-by-Step Process
    
    Set Up Azure CLI

    Log in to Azure:
    az login


    Set the desired subscription (if you have multiple subscriptions):
    az account set --subscription <subscription-id>

    Create a Resource Group

    Create a resource group:
    az group create --name myResourceGroup --location eastus

    Replace myResourceGroup with your desired resource group name and eastus with your preferred location.
    
    Create an AKS Cluster

    az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys

    myResourceGroup: The name of the resource group.
    myAKSCluster: The name of the AKS cluster.
    --node-count 3: Specifies the number of nodes in the cluster.
    --enable-addons monitoring: Enables the monitoring addon for the cluster.
    --generate-ssh-keys: Generates SSH keys for node access.


    Configure kubectl to Connect to Your AKS Cluster
    Get the AKS credentials:

    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
 
    This command configures kubectl to use the credentials of your AKS cluster.
    The command az aks get-credentials --resource-group myResourceGroup --name myAKSCluster performs the following actions:

    Fetches the Credentials: It retrieves the Kubernetes configuration (kubeconfig) file for your specified AKS cluster.
    Configures kubectl: It merges the retrieved credentials with your local kubeconfig file, which kubectl uses to communicate with your AKS cluster.
    
    Verify the Cluster

    Check the nodes:
    kubectl get nodes


    You should see the list of nodes in your cluster.
    
    
    Deploying an Application

    Let's deploy a simple Nginx application to the cluster.

    Create a deployment:
    
    kubectl create deployment nginx --image=nginx
    
    Expose the deployment:
    
    kubectl expose deployment nginx --port=80 --type=LoadBalancer


    Get the external IP address:
    kubectl get service nginx

    Wait for the EXTERNAL-IP to be assigned, and then you can access your Nginx application using the external IP address.
    
    Cleaning Up

    When you no longer need the cluster, you can delete it to avoid incurring charges.

    Delete the AKS cluster:
    az aks delete --resource-group myResourceGroup --name myAKSCluster --yes --no-wait
    
    Delete the resource group (if you no longer need it):
    az group delete --name myResourceGroup --yes --no-wait
    
    Summary

    Set up the Azure CLI and log in.
    Create a resource group.
    Create an AKS cluster.
    Configure kubectl to connect to your cluster.
    Verify the cluster.
    Deploy and expose an application.
    Clean up resources when done.

This guide covers the basics of creating and managing an AKS cluster on Azure. Depending on your requirements, you might need to configure additional settings such as networking, security, and scaling.


    
    
    




Comments

Popular posts from this blog

Delploy Cluster : Managed K8 & Self Managed K8

ctr | nerdctl | crictl

Deploy To Kubernetes with Jenkins GitOps GitHub Pipeline