Friday 3 January 2020

Create Azure CD release pipeline to deploy images on Kubernetes | Docker part 5

We already covered how to build and push Docker image to Docker hub or azure container registry through azure DevOps build pipeline. So we have:
  1. GitHub repo.
  2. Azure devops build pipeline with Container Build and Push tasks.
  3. DockerHub repository. (Public)
  4. Kubernetes service created and running.
Now what we have TODO now:
  1. Create deployment yaml file that required for Kubernetes deployment.
  2.  Add some more task in Build pipeline.
  3. Get Devops artifact.
  4. Create a Release pipeline.
  5. Deploy and verify pods on local Kubernetes dashboard.
Instead of doing TODO, if you want to deploy containers manually on Kubernetes you can follow YouTube video of Houssem Dellai.

Let's have a look on above TODO listed points, one by one. Special thanks to Microsoft Visual Studio, who described nicely on his YouTube video.

Create deployment yaml file that required for Kubernetes deployment.
Get the quick reference from Microsoft Official for creation of deployment file. And create simple kubernetes-deployement.yml in project folder with below content:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mysamplekubapps
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: demo-kub-apps
    spec:
      containers:
        - name: mssample-services-app
          image: rajkrs/docker_linux_redis_netcore:latest
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
    name: demo-kub-apps
spec:
  ports:
    - name: http-port
      port: 80
      targetPort: 80
  selector:
    app: demo-kub-apps
  type: LoadBalancer


Add some more task in Build pipeline.
Because we will be regularly using build id as version variable, so let's create a variable

We want to change deployment file in such a way that, for each build image rajkrs/docker_linux_redis_netcore:latest would become  rajkrs/docker_linux_redis_netcore:<1.100>

So we are adding one CLI script task that will take care of latest version replacement.


Get Artifact.
And will publish changed deployment yml as artifact.

Create a Release pipeline.
We just create a release pipeline and assign the source build pipeline which we have created earlier.




To create Kubernetes service connection, click on New


Make sure in above image we have correct Manifests *. 

Now we have created the release pipeline, you may enable continues deployment  from Artifacts trigger option.


Deploy and verify pods on local Kubernetes dashboard.
Let's got to build and Queue one new build. Verify build completred.


Verify we have pushed tag 1.100 in Dockerhub.
Verify release pipeline is in progress..


Verify release completed successfully.

Verify we have Pods in Kubernetes.

Verify app had assigned with external IP: 52.154.232.146:80


And we are able to browse app. 🙂


Don’t forgot to verify azure subscription credit. 🤯