• United States+1
  • United Kingdom+44
  • Afghanistan (‫افغانستان‬‎)+93
  • Albania (Shqipëri)+355
  • Algeria (‫الجزائر‬‎)+213
  • American Samoa+1684
  • Andorra+376
  • Angola+244
  • Anguilla+1264
  • Antigua and Barbuda+1268
  • Argentina+54
  • Armenia (Հայաստան)+374
  • Aruba+297
  • Australia+61
  • Austria (Österreich)+43
  • Azerbaijan (Azərbaycan)+994
  • Bahamas+1242
  • Bahrain (‫البحرين‬‎)+973
  • Bangladesh (বাংলাদেশ)+880
  • Barbados+1246
  • Belarus (Беларусь)+375
  • Belgium (België)+32
  • Belize+501
  • Benin (Bénin)+229
  • Bermuda+1441
  • Bhutan (འབྲུག)+975
  • Bolivia+591
  • Bosnia and Herzegovina (Босна и Херцеговина)+387
  • Botswana+267
  • Brazil (Brasil)+55
  • British Indian Ocean Territory+246
  • British Virgin Islands+1284
  • Brunei+673
  • Bulgaria (България)+359
  • Burkina Faso+226
  • Burundi (Uburundi)+257
  • Cambodia (កម្ពុជា)+855
  • Cameroon (Cameroun)+237
  • Canada+1
  • Cape Verde (Kabu Verdi)+238
  • Caribbean Netherlands+599
  • Cayman Islands+1345
  • Central African Republic (République centrafricaine)+236
  • Chad (Tchad)+235
  • Chile+56
  • China (中国)+86
  • Christmas Island+61
  • Cocos (Keeling) Islands+61
  • Colombia+57
  • Comoros (‫جزر القمر‬‎)+269
  • Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)+243
  • Congo (Republic) (Congo-Brazzaville)+242
  • Cook Islands+682
  • Costa Rica+506
  • Côte d’Ivoire+225
  • Croatia (Hrvatska)+385
  • Cuba+53
  • Curaçao+599
  • Cyprus (Κύπρος)+357
  • Czech Republic (Česká republika)+420
  • Denmark (Danmark)+45
  • Djibouti+253
  • Dominica+1767
  • Dominican Republic (República Dominicana)+1
  • Ecuador+593
  • Egypt (‫مصر‬‎)+20
  • El Salvador+503
  • Equatorial Guinea (Guinea Ecuatorial)+240
  • Eritrea+291
  • Estonia (Eesti)+372
  • Ethiopia+251
  • Falkland Islands (Islas Malvinas)+500
  • Faroe Islands (Føroyar)+298
  • Fiji+679
  • Finland (Suomi)+358
  • France+33
  • French Guiana (Guyane française)+594
  • French Polynesia (Polynésie française)+689
  • Gabon+241
  • Gambia+220
  • Georgia (საქართველო)+995
  • Germany (Deutschland)+49
  • Ghana (Gaana)+233
  • Gibraltar+350
  • Greece (Ελλάδα)+30
  • Greenland (Kalaallit Nunaat)+299
  • Grenada+1473
  • Guadeloupe+590
  • Guam+1671
  • Guatemala+502
  • Guernsey+44
  • Guinea (Guinée)+224
  • Guinea-Bissau (Guiné Bissau)+245
  • Guyana+592
  • Haiti+509
  • Honduras+504
  • Hong Kong (香港)+852
  • Hungary (Magyarország)+36
  • Iceland (Ísland)+354
  • India (भारत)+91
  • Indonesia+62
  • Iran (‫ایران‬‎)+98
  • Iraq (‫العراق‬‎)+964
  • Ireland+353
  • Isle of Man+44
  • Israel (‫ישראל‬‎)+972
  • Italy (Italia)+39
  • Jamaica+1876
  • Japan (日本)+81
  • Jersey+44
  • Jordan (‫الأردن‬‎)+962
  • Kazakhstan (Казахстан)+7
  • Kenya+254
  • Kiribati+686
  • Kosovo+383
  • Kuwait (‫الكويت‬‎)+965
  • Kyrgyzstan (Кыргызстан)+996
  • Laos (ລາວ)+856
  • Latvia (Latvija)+371
  • Lebanon (‫لبنان‬‎)+961
  • Lesotho+266
  • Liberia+231
  • Libya (‫ليبيا‬‎)+218
  • Liechtenstein+423
  • Lithuania (Lietuva)+370
  • Luxembourg+352
  • Macau (澳門)+853
  • Macedonia (FYROM) (Македонија)+389
  • Madagascar (Madagasikara)+261
  • Malawi+265
  • Malaysia+60
  • Maldives+960
  • Mali+223
  • Malta+356
  • Marshall Islands+692
  • Martinique+596
  • Mauritania (‫موريتانيا‬‎)+222
  • Mauritius (Moris)+230
  • Mayotte+262
  • Mexico (México)+52
  • Micronesia+691
  • Moldova (Republica Moldova)+373
  • Monaco+377
  • Mongolia (Монгол)+976
  • Montenegro (Crna Gora)+382
  • Montserrat+1664
  • Morocco (‫المغرب‬‎)+212
  • Mozambique (Moçambique)+258
  • Myanmar (Burma) (မြန်မာ)+95
  • Namibia (Namibië)+264
  • Nauru+674
  • Nepal (नेपाल)+977
  • Netherlands (Nederland)+31
  • New Caledonia (Nouvelle-Calédonie)+687
  • New Zealand+64
  • Nicaragua+505
  • Niger (Nijar)+227
  • Nigeria+234
  • Niue+683
  • Norfolk Island+672
  • North Korea (조선 민주주의 인민 공화국)+850
  • Northern Mariana Islands+1670
  • Norway (Norge)+47
  • Oman (‫عُمان‬‎)+968
  • Pakistan (‫پاکستان‬‎)+92
  • Palau+680
  • Palestine (‫فلسطين‬‎)+970
  • Panama (Panamá)+507
  • Papua New Guinea+675
  • Paraguay+595
  • Peru (Perú)+51
  • Philippines+63
  • Poland (Polska)+48
  • Portugal+351
  • Puerto Rico+1
  • Qatar (‫قطر‬‎)+974
  • Réunion (La Réunion)+262
  • Romania (România)+40
  • Russia (Россия)+7
  • Rwanda+250
  • Saint Barthélemy (Saint-Barthélemy)+590
  • Saint Helena+290
  • Saint Kitts and Nevis+1869
  • Saint Lucia+1758
  • Saint Martin (Saint-Martin (partie française))+590
  • Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)+508
  • Saint Vincent and the Grenadines+1784
  • Samoa+685
  • San Marino+378
  • São Tomé and Príncipe (São Tomé e Príncipe)+239
  • Saudi Arabia (‫المملكة العربية السعودية‬‎)+966
  • Senegal (Sénégal)+221
  • Serbia (Србија)+381
  • Seychelles+248
  • Sierra Leone+232
  • Singapore+65
  • Sint Maarten+1721
  • Slovakia (Slovensko)+421
  • Slovenia (Slovenija)+386
  • Solomon Islands+677
  • Somalia (Soomaaliya)+252
  • South Africa+27
  • South Korea (대한민국)+82
  • South Sudan (‫جنوب السودان‬‎)+211
  • Spain (España)+34
  • Sri Lanka (ශ්‍රී ලංකාව)+94
  • Sudan (‫السودان‬‎)+249
  • Suriname+597
  • Svalbard and Jan Mayen+47
  • Swaziland+268
  • Sweden (Sverige)+46
  • Switzerland (Schweiz)+41
  • Syria (‫سوريا‬‎)+963
  • Taiwan (台灣)+886
  • Tajikistan+992
  • Tanzania+255
  • Thailand (ไทย)+66
  • Timor-Leste+670
  • Togo+228
  • Tokelau+690
  • Tonga+676
  • Trinidad and Tobago+1868
  • Tunisia (‫تونس‬‎)+216
  • Turkey (Türkiye)+90
  • Turkmenistan+993
  • Turks and Caicos Islands+1649
  • Tuvalu+688
  • U.S. Virgin Islands+1340
  • Uganda+256
  • Ukraine (Україна)+380
  • United Arab Emirates (‫الإمارات العربية المتحدة‬‎)+971
  • United Kingdom+44
  • United States+1
  • Uruguay+598
  • Uzbekistan (Oʻzbekiston)+998
  • Vanuatu+678
  • Vatican City (Città del Vaticano)+39
  • Venezuela+58
  • Vietnam (Việt Nam)+84
  • Wallis and Futuna+681
  • Western Sahara (‫الصحراء الغربية‬‎)+212
  • Yemen (‫اليمن‬‎)+967
  • Zambia+260
  • Zimbabwe+263
  • Åland Islands+358
