Azure CD Pipeline to push image into the AKS (Kubernetes pipeline)

1/16/2020

I am very new creating CD pipeline to grape image from Azure Container Registry(ACR) and push it into the Azure Kubernetes(AKS), In first part like in CI pipeline I am able to push my .netcore api image into the ACR, now my aim is to

Create CD pipeline to grape that image and deploy it to Kubernetes

Although I have created Kubernetes cluster in Azure with running 3 agents. I want to make it very simple without involving any deployment.yaml file etc, Can any one help me out how i can achieve this goal and

What is the exact tasks in my CD pipeline ?

Thanks for the help in advance

-- Saad Awan
azure-devops
devops
kubernetes

2 Answers

1/16/2020

this is impossible doesn't really makes sense without any deployment.yaml file or something similar. you can use:

kubectl create deployment %name% --image=your_image.azurecr.io

but this is not really flexible and won't get you anywhere. If you want to use kubernetes you have to understand deployments\pods\services\etc. No way of getting around that

-- 4c74356b41
Source: StackOverflow

1/16/2020

Creating the YAML file is critical for being able to redeploy and track what is happening. If you don't want to create YAML then you have limited options. You could execute the imperative command from Azure DevOps by using a kubectl task.

kubectl create deployment <name> --image=<image>.azureacr.io

Or you can use the Kubernetes provider for Terraform to avoid creating YAML directly.

Follow up:

So if you are familiar with the Kubernetes imperative commands you can use that to generate your YAML by using the --dry-run and --output options. Like so:

kubectl create deployment <name> --image=<image>.azureacr.io --dry-run --output yaml > example.yaml

That would produce something like looks like this which you can use to bootstrap creating your manifest file.

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: example
  name: example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: example
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

Now you can pull that repo or an artifact that contains that manifest into your Azure DevOps Release Pipeline and add the "Deploy to Kubernetes Cluster" task.

enter image description here

This should get you pretty close to completing a pipeline.

-- Jamie
Source: StackOverflow