0%
Azure CLI Commands for Containers and Kubernetes

Azure CLI Commands for Containers and Kubernetes

Discover the Azure CLI commands for managing containers and Kubernetes on Azure.

I

InSkillCoach

· min

Azure CLI Commands for Containers and Kubernetes

Discover the essential commands for managing containers and Kubernetes on Azure.

Azure Container Registry (ACR)

Creation and configuration

# Create a container registry
az acr create \
    --resource-group mon-groupe \
    --name monregistre \
    --sku Basic \
    --admin-enabled true

# Log in to the registry
az acr login --name monregistre

# Create a secret for AKS
az acr credential show --name monregistre

Image management

# Tag an image
docker tag mon-app:latest monregistre.azurecr.io/mon-app:latest

# Push an image
docker push monregistre.azurecr.io/mon-app:latest

# List images
az acr repository list --name monregistre

# Delete an image
az acr repository delete \
    --name monregistre \
    --image mon-app:latest

Azure Kubernetes Service (AKS)

Creating a cluster

# Create an AKS cluster
az aks create \
    --resource-group mon-groupe \
    --name mon-cluster \
    --node-count 2 \
    --generate-ssh-keys \
    --attach-acr monregistre

# Get credentials
az aks get-credentials \
    --resource-group mon-groupe \
    --name mon-cluster

Cluster management

# Scale the cluster
az aks scale \
    --resource-group mon-groupe \
    --name mon-cluster \
    --node-count 3

# Upgrade the cluster
az aks upgrade \
    --resource-group mon-groupe \
    --name mon-cluster \
    --kubernetes-version 1.24.0

# Check the status
az aks show \
    --resource-group mon-groupe \
    --name mon-cluster

Managing Kubernetes Applications

Deploying an application

# Create a deployment
kubectl create deployment mon-app \
    --image=monregistre.azurecr.io/mon-app:latest \
    --replicas=3

# Expose the service
kubectl expose deployment mon-app \
    --type=LoadBalancer \
    --port=80

# Check the status
kubectl get deployments
kubectl get pods
kubectl get services

Resource management

# Create a namespace
kubectl create namespace mon-namespace

# Create a secret
kubectl create secret generic mon-secret \
    --from-literal=username=admin \
    --from-literal=password=secret \
    --namespace mon-namespace

# Create a configmap
kubectl create configmap mon-config \
    --from-literal=APP_ENV=production \
    --namespace mon-namespace

Azure Container Apps

Creating a containerized application

# Create an environment
az containerapp env create \
    --name mon-env \
    --resource-group mon-groupe \
    --location westeurope

# Create an application
az containerapp create \
    --name mon-app \
    --resource-group mon-groupe \
    --environment mon-env \
    --image monregistre.azurecr.io/mon-app:latest \
    --target-port 80 \
    --ingress external

Application management

# Scale
az containerapp replica scale \
    --name mon-app \
    --resource-group mon-groupe \
    --replicas 5

# Update the application
az containerapp update \
    --name mon-app \
    --resource-group mon-groupe \
    --image monregistre.azurecr.io/mon-app:v2

Best Practices

  1. Security

    • Use secrets
    • Scan images
    • Restrict access
    • Update regularly
  2. Performance

    • Optimize images
    • Configure resources
    • Use caching
    • Monitor metrics
  3. Costs

    • Clean up images
    • Optimize clusters
    • Use reservations
    • Monitor usage

Conclusion

Key takeaways:

  • Container management
  • Kubernetes orchestration
  • Containerized applications
  • Best practices

Recommendations:

  • Start with ACR
  • Learn Kubernetes
  • Automate deployments
  • Follow best practices
  • Train on Microsoft Learn
InSkillCoach

About InSkillCoach

Training and technology expert

Coach specializing in advanced technologies and AI, backed by GNeurone Inc.

Certifications:

  • AWS Certified Solutions Architect – Professional
  • Google Cloud certifications
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
1.3k
220

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!