Thanks! We'll be in touch in the next 12 hours
Oops! Something went wrong while submitting the form.

Continuous Deployment with Azure Kubernetes Service, Azure Container Registry & Jenkins

Introduction

Containerization has taken the application development world by storm. Kubernetes has become the standard way of deploying new containerized distributed applications used by the largest enterprises in a wide range of industries for mission-critical tasks, it has become one of the biggest open-source success stories.

Although Google Cloud has been providing Kubernetes as a service since November 2014 (Note it started with a beta project), Microsoft with AKS (Azure Kubernetes Service) and Amazon with EKS (Elastic Kubernetes Service)  have jumped on to the scene in the second half of 2017.

Example:

AWS had KOPS

Azure had Azure Container Service.

However, they were wrapper tools available prior to these services which would help a user create a Kubernetes cluster, but the management and the maintenance (like monitoring and upgrades) needed efforts.

Azure Container Registry:

With container demand growing, there is always a need in the market for storing and protecting the container images. Microsoft provides a Geo Replica featured private repository as a service named Azure Container Registry.

Azure Container Registry is a registry offering from Microsoft for hosting container images privately. It integrates well with orchestrators like Azure Container Service, including Docker Swarm, DC/OS, and the new Azure Kubernetes service. Moreover, ACR  provides capabilities such as Azure Active Directory-based authentication, webhook support, and delete operations.

