Drone CI using for CI/CD in AKS environment

Maciej
3 min readJan 7, 2020

--

What is Drone?

CI tool with high affinity with containers. drone.io

Drone action environment

It is running on Docker on-premise (private cloud).

Thing you want to do

  1. Automatically deploy to AKS (Staging Environment) when repository is merged with master
  2. When git tag is hit in the repository (release tag), auto-deploy to AKS (production environment)

General overview

Create an Azure AD service principal

  • Create a service principal with Azure CLI. (You can make it in the portal)
$ is the login
$ az ad sp create-for-rbac -n "[Your SP Name]" --skip-assignment --years 10
  • Please note the [appId], [password], and [tenant] displayed at this time, as they will be used later.
  • Select the ACR IAM in the portal and select + Add.
  • Select [Add role assingment].
  • Grant [AcrPull] permission to the created SP.
  • In the same way, grant [AcrPush] permission.
  • Next, since there is a resource group with AKS VM and Disk called MC_ [Your AKS Name] _ [Your AKS Name] [Region Name] Grant the [Contributor] permission.

By Drone Secret

  • Select [SETTINGS] from the Drone repository.
  • Provide the Secret name and Secret Value and select [ADD A SECRET].
  • Create the following three SECRETs.
  • AZURE_APPLICATION_ID -> [AppId] value noted in advance
  • AZURE_SECRET -> [Password] value that you wrote down in advance
  • AZURE_TENANT_ID -> The value of [tenant] noted in advance

Azure CLI container image creation

  • Create an Azure CLI container image in the Docker repository on the server where Drone CI is running, referring to the following article.

Execute Azure CLI command at the same time as docker run, and destroy the container when execution is completed

  • Create the image name with [azurecli] and the tag with [latest]. This will be used later when deploying to AKS with Drone.

.drone.yaml made

  • Create .drone.yaml in GitHub repository. The steps for building and testing the application are omitted, and only the AKS deployment part is described.
  • The reason for changing the image tag with kubectl set image is that I wanted to fix the image tag to latest in the deployment manifest file. In fact, I wish I could change the manifest file tags, but I couldn’t do anything with the Drone, so I started with latest and changed to the target tag.
  • The image tag contains the Git commit ID for staging, and the release tag (for example, v1.0) for production.

Restore method

  • If you find a bug after release and want to revert to the previous release version, find and select the Drone job tagged with the previous release
  • Just click the [RESTART] button to return to the previous version.

--

--

Maciej
Maciej

Written by Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.

Responses (1)