Part 1-Creating a DevOps Pipeline to deploy Docker Containers using Azure Kubernetes Service and Infrastructure as Code (1 of 3)
Of course you know Bill Gates is no longer the richest man in the world. It is now his nemesis over at Amazon. Bill Gates is not running Microsoft but has a full time job giving his money away faster than anyone can spend it.
Meanwhile the Cloud War blazes on…
And I was sure the book seller had it in the bag until I began looking at Microsoft’s offering for Kubernetes.
And again, they’ve greatly simplified something that is very complex in a way that… well, only Microsoft can.
Kubernetes is a container-orchestration system that automates deployment, scaling and management of containerized applications.
It was originally designed and used at Google and is now maintained by the Cloud Native Computing Foundation.
It is taking the country by storm.
Kubernetes orchestrates the deployment of containers onto clusters. And it does it in a way that is pretty magnificent.
Some of the tasks it performs:
· Horizontal scaling
· Service discovery and load balancing
· Automated rollouts and rollbacks
· Secret and configuration management
But it contains a lot of complexity and is not easy to do.
After a spending a lot of time working with Kubernetes on Aws, I decided to also take a look at what Microsoft offered.
I was not disappointed.
This 3 part article will explain and show how to get a .Net Core application up and running on Docker Containers in load balanced clusters using the Azure Kubernetes Service (AKS) and Infrastructure as Code.
It will be done inside a Continuous Deployment pipeline!!
And if you’re signed up for an Azure Free Tier, run your builds as public on Azure DevOps (formerly VSTS) and put your code on free Git repo, you can do this one and many like it for free!
The source code for this article is a public repo in my GitHub account.
You can just grab the repo and following along. If you like, fork it and use it.
Just realize that in this section with the resource group templates you’ll have to use the templates that you will create in this series of articles.
This is what we’ll be doing in 3 parts:
1. Create a Kubernetes cluster using the Azure Kubernetes Service, create an ARM template (Azure Resource Manager) from the service deployment and save it as Infrastructure as Code.
2. Create an automated build that will build the Docker container and push it out to Docker Hub.
3. Create an automated release that will create or update the clusters and apply the deployment to the cluster, which gets the containers with the .Net Core workload and runs them.
Part 1: Create a Kubernetes cluster using the Azure Kubernetes Service, create an ARM template (Azure Resource Manager) from the service deployment and save it as Infrastructure as Code.
The first thing we’ll do is create a Kubernetes cluster using the Azure Kubernetes Service. We’re creating this cluster only to create an ARM template from it. Then we’ll use the ARM template later in the DevOps pipeline to create and update the cluster.
Infrastructure as code (IaC) is the process of managing and provisioning infrastructure using resources definition files. This allows all the infrastructure, the VMs, networks, load balancers, etc. to be stored in files inside source control.
Create a Kubernetes cluster using the Azure Kubernetes Service
After creating your free tier in Azure or if you already have one, go to the Azure Portal.
The first thing we want to do is create a Resource Group. A Resource Group is an Azure resource that allows you to group other Azure resources inside of it. You can also delete the resource group to blow away all the resources inside of it at once.
Click on Create a resource.
Type in ‘resource group’ and hit enter.
Click on resource group when it comes up.
Click on the Create button. This begins the creation process.
Choose a unique name for your resource group and a Region. Here I am putting an –rg on the end of my resource group name to specify it is a resource group. This is to make it easier to read and identify.
Review and create.
Click on ‘Resource Groups’ in the left menu. You’ll see the resource group you just created. Click on the resource group to open it.
It will be empty.
Now let’s create our Kubernetes service. Go back to the Azure home page. Click on ‘Create a resource’.
Type in ‘Kubernetes’ and hit enter.
Choose Kubernetes Service when it comes up.
Click the Create button. This begins the creation process.
Choose the resource group you just created and a cluster name. I like to choose these names in a way they will make sense when I am looking at them together later on. Also put in a short DNS name prefix. It can be anything.
Change the Node Count from 3 to 2. They are going to be replicas anyway.
A word of warning here: With a node count of 2, this is going to create 2 VMs. I will show you how to delete them at the end, but don’t go off and forget about them and just let them run. You’ll burn through all your free tier minutes for the month or worse, if you have a card set up, it will start charging your card. Not to scare you away; it’s just something to be aware of.
Click Review + create.
After the validation passes, click on Create.
You’ll see a moving line to indicate your cluster is being created.
Click on Resource Groups in the Menu. You’ll see the resource group you created earlier but also there will be another one that is named similarly but has an MC_ prefix. There is where Azure will put the resources for the new cluster.
Click on it and you’ll begin to see the new cluster resources as they are created. It looks like a lot but there is little or no charge for most of them. The VMs incur the most charge on your free tier minutes.
After the progress indicator stops, click on the icon and you see the deployment is complete. Your cluster has been created.
You’ve got 2 resource groups with cluster resources in them. This includes everything that the Kubernetes service creates.
At this point you have all the resources for a cluster. You could break out a command line and do everything you need to do to get Docker containers running on your clusters.
But that’s not good enough for us. We want Continuous Integration/Continuous Delivery. We want the whole thing running in a pipeline.
So let’s get our infrastructure as code.
Open the primary resource group.
Click on Deployments in the side menu and click on the only deployment available.
Highlight the template and click on View template.
Here is our infrastructure as code. Click on Download.
Download this to your machine.
Unzip it. These are the ARM (Azure Resource Management) template files. We will use this in the Deployment section of your deployment pipeline to create and maintain our Infrastructure as Code.
Once you have created these template, you’ll want to go back and delete the resource groups containing your clusters so you won’t incur charges. We will be creating them in Part 3 in the Release Pipeline using IaC (Infrastructure as Code)!
Go back to the Azure Portal. Click on Resource Groups.
Locate the 2 Resource Groups that were created that contain the cluster and related infrastructure and delete both of them.