The coolest feature provided is Geo-Replication. This will create multiple copies of your image and distribute it across the globe and the container when spawned will have access to the image which is nearest.

Although Microsoft has good documentation on how to set up ACR  in your Azure Subscription, we did encounter some issues and hence decided to write a blog on the precautions and steps required to configure the Registry in the correct manner.

Note: We tried this using a free trial account. You can setup it up by referring the following link

Prerequisites:

  • Make sure you have resource groups created in the supported region.
    Supported Regions: eastus, westeurope, centralus, canada central, canadaeast
  • If you are using Azure CLI for operations please make sure you use the version: 2.0.23 or 2.0.25 (This was the latest version at the time of writing this blog)

Steps to install Azure CLI 2.0.23 or 2.0.25 (ubuntu 16.04 workstation):

echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \          
sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893
sudo apt-get install apt-transport-httpssudo apt-get update && sudo apt-get install azure-cli
Install a specific version:
sudo apt install azure-cli=2.0.23-1
sudo apt install azure-cli=2.0.25.1
view raw install_azure hosted with ❤ by GitHub

Steps for Container Registry Setup:

  • Login to your Azure Account:

az  login --username --password
view raw login.js hosted with ❤ by GitHub

  • Create a resource group:

az group create --name <RESOURCE-GROUP-NAME>  --location eastus
Example : az group create --name acr-rg  --location eastus
view raw resource.js hosted with ❤ by GitHub

  • Create a Container Registry:

