Skip to main content

Deploy using Kubernetes Manifest

This tutorial will get you started with Harness Continuous Delivery (CD). We will guide you through deploying a Guestbook application using Harness CD pipeline and GitOps methods. This Guestbook application uses a publicly available Kubernetes manifest and Docker image.

Harness CD pipelines allow you to orchestrate and automate your deployment workflows, and push updated application images to your target Kubernetes cluster. Pipelines allow extensive control over how you want to progress artifacts through various dev / test / stage / prod clusters, while running a variety of scans & tests to ensure quality and stability standards you and team may have defined.

You can choose to proceed with the tutorial either by using the command-line interface (Harness CLI) or the user interface (Harness UI).

Before you begin

Verify the following:

  1. Obtain Harness API Token. For steps, go to the Harness documentation on creating a personal API token.
  2. Obtain GitHub personal access token with repo permissions. For steps, go to the GitHub documentation on creating a personal access token.
  3. A Kubernetes cluster. Use your own Kubernetes cluster or we recommend using K3D for installing Harness delegates and deploying a sample application in a local development environment.
  4. Install Helm CLI.
  5. Fork the harnessed-example-apps repository through the GitHub web interface.
    • For details on forking a GitHub repository, go to GitHub docs.

Getting Started with Harness CD


  1. Download and Configure Harness CLI.

    curl -LO https://github.com/harness/harness-cli/releases/download/v0.0.13-alpha/harness-v0.0.13-alpha-darwin-amd64.tar.gz 
    tar -xvf harness-v0.0.13-alpha-darwin-amd64.tar.gz
    echo 'export PATH="'$(pwd)':$PATH"' >> ~/.bash_profile
    source ~/.bash_profile
  2. Clone the Forked harnessed-example-apps repo and change directory.

    git clone https://github.com/GITHUB_ACCOUNTNAME/harnesscd-example-apps.git
    cd harnesscd-example-apps
    note

    Replace GITHUB_ACCOUNTNAME with your GitHub Account name.

  3. Log in to Harness from the CLI.

    harness login --api-key  --account-id HARNESS_API_TOKEN 
    note

    Replace HARNESS_API_TOKEN with Harness API Token that you obtained during the prerequisite section of this tutorial.

caution

For the pipeline to run successfully, please follow all of the following steps as they are, including the naming conventions.

Delegate

The Harness Delegate is a service that runs in your local network or VPC to establish connections between the Harness Manager and various providers such as artifact registries, cloud platforms, etc. The delegate is installed in the target infrastructure (Kubernetes cluster) and performs operations including deployment and integration. To learn more about the delegate, go to delegate Overview.

  1. Log in to the Harness UI. In Project Setup, select Delegates.

    • Select Delegates.

      • Select Install delegate. For this tutorial, let's explore how to install the delegate using Helm.

      • Add the Harness Helm chart repo to your local Helm registry.

        helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
        helm repo update harness-delegate
      • In the command provided, ACCOUNT_ID, MANAGER_ENDPOINT, and DELEGATE_TOKEN are auto-populated values that you can obtain from the delegate Installation wizard.

        helm upgrade -i helm-delegate --namespace harness-delegate-ng --create-namespace \
        harness-delegate/harness-delegate-ng \
        --set delegateName=helm-delegate \
        --set accountId=ACCOUNT_ID \
        --set managerEndpoint=MANAGER_ENDPOINT \
        --set delegateDockerImage=harness/delegate:23.03.78904 \
        --set replicas=1 --set upgrader.enabled=false \
        --set delegateToken=DELEGATE_TOKEN
    • Verify that the delegate is installed successfully and can connect to the Harness Manager.

    • You can also follow the Install Harness delegate on Kubernetes or Docker tutorial to install the delegate using the Terraform Helm Provider or Kubernetes manifest.

Secrets

What are Harness secrets?

Harness offers built-in secret management for encrypted storage of sensitive information. Secrets are decrypted when needed, and only the private network-connected Harness delegate has access to the key management system. You can also integrate your own secret manager. To learn more about secrets in Harness, go to Harness Secret Manager Overview.

  1. Use the following command to add the GitHub PAT you created previously for your secret.

    harness secret --token <YOUR GITHUB PAT>

Connectors

What are connectors?

Connectors in Harness enable integration with 3rd party tools, providing authentication and operations during pipeline runtime. For instance, a GitHub connector facilitates authentication and fetching files from a GitHub repository within pipeline stages. Explore connector how-tos here.

  1. Replace GITHUB_USERNAME with your GitHub account username in the github-connector.yaml

  2. In projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (after account). If it is incorrect, the Harness YAML editor will suggest the correct Id.

  3. Now create the GitHub connector using the following CLI command:

    harness connector --file github-connector.yml apply --git-user <YOUR GITHUB USERNAME>
  4. Please check the delegate name to be helm-delegate in the kubernetes-connector.yml

  5. Create the Kubernetes connector using the following CLI command:

    harness connector --file kubernetes-connector.yml apply --delegate-name kubernetes-delegate

Environment

What are Harness environments?

Environments define the deployment location, categorized as Production or Pre-Production. Each environment includes infrastructure definitions for VMs, Kubernetes clusters, or other target infrastructures. To learn more about environments, go to Environments overview.

  1. Use the following CLI Command to create Environments in your Harness project:

    harness environment --file environment.yml apply
  2. In your new environment, add Infrastructure Definitions using the following CLI command:

    harness infrastructure --file infrastructure-definition.yml apply 

Services

What are Harness services?

In Harness, services represent what you deploy to environments. You use services to configure variables, manifests, and artifacts. The Services dashboard provides service statistics like deployment frequency and failure rate. To learn more about services, go to Services overview.

  1. Use the following CLI command to create Services in your Harness Project.

    harness service -file service.yml apply

Pick Your Deployment Strategy

What are Harness pipelines?

A pipeline is a comprehensive process encompassing integration, delivery, operations, testing, deployment, and monitoring. It can utilize CI for code building and testing, followed by CD for artifact deployment in production. A CD Pipeline is a series of stages where each stage deploys a service to an environment. To learn more about CD pipeline basics, go to CD pipeline basics.

What are Canary deployments?

A canary deployment updates nodes in a single environment gradually, allowing you to use gates between increments. Canary deployments allow incremental updates and ensure a controlled rollout process. For more information, go to When to use Canary deployments.

  1. CLI Command for canary deployment:

    harness pipeline --file canary-pipeline.yml apply

    You can switch to the Visual editor and confirm the pipeline stage and execution steps as shown below.

Execute the pipeline

Finally, it's time to execute your pipeline.

  1. Select Run, and then select Run Pipeline to initiate the deployment.

    • Observe the execution logs as Harness deploys the workload and checks for steady state.

    • After a successful execution, you can check the deployment on your Kubernetes cluster using the following command:

      kubectl get pods -n default
    • To access the Guestbook application deployed by the Harness pipeline, port forward the service and access it at http://localhost:8080

      kubectl port-forward svc/guestbook-ui 8080:80

Congratulations!🎉

You've just learned how to use Harness CD to deploy an application using a Kubernetes manifest.

What's Next?

  • Keep learning about Harness CD. For example, add Triggers to your pipeline that initiate pipeline deployments in response to Git events.
  • Visit the Harness Developer Hub for more tutorials and resources.

How to deploy your own app by using Harness

You can integrate your own microservice application into this tutorial by following the steps outlined below:

  • Utilize the same delegate that you deployed as part of this tutorial. Alternatively, deploy a new delegate, but remember to use a newly created delegate identifier when creating connectors.

  • If you intend to use a private Git repository that hosts your manifest files, create a Harness secret containing the Git personal access token (PAT). Subsequently, create a new Git connector using this secret.

  • Create a Kubernetes connector if you plan to deploy your applications in a new Kubernetes environment. Make sure to update the infrastructure definition to reference this newly created Kubernetes connector.

  • Once you complete all the aforementioned steps, create a new Harness service that leverages Kubernetes manifests for deploying applications.

  • Lastly, establish a new deployment pipeline and select the newly created infrastructure definition and service. Choose a deployment strategy that aligns with your microservice application's deployment needs.

  • Voila! You're now ready to deploy your own application by using Harness.