Setting up service connections for Azure Container Registry (ACR) and Azure Kubernetes Service (AKS) in Azure DevOps - kondareddypp/azure-network-fundamentals GitHub Wiki

Setting up service connections for Azure Container Registry (ACR) and Azure Kubernetes Service (AKS) in Azure DevOps ensures seamless integration and secure communication between Azure resources. Here's how to do it:


1. Azure Container Registry (ACR) Service Connection

  1. Navigate to Azure DevOps:

    • Go to your Azure DevOps project.
    • Click on Project Settings in the bottom-left corner.
  2. Create a New Service Connection:

    • Under Pipelines, select Service Connections.
    • Click New Service Connection > Docker Registry.
  3. Configure the Connection:

    • Choose Azure Container Registry.
    • If you're logged into Azure DevOps with the same Azure account, your container registries will be listed.
    • Select your registry and click Verify to ensure the connection works.
  4. Assign a Name:

    • Provide a meaningful name for the connection (e.g., acr-service-connection).
    • Save the connection.

2. Azure Kubernetes Service (AKS) Service Connection

  1. Navigate to Azure DevOps:

    • Go to Project Settings > Service Connections in your Azure DevOps project.
  2. Create a New Service Connection:

    • Select Kubernetes as the service connection type.
    • Choose the Service Principal (Automatic) option for a simplified setup.
  3. Provide AKS Details:

    • Select your Azure Subscription.
    • Choose the Resource Group and Kubernetes Cluster from the dropdown menus.
    • If your cluster isn't listed, ensure your Azure account has the necessary permissions.
  4. Verify and Save:

    • Test the connection to ensure it's working properly.
    • Assign a name for the connection (e.g., aks-service-connection).
    • Save the service connection.

Using the Service Connections in Pipelines

  • In your YAML pipeline, reference the service connection name:
    steps:
    - task: Docker@2
      inputs:
        containerRegistry: 'acr-service-connection'
        command: 'buildAndPush'
        repository: 'your-image-name'
        Dockerfile: '**/Dockerfile'
        tags: '$(Build.BuildId)'
    
    - script: |
        kubectl apply -f deployment.yaml
        kubectl apply -f service.yaml
      displayName: 'Deploy to AKS'
      env:
        KUBECONFIG: $(kubeconfig)
    

This setup allows your pipeline to authenticate securely with ACR and AKS.