az acr create --resource-group <RESOURCE-GROUP-NAME> --name <CONTAINER-REGISTRY-NAME> --sku Basic --admin-enabled true
Example : az acr create --resource-group acr-rg --name testacr --sku Basic --admin-enabled true

Note: SKU defines the storage available for the registry for type Basic the storage available is 10GB, 1 WebHook and the billing amount is 11 Rs/day.

For detailed information on the different SKU available visit the following link

  • Login to the registry :

az acr login --name <CONTAINER-REGISTRY-NAME>
Example :az acr login --name testacr

  • Sample docker file for a node application :

FROM node:carbon
# Create app directory
WORKDIR /usr/src/app
COPY package*.json ./
# RUN npm install
EXPOSE 8080
CMD [ "npm", "start" ]

  • Build the docker image :

docker build -t <image-tag>:<software>
Example :docker build -t base:node8
view raw build_docker.js hosted with ❤ by GitHub

  • Get the login server value for your ACR :

az acr list --resource-group acr-rg --query "[].{acrLoginServer:loginServer}" --output table
Output  :testacr.azurecr.io
view raw login_server.js hosted with ❤ by GitHub

  • Tag the image with the Login Server Value:
    Note: Get the image ID from docker images command

Example:

docker tag image-id testacr.azurecr.io/base:node8

Push the image to the Azure Container Registry:Example:

docker push testacr.azurecr.io/base:node8
view raw push_image.sh hosted with ❤ by GitHub

Microsoft does provide a GUI option to create the ACR.

  • List Images in the Registry:

Example:

az acr repository list --name testacr --output table
view raw list_image.js hosted with ❤ by GitHub

  • List tags for the Images:

Example:

az acr repository show-tags --name testacr --repository <name> --output table
view raw list_tag.js hosted with ❤ by GitHub

  • How to use the ACR image in Kubernetes deployment: Use the login Server Name + the image name

Example :

containers:-
name: demo
image: testacr.azurecr.io/base:node8
view raw test_acr.js hosted with ❤ by GitHub

Azure Kubernetes Service

Microsoft released the public preview of Managed Kubernetes for Azure Container Service (AKS) on October 24, 2017. This service simplifies the deployment, management, and operations of Kubernetes. It features an Azure-hosted control plane, automated upgrades, self-healing, easy scaling.

Similarly to Google AKE and Amazon EKS, this new service will allow access to the nodes only and the master will be managed by Cloud Provider. For more information visit the following link.

Let's now get our hands dirty and deploy an AKS infrastructure to play with:

  • Enable AKS preview for your Azure Subscription: At the time of writing this blog, AKS is in preview mode, it requires a feature flag on your subscription.

az provider register -n Microsoft.ContainerService
view raw enable_aks.js hosted with ❤ by GitHub

  • Kubernetes Cluster Creation Command: Note: A new separate resource group should be created for the Kubernetes service.Since the service is in preview, it is available only to certain regions.

Make sure you create a resource group under the following regions.

eastus, westeurope, centralus, canadacentral, canadaeast
az  group create  --name  <RESOURCE-GROUP>   --location eastus
Example : az group create --name aks-rg --location eastus
az aks create --resource-group <RESOURCE-GROUP-NAME> --name <CLUSTER-NAME>   --node-count 2 --generate-ssh-keys
Example : az aks create --resource-group aks-rg --name akscluster  --node-count 2 --generate-ssh-keys

Example with different arguments :

Create a Kubernetes cluster with a specific version.

az aks create -g MyResourceGroup -n MyManagedCluster --kubernetes-version 1.8.1
view raw create_aks hosted with ❤ by GitHub

Create a Kubernetes cluster with a larger node pool.

az aks create -g MyResourceGroup -n MyManagedCluster --node-count 7
view raw mode_count.js hosted with ❤ by GitHub

Install the Kubectl CLI :

To connect to the kubernetes cluster from the client computer Kubectl command line client is required.

