DEV Community

Cover image for CD onboarding with Harness using Azure.
SAGAR SATAPATHY
SAGAR SATAPATHY

Posted on

CD onboarding with Harness using Azure.

What is Harness?

Harness is the industry's first Software Delivery Platform to use AI to simplify your DevOps processes - CI, CD, Feature Flags, Cloud Costs, and much more.

Why Harness?

Harness is a modern software delivery platform that allows engineers and DevOps to build, test, deploy, and verify software, on-demand.

What is Cloud Delivery Pipeline (CD Pipeline)?

A CD Pipeline is a series of Stages where each Stage deploys a Service to an Environment.A CD Pipeline can perform many additional CD operations, including, but not limited to:

  • Propagating Services and their definitions across Stages
  • Approvals using integrations like Jira and ServiceNow.
  • Synchronizing stage deployments using barriers.
  • Notifications.

Aim: Setting up and running the pipeline which can run an Nginx image on your cluster with Harness using Microsoft Azure!

Image description

PreFlight Checklist!

  1. Forking the Repository✔️
  2. Microsoft Azure Account✔️
  3. A Docker Hub account✔️
  4. Kubernetes cluster✔️ Image description

Steps to set up Azure-kubernetes cluster

  1. Log in to Microsoft Azure Portal,using student id gives you free credit.
  2. Search for Kubernetes Services.
  3. Click on Create.Then click on Create Kubernetes cluster.
  4. Fill up all the necessary details like Kubernetes cluster name-demo(example).
  5. Finally Click Review+Create button then Create and give it some time to Initialize deployment.You will be notified once it's deployed. 6.Click connect and get ready for using Harness. Image description

Steps to set up the Harness Delegate

  1. Log in to your Harness Account. Image description
  2. In The Project Setup tab choose Delegates and hit + Create a Delegate after setting up project:firstproject. Image description Image description
  3. Choose Kubernetes and continue. Enter the following details:
    • Delegate Name:newdelegate
    • Delegate Size:Small
    • What installer do you want to use?:Kubernetes Image description
  4. Press Continue.
  5. Download YAML file and then Continue
  6. Open Kubernetes Cluster tab and Press Connect then Open Cloud Shell
  7. Upload the YAML file in the cli or copy the content of YAML file to cli of Cloud Shell
  8. Enter the following code
kubectl apply -f harness-delegate.yml
Enter fullscreen mode Exit fullscreen mode

Image description
Press Done once you see green check mark in Checking for
Heartbeat section in Harness tab.
Image description

Secrets and steps to set them up

GitHub Personal Access Token
Harness needs a Personal Access Token to access GitHub repositories.

  1. Login to GitHub and click on Settings from the top-right menu
  2. Select Developer Settings from the list of Account Settings
  3. Select Personal access tokens->Token(Classic)->generate new Token
  4. Click on Generate new token (grant ALL permissions)
  5. Copy the generated token and save it. Image description
  6. Now go to Harness Secret Tab
  7. Click New Secret->Text
  8. Fill up the details and copy the secret key from github token generated and paste it in harness secret just created. Image description

DockerHub Access Token
Sign-in to Docker Hub
Go to Account Setting then Security and generate New
Access Token
and generate.

Image description

  1. Now go to Harness Secret Tab and click New Secret->Text
  2. Fill up details and paste the key generated from docker hub and hit save. Image description

Steps the to set up GitHub Connector

In Harness Dashboard you will notice Connector tab under your
project setup section.

  1. Click + New Connector and choose Github from Code Repositories
    • Name:githubconnector
    • GitHub Account URL: YOUR_GITHUB_URL
    • Test Repository:cd-pipeline-sample and Continue.
    • Username:YOUR_GITHUB_USERNAME
    • Personal Access Token:choose your github secret created in harness
    • Check the Enable API access (recommended)☑️
    • Personal Access Token:choose your github secret created in harness and Continue
  2. Select how you would like to connect to the provider:Connect through a Harness Delegate
  3. Choose the Delegate you created-newdelegate then Save and Continue and Finish.

Steps the to set up Docker Connector

