How to run script which start kubernetes cluster on azure devops

8/5/2021

I tried to start #kubernetes cluster and then run tests and publish results. Do you have any idea on how this can be done?

  1. I created a pipeline but I do not know which yml to use
  2. Which task to add first - kubernetes deploy or something else
-- Alexa
azure-devops
kubernetes

1 Answer

9/3/2021

We have Kubernetes deployment.yml file>>It takes the container( image )(exampleacr.io/sampleapp) that we going to publish on AKS App version: app/v1

Service.yml is to just expose the application App version: v1

Both the yml files are to be added .Please refer WAY2 for modifying manually.

enter image description here

WAY 1:

Quick way: Deploy to Azure Kubernetes service will do everything that’s needed because if you use the Deploy to Azure Kubernetes Services template, these variables get defined for you.

Steps:

  1. Create AKS cluster and ACR(container registry) in azure.

  2. In azure Devops:

    Create a pipeline>choose any source:for select an application hosted in git hub

  3. Then select Deploy to Azure Kubernetes service >select your aks subscription> select the existing cluster>then select the container registry that you want to put docker image into.keep the remaining as default

  4. Click on validate and configure

azure pipeline will generate a YAML file.

  1. In the review pipeline YAML of azure-pipelines.yml

You have two stages:Build,deploy

Click save and run:This saves yaml file in master branch and it creates manifests files(deployment.yml and service.yml) for kubernetes deployment.

  1. Click save and run>this will also trigger build.

Reference

WAY2: Using Docker image

  1. To do modifications in the azurepipelines.yml file In the 3rd step from above ,Select Docker image instead of Deploy to Azure Kubernetes service.

  2. Under configure pipeline>If it is in Build.SourcesDirectory in our application , it will appear as say $ Build.SourcesDirectory/app/Dockerfile

That builds the docker file /pipeline.

  1. In the review pipeline YAML of azure-pipelines.yml

    Few things can be modified like

  2. You can change variable tag to repo name: and then deployment and service.yml file can be added to the yml file by doing few modifications

Build stage is automatic and no need to modify there.

You have to Add push and deploy stages in yml file as shown in the article

And get source code here

-- kavyasaraboju-MT
Source: StackOverflow