sudo az aks install-cli
view raw sudo_az.sh hosted with ❤ by GitHub

Note: If you're using Azure CloudShell, kubectl is already installed. If you want to install it locally, run the above  command:

  • To configure kubectl to connect to your Kubernetes cluster :

az aks get-credentials --resource-group=<RESOURCE-GROUP-NAME> --name=<CLUSTER-NAME>

Example :

az aks get-credentials --resource-group=aks-rg --name=akscluster
view raw aks_cluster.js hosted with ❤ by GitHub

  • Verify the connection to the cluster :

kubectl get nodes -o wide

  • For all the command line features available for Azure check the link: https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest

We had encountered a few issues while setting up the AKS cluster at the time of writing this blog. Listing them along with the workaround/fix:

az aks create --resource-group aks-rg --name akscluster  --node-count 2 --generate-ssh-keys
view raw command.js hosted with ❤ by GitHub

Error: Operation failed with status: 'Bad Request'.

Details: Resource provider registrations Microsoft.Compute, Microsoft.Storage, Microsoft.Network are needed we need to enable them.

Fix: If you are using the trial account, click on subscriptions and check whether the following providers are registered or not :

  • Microsoft.Compute
  • Microsoft.Storage
  • Microsoft.Network
  • Microsoft.ContainerRegistry
  • Microsoft.ContainerService

Error: We had encountered the following mentioned open issues at the time of writing this blog.

  1. Issue-1
  2. Issue-2
  3. Issue-3

Jenkins setup for CI/CD with ACR, AKS

Microsoft provides a solution template which will install the latest stable Jenkins version on a Linux (Ubuntu 14.04 LTS) VM along with tools and plugins configured to work with Azure. This includes:

  • git for source control
  • Azure Credentials plugin for connecting securely
  • Azure VM Agents plugin for elastic build, test and continuous integration
  • Azure Storage plugin for storing artifacts
  • Azure CLI to deploy apps using scripts

Refer the below link to bring up the Instance

Pipeline plan for Spinning up a Nodejs Application using ACR - AKS - Jenkins

Azure Pipeline

What the pipeline accomplishes :

Stage 1:

The code gets pushed in the Github. The Jenkins job gets triggered automatically. The Dockerfile is checked out from Github.

Stage 2:

Docker builds an image from the Dockerfile and then the image is tagged with the build number.Additionally, the latest tag is also attached to the image for the containers to use.

Stage 3:

We have default deployment and service YAML files stored on the Jenkins server. Jenkins makes a copy of the default YAML files, make the necessary changes according to the build and put them in a separate folder.

Stage 4:

kubectl was initially configured at the time of setting up AKS on the Jenkins server. The YAML files are fed to the kubectl util which in turn creates pods and services.

Sample Jenkins pipeline code :

node {      
// Mark the code checkout 'stage'....        
stage('Checkout the dockefile from GitHub') {            
git branch: 'docker-file', credentialsId: 'git_credentials', url: 'https://gitlab.com/demo.git'        
}        
// Build and Deploy to ACR 'stage'...        
stage('Build the Image and Push to Azure Container Registry') {                
app = docker.build('testacr.azurecr.io/demo')                
withDockerRegistry([credentialsId: 'acr_credentials', url: 'https://testacr.azurecr.io']) {                
app.push("${env.BUILD_NUMBER}")                
app.push('latest')                
}        
}        
stage('Build the Kubernetes YAML Files for New App') {
<The code here will differ depending on the YAMLs used for the application>        
}        
stage('Delpoying the App on Azure Kubernetes Service') {            
app = docker.image('testacr.azurecr.io/demo:latest')            
withDockerRegistry([credentialsId: 'acr_credentials', url: 'https://testacr.azurecr.io']) {            
app.pull()            
sh "kubectl create -f ."            
}      
}    
}