In Harness Dashboard you will notice Connector tab under your
project setup section.

  1. Click + New Connector and choose Docker Repositories from Artifact Repositories.
  2. Select how you would like to connect to the provider:Connect through a Harness Delegate
  3. Select the Delegates this Connector will use:Use Delegate you created-newdelegate then Save and Continue and Finish.

Setting up Project

We have already forked the cd-pipeline-sample.
Its time to create Pipeline and see what we have created.

Setting up the Pipeline

Go to cd-pipeline-sample repo which you forked browse
through*.harness folder* and edit Pipeline.yaml file
Name the projectIdentifier:PROJECT_NAME_CREATED_IN_HARNESS
(for eg:my project name is firstproject)
So Pipeline.yaml will be:

pipeline:
  name: testk8s
  identifier: testk8s
  projectIdentifier: firstproject
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: k8deploy
        identifier: k8deploy
        description: ""
        type: Deployment
        spec:
          serviceConfig:
            serviceRef: k8service
            serviceDefinition:
              spec:
                variables: []
                manifests:
                  - manifest:
                      identifier: manifest
                      type: K8sManifest
                      spec:
                        store:
                          type: Github
                          spec:
                            connectorRef: testhelp
                            gitFetchType: Branch
                            paths:
                              - default-k8s-manifests/Manifests/Files/templates
                            repoName: harness-docs
                            branch: main
                        skipResourceVersioning: false
                  - manifest:
                      identifier: values
                      type: Values
                      spec:
                        store:
                          type: Github
                          spec:
                            connectorRef: testhelp
                            gitFetchType: Branch
                            paths:
                              - default-k8s-manifests/Manifests/Files/ng_values_dockercfg.yaml
                            repoName: harness-docs
                            branch: main
                artifacts:
                  primary:
                    spec:
                      connectorRef: harnessdocker
                      imagePath: <+input>
                      tag: <+input>
                    type: DockerRegistry
              type: Kubernetes
          infrastructure:
            environmentRef: K8Env
            infrastructureDefinition:
              type: KubernetesDirect
              spec:
                connectorRef: test
                namespace: default
                releaseName: release-<+INFRA_KEY>
            allowSimultaneousDeployments: false
          execution:
            steps:
              - step:
                  name: Rollout Deployment
                  identifier: rolloutDeployment
                  type: K8sRollingDeploy
                  timeout: 10m
                  spec:
                    skipDryRun: false
            rollbackSteps:
              - step:
                  name: Rollback Rollout Deployment
                  identifier: rollbackRolloutDeployment
                  type: K8sRollingRollback
                  timeout: 10m
                  spec: {}
        tags: {}
        failureStrategies:
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback
Enter fullscreen mode Exit fullscreen mode
  1. Choose the Pipeline tab from your project in Harness Dashboard and click on + Import From Git
  2. Fill the details according to image Image description
  3. Now open the pipeline you created and click on k8deploy Image description
  4. Under Services -> Select Service click New Service and name it as nginx then choose it from dropdown Image description
  5. Lets setup the manifest now Image description
  6. Click on manifest edit button ->Continue GitHub Connector:CONNECTOR_CREATED_FOR_GITHUB_IN_HARNESS i.e githubconnector. Image description
  7. Edit values by clicking its edit button then Continue and choose the Connector created for Github in Harness Connector and Submit.
  8. Finally lets edit the Docker Artifact->Continue Choose the Docker connecter you created in Harness Connector section.
  9. Click on the button shown in the image and give the path as library/nginx and Submit. Image description
  10. Continue it will take you to Infrastructure section Specify Environment:+ New Environment . Image description
  • Connector: + New Connector
  • Name:kubernetesinfraconnector
  • Details:Use the credentials of a specific Harness Delegate (IAM role, service account, etc) and Continue
  • Delegate:Delegate you created in harness-newdelegate
  • Finally Save and Continue and Finish then Continue.
  • Now hit Save and Save again then Run. Image description

Give tag:latest and click Run Pipeline
🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈🦈

Hoooray we have completed our cd pipeline.
Image description
Image description

👌Happy hacking,see you until next time!अलविदा
About me:freaking_wish 😊
ref:Github repo
vid ref:Harness community

Top comments (1)

Collapse
 
sai143cool profile image
Sai Gangadhar Reddy

Can you make a video of this that will be easily understood better than a document