Introduction to Azure CLI for Kubernetes

The Azure Command-Line Interface (CLI) provides a rich set of commands for managing Azure Kubernetes Service (AKS) clusters. This guide will walk you through essential commands for interacting with your Kubernetes deployments directly from your terminal.

Getting Started

Before you begin, ensure you have the Azure CLI installed and are logged in to your Azure account. For Kubernetes-specific commands, you'll typically interact with the az aks command group.

Prerequisite: Install Azure CLI and log in with az login.

Cluster Management

Create, manage, and delete your AKS clusters using the following commands:

Creating an AKS Cluster

To create a new AKS cluster, use the az aks create command. You'll need to specify a resource group, a name for your cluster, and other configuration options.

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

Getting Cluster Credentials

To configure kubectl to connect to your AKS cluster, use the az aks get-credentials command.

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
Merged "myAKSCluster" as current context in /home/user/.kube/config

Listing AKS Clusters

View all AKS clusters in your subscription or a specific resource group:

az aks list --output table

Deleting an AKS Cluster

To remove an AKS cluster and all its associated resources:

az aks delete --resource-group myResourceGroup --name myAKSCluster

Application Deployment

Deploy your containerized applications to AKS using standard Kubernetes manifests and Helm charts.

Deploying Kubernetes Manifests

Once your kubectl is configured, you can deploy using:

kubectl apply -f deployment.yaml

Deploying with Helm

Helm is a package manager for Kubernetes. You can manage Helm charts directly:

helm install my-release ./my-chart

Listing Deployments

View running deployments in your cluster:

kubectl get deployments

Monitoring and Logging

Azure CLI integrates with Azure Monitor for comprehensive insights into your cluster's performance and health.

Tip: Ensure the monitoring addon is enabled during cluster creation for full integration.

Accessing Pod Logs

Retrieve logs from your application pods:

kubectl logs -n

Viewing Cluster Metrics

Get metrics for your nodes and pods:

kubectl top nodes
kubectl top pods -n

Networking and Security

Manage network policies, ingress controllers, and service principals for secure communication.

Configuring Ingress

Deploy and manage ingress controllers to expose your services to external traffic.

Managing Network Policies

Implement network segmentation within your cluster using Kubernetes Network Policies.

Advanced Topics

Explore more advanced features such as auto-scaling, integration with Azure services, and custom configurations.

Cluster Auto-scaler

Configure your cluster to automatically scale the number of nodes based on workload demands. This can be enabled via the Azure portal or by updating your cluster's profile using the CLI.

az aks scale \ --resource-group myResourceGroup \ --name myAKSCluster \ --node-count 5

Integrating with Azure Services

Learn how to integrate AKS with Azure Container Registry (ACR), Azure Active Directory (AAD), and other Azure services for seamless management.

This documentation provides a starting point. For comprehensive details and advanced scenarios, please refer to the official Azure AKS documentation.