What we achieved:

  • We managed to create a private Docker registry on Azure using the ACR feature using az-cli 2.0.25.
  • Secondly, we were able to spin up a private Kubernetes cluster on Azure with 2 nodes.
  • Setup Up Jenkins using a pre-cooked template which had all the plugins necessary for communication with ACR and AKS.
  • Orchestrate  a Continuous Deployment pipeline in Jenkins which uses docker features.
Get the latest engineering blogs delivered straight to your inbox.
No spam. Only expert insights.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Did you like the blog? If yes, we're sure you'll also like to work with the people who write them - our best-in-class engineering team.

We're looking for talented developers who are passionate about new emerging technologies. If that's you, get in touch with us.

Explore current openings

Continuous Deployment with Azure Kubernetes Service, Azure Container Registry & Jenkins

Introduction

Containerization has taken the application development world by storm. Kubernetes has become the standard way of deploying new containerized distributed applications used by the largest enterprises in a wide range of industries for mission-critical tasks, it has become one of the biggest open-source success stories.

Although Google Cloud has been providing Kubernetes as a service since November 2014 (Note it started with a beta project), Microsoft with AKS (Azure Kubernetes Service) and Amazon with EKS (Elastic Kubernetes Service)  have jumped on to the scene in the second half of 2017.

Example:

AWS had KOPS

Azure had Azure Container Service.

However, they were wrapper tools available prior to these services which would help a user create a Kubernetes cluster, but the management and the maintenance (like monitoring and upgrades) needed efforts.

Azure Container Registry:

With container demand growing, there is always a need in the market for storing and protecting the container images. Microsoft provides a Geo Replica featured private repository as a service named Azure Container Registry.

Azure Container Registry is a registry offering from Microsoft for hosting container images privately. It integrates well with orchestrators like Azure Container Service, including Docker Swarm, DC/OS, and the new Azure Kubernetes service. Moreover, ACR  provides capabilities such as Azure Active Directory-based authentication, webhook support, and delete operations.

The coolest feature provided is Geo-Replication. This will create multiple copies of your image and distribute it across the globe and the container when spawned will have access to the image which is nearest.

Although Microsoft has good documentation on how to set up ACR  in your Azure Subscription, we did encounter some issues and hence decided to write a blog on the precautions and steps required to configure the Registry in the correct manner.

Note: We tried this using a free trial account. You can setup it up by referring the following link

Prerequisites:

  • Make sure you have resource groups created in the supported region.
    Supported Regions: eastus, westeurope, centralus, canada central, canadaeast
  • If you are using Azure CLI for operations please make sure you use the version: 2.0.23 or 2.0.25 (This was the latest version at the time of writing this blog)

Steps to install Azure CLI 2.0.23 or 2.0.25 (ubuntu 16.04 workstation):

echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \          
sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893
sudo apt-get install apt-transport-httpssudo apt-get update && sudo apt-get install azure-cli
Install a specific version:
sudo apt install azure-cli=2.0.23-1
sudo apt install azure-cli=2.0.25.1
view raw install_azure hosted with ❤ by GitHub

Steps for Container Registry Setup:

  • Login to your Azure Account:

az  login --username --password
view raw login.js hosted with ❤ by GitHub

  • Create a resource group:

az group create --name <RESOURCE-GROUP-NAME>  --location eastus
Example : az group create --name acr-rg  --location eastus
view raw resource.js hosted with ❤ by GitHub

  • Create a Container Registry:

az acr create --resource-group <RESOURCE-GROUP-NAME> --name <CONTAINER-REGISTRY-NAME> --sku Basic --admin-enabled true
Example : az acr create --resource-group acr-rg --name testacr --sku Basic --admin-enabled true

Note: SKU defines the storage available for the registry for type Basic the storage available is 10GB, 1 WebHook and the billing amount is 11 Rs/day.

For detailed information on the different SKU available visit the following link

  • Login to the registry :

az acr login --name <CONTAINER-REGISTRY-NAME>
Example :az acr login --name testacr

  • Sample docker file for a node application :

