Deploying to Azure Container Service

2 minute read

You can find a sample repo for deploying to the Azure Container Service with CloudBees CodeShip Pro on Github here.

Continuous Delivery To Microsoft Azure

To make it easy for you to deploy your application to Azure Container Service, we’ve built deployment images that have the Azure Container Service CLI installed and configured for use in the CI/CD process.

You will simply need to add one of the Azure deployment images as a service in your codeship-services.yml file so that you can run the commands you need.


Prior to getting started, please ensure you have the following:

Authenticating With Azure

To deploy to the Azure Container Service, you will need to add the following values to your encrypted environment variables that you encrypt and include in your codeship-services.yml file:

  • AZURE_USERNAME - Your Azure username

  • AZURE_PASSWORD - The password associated with your Azure user

These variables will be set on the Azure deployment container, which you can read more about below. This deployment container will use the environment variables as part of the authentication required by the Azure Container Service when you run your deployment commands.

Configuring Deployment Service

Once you have created your encrypted environment variables, you will want to add a new service to your codeship-services.yml file.

This file will use the image CodeShip maintains for Azure-based deployments, and will read your code from a volume connected to your primary service.

This service will be used for all of your Azure Container Service deployment commands, and will use the encrypted environment variables you created above.

app: build: image: your-org/your-app path: . dockerfile_path: encrypted_env_file: - env.encrypted volumes: - ./:/code azure_deployment: build: image: codeship/azure-deployment path: ./deployment dockerfile_path: Dockerfile environment: - AZURE_RESOURCE_GROUP=cs-k8s - AZURE_CLUSTER_NAME=cs-k8s-testing encrypted_env_file: - aks.env.encrypted volumes_from: - app

Azure Container Registry

Using Azure Container Service usually involves pushing images to the Azure Container Registry as part of your CI/CD process.

We recommend reading our guide for pushing to the Azure Container Registry, as the deployment commands below will feature an image push based on those instructions.

Deploying Your App

Azure Container Service

Once you have added the deployment service to your codeship-services.yml file, you will now run Azure Container Service deployment commands from your codeship-steps.yml file using that service to execute the commands.

Note that in this example, all of the Container Service deployment commands have been moved to a script file named because the Azure Container Service uses Kubernetes to manage your application.

- name: Azure Container Service Deployment service: azure_deployment command:

Inside the script, you will have something similar to the commands below:

#!/bin/bash set -e : "${AZURE_USERNAME:?Need to set your AZURE_USERNAME}" : "${AZURE_PASSWORD:?Need to set your AZURE_PASSWORD}" : "${AZURE_RESOURCE_GROUP:?Need to set your AZURE_RESOURCE_GROUP}" : "${AZURE_CLUSTER_NAME:?Need to set your AZURE_CLUSTER_NAME}" echo "Logging into Microsoft Azure using credentials for ${AZURE_USERNAME}" az login --username "${AZURE_USERNAME}" --password "${AZURE_PASSWORD}" # Configure kubectl echo "Configuring access for kubectl" az aks get-credentials --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_CLUSTER_NAME}" # run the commands required to deploy the application via `kubectl` kubectl version kubectl cluster-info