Skip to main content

Deploy using Kustomize

This tutorial helps you get started with Harness Continuous Delivery (CD). We will guide you through creating a CD pipeline and deployment of a Guestbook application. This Guestbook application will use Kustomize for deployment.

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

Complete the following tasks:

  1. Obtain a Harness API Token. For steps, go to the Harness documentation on creating a personal API token.
  2. Obtain a GitHub personal access token (PAT) with repo permissions. For steps, go to the GitHub documentation on creating a personal access token.
  3. Obtain a Kubernetes cluster. Use your own Kubernetes cluster. If you do not have one, we recommend that you use 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 the 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
  1. Clone the forked harnessed-example-apps repo and change the 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.

  2. Log in to Harness from the CLI.

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

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

caution

For the pipeline to run successfully, perform 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 by 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
      • Run the following command, replacing ACCOUNT_ID, MANAGER_ENDPOINT, and DELEGATE_TOKEN with the corresponding auto-populated values 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 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

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 management solution. To learn more about secrets in Harness, go to Secrets Management.

  1. Create a secret to store the GitHub PAT. This will be used in the next step to create a GitHub connector.

    harness secret  --token GITHUB_PAT apply 

    Note: Replace GITHUB_PAT with the GitHub PAT that you obtained during the prerequisite section of this tutorial.

Connectors

Connectors in Harness enable integration with third-party tools, providing connection and authentication at deployment runtime. For example, a GitHub connector facilitates authentication and fetching files from a GitHub repository within pipeline stages. To learn more about connectors, go to Connectors.

  1. Create a GitHub connector.

    harness connector --file kustomize-guestbook/harnesscd-pipeline/github-connector.yml apply --git-user GITHUB_ACCOUNTNAME
  2. Create a Kubernetes connector.

    harness connector --file kustomize-guestbook/harnesscd-pipeline/kubernetes-connector.yml apply --delegate-name helm-delegate

Environment

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

  1. Create a Environment.

    harness environment --file kustomize-guestbook/harnesscd-pipeline/environment.yml apply
  2. Create a Infrastructure Definition.

    harness infrastructure  --file kustomize-guestbook/harnesscd-pipeline/infrastructure-definition.yml apply

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. Create a Service.
    harness service --file kustomize-guestbook/harnesscd-pipeline/service.yml apply 

Pipeline

A pipeline is a comprehensive process encompassing integration, delivery, operations, testing, deployment, and monitoring. It can utilize CI for code building and testing and follow that up with 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.

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.

harness pipeline --file kustomize-guestbook/harnesscd-pipeline/canary-pipeline.yml apply
  • You can confirm the pipeline, stage, and execution steps are as shown below in the Harness UI.

Canary

  • Finally, it's time to execute the pipeline. 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 in your Kubernetes cluster using the following command:

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

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

Congratulations!🎉

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

What's Next?

  • Keep learning about Harness CD. Add triggers to your pipeline that'll respond to Git events by following this guide.
  • 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 Kustomize 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 Kustomize 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 using Harness.