FROM node:carbon
# Create app directory
WORKDIR /usr/src/app
COPY package*.json ./
# RUN npm install
EXPOSE 8080
CMD [ "npm", "start" ]

  • Build the docker image :

docker build -t <image-tag>:<software>
Example :docker build -t base:node8
view raw build_docker.js hosted with ❤ by GitHub

  • Get the login server value for your ACR :

az acr list --resource-group acr-rg --query "[].{acrLoginServer:loginServer}" --output table
Output  :testacr.azurecr.io
view raw login_server.js hosted with ❤ by GitHub

  • Tag the image with the Login Server Value:
    Note: Get the image ID from docker images command

Example:

docker tag image-id testacr.azurecr.io/base:node8

Push the image to the Azure Container Registry:Example:

docker push testacr.azurecr.io/base:node8
view raw push_image.sh hosted with ❤ by GitHub

Microsoft does provide a GUI option to create the ACR.

  • List Images in the Registry:

Example:

az acr repository list --name testacr --output table
view raw list_image.js hosted with ❤ by GitHub

  • List tags for the Images:

Example:

az acr repository show-tags --name testacr --repository <name> --output table
view raw list_tag.js hosted with ❤ by GitHub

  • How to use the ACR image in Kubernetes deployment: Use the login Server Name + the image name

Example :

containers:-
name: demo
image: testacr.azurecr.io/base:node8
view raw test_acr.js hosted with ❤ by GitHub

Azure Kubernetes Service

Microsoft released the public preview of Managed Kubernetes for Azure Container Service (AKS) on October 24, 2017. This service simplifies the deployment, management, and operations of Kubernetes. It features an Azure-hosted control plane, automated upgrades, self-healing, easy scaling.

Similarly to Google AKE and Amazon EKS, this new service will allow access to the nodes only and the master will be managed by Cloud Provider. For more information visit the following link.

Let's now get our hands dirty and deploy an AKS infrastructure to play with:

  • Enable AKS preview for your Azure Subscription: At the time of writing this blog, AKS is in preview mode, it requires a feature flag on your subscription.

az provider register -n Microsoft.ContainerService
view raw enable_aks.js hosted with ❤ by GitHub

  • Kubernetes Cluster Creation Command: Note: A new separate resource group should be created for the Kubernetes service.Since the service is in preview, it is available only to certain regions.

Make sure you create a resource group under the following regions.

eastus, westeurope, centralus, canadacentral, canadaeast
az  group create  --name  <RESOURCE-GROUP>   --location eastus
Example : az group create --name aks-rg --location eastus
az aks create --resource-group <RESOURCE-GROUP-NAME> --name <CLUSTER-NAME>   --node-count 2 --generate-ssh-keys
Example : az aks create --resource-group aks-rg --name akscluster  --node-count 2 --generate-ssh-keys

Example with different arguments :

Create a Kubernetes cluster with a specific version.

az aks create -g MyResourceGroup -n MyManagedCluster --kubernetes-version 1.8.1
view raw create_aks hosted with ❤ by GitHub

Create a Kubernetes cluster with a larger node pool.

az aks create -g MyResourceGroup -n MyManagedCluster --node-count 7
view raw mode_count.js hosted with ❤ by GitHub

Install the Kubectl CLI :

To connect to the kubernetes cluster from the client computer Kubectl command line client is required.

sudo az aks install-cli
view raw sudo_az.sh hosted with ❤ by GitHub

Note: If you're using Azure CloudShell, kubectl is already installed. If you want to install it locally, run the above  command:

  • To configure kubectl to connect to your Kubernetes cluster :

az aks get-credentials --resource-group=<RESOURCE-GROUP-NAME> --name=<CLUSTER-NAME>

Example :

az aks get-credentials --resource-group=aks-rg --name=akscluster
view raw aks_cluster.js hosted with ❤ by GitHub

  • Verify the connection to the cluster :

kubectl get nodes -o wide

  • For all the command line features available for Azure check the link: https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest

We had encountered a few issues while setting up the AKS cluster at the time of writing this blog. Listing them along with the workaround/fix:

az aks create --resource-group aks-rg --name akscluster  --node-count 2 --generate-ssh-keys
view raw command.js hosted with ❤ by GitHub

Error: Operation failed with status: 'Bad Request'.

Details: Resource provider registrations Microsoft.Compute, Microsoft.Storage, Microsoft.Network are needed we need to enable them.

Fix: If you are using the trial account, click on subscriptions and check whether the following providers are registered or not :

  • Microsoft.Compute
  • Microsoft.Storage
  • Microsoft.Network
  • Microsoft.ContainerRegistry
  • Microsoft.ContainerService

Error: We had encountered the following mentioned open issues at the time of writing this blog.

  1. Issue-1
  2. Issue-2
  3. Issue-3

Jenkins setup for CI/CD with ACR, AKS

Microsoft provides a solution template which will install the latest stable Jenkins version on a Linux (Ubuntu 14.04 LTS) VM along with tools and plugins configured to work with Azure. This includes:

  • git for source control
  • Azure Credentials plugin for connecting securely
  • Azure VM Agents plugin for elastic build, test and continuous integration
  • Azure Storage plugin for storing artifacts
  • Azure CLI to deploy apps using scripts

Refer the below link to bring up the Instance

Pipeline plan for Spinning up a Nodejs Application using ACR - AKS - Jenkins

Azure Pipeline

What the pipeline accomplishes :

Stage 1:

The code gets pushed in the Github. The Jenkins job gets triggered automatically. The Dockerfile is checked out from Github.

Stage 2:

Docker builds an image from the Dockerfile and then the image is tagged with the build number.Additionally, the latest tag is also attached to the image for the containers to use.

Stage 3:

We have default deployment and service YAML files stored on the Jenkins server. Jenkins makes a copy of the default YAML files, make the necessary changes according to the build and put them in a separate folder.

Stage 4:

kubectl was initially configured at the time of setting up AKS on the Jenkins server. The YAML files are fed to the kubectl util which in turn creates pods and services.

Sample Jenkins pipeline code :

node {      
// Mark the code checkout 'stage'....        
stage('Checkout the dockefile from GitHub') {            
git branch: 'docker-file', credentialsId: 'git_credentials', url: 'https://gitlab.com/demo.git'        
}        
// Build and Deploy to ACR 'stage'...        
stage('Build the Image and Push to Azure Container Registry') {                
app = docker.build('testacr.azurecr.io/demo')                
withDockerRegistry([credentialsId: 'acr_credentials', url: 'https://testacr.azurecr.io']) {                
app.push("${env.BUILD_NUMBER}")                
app.push('latest')                
}        
}        
stage('Build the Kubernetes YAML Files for New App') {
<The code here will differ depending on the YAMLs used for the application>        
}        
stage('Delpoying the App on Azure Kubernetes Service') {            
app = docker.image('testacr.azurecr.io/demo:latest')            
withDockerRegistry([credentialsId: 'acr_credentials', url: 'https://testacr.azurecr.io']) {            
app.pull()            
sh "kubectl create -f ."            
}      
}    
}

What we achieved:

  • We managed to create a private Docker registry on Azure using the ACR feature using az-cli 2.0.25.
  • Secondly, we were able to spin up a private Kubernetes cluster on Azure with 2 nodes.
  • Setup Up Jenkins using a pre-cooked template which had all the plugins necessary for communication with ACR and AKS.
  • Orchestrate  a Continuous Deployment pipeline in Jenkins which uses docker features.

Did you like the blog? If yes, we're sure you'll also like to work with the people who write them - our best-in-class engineering team.

We're looking for talented developers who are passionate about new emerging technologies. If that's you, get in touch with us.

Explore current openings