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.

Before you begin

Verify the following:

  1. Obtain GitHub personal access token with repo permissions. For steps, go to the GitHub documentation on creating a personal access token.
  2. 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.
  3. Install Helm CLI.
  4. 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. Log into Harness.

  2. Select Projects, and then select Default Project.

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. In Project Setup, select Delegates.

    • Select Tokens.

      • Select New Token.
      • Enter the named delegate_token.
      • Select Apply.
      • Copy the token value by selecting the copy icon and store the token somewhere.
      • Select Close.
    • 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 and MANAGER_ENDPOINT are auto-populated values that you can obtain from the delegate Installation wizard. You simply need to replace DELEGATE_TOKEN in the command with the token that was copied earlier and proceed with installing the delegate.

        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

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. In Project Setup, select Secrets.
    • Select New Secret > Text.
    • Enter the secret name harness_gitpat.
    • For the secret value, paste in the GitHub Personal Access Token.
    • Select Save.

Connectors

Connectors in Harness enable integration with 3rd 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.

    • Copy the contents of github-connector.yml.
    • In Harness, in Project Setup, select Connectors.
    • Select Create via YAML Builder and paste the copied YAML.
    • Assuming you have already forked the harnessed-example-apps repository as mentioned earlier, replace GITHUB_USERNAME with your GitHub account username in the YAML wherever required.
    • Select Save Changes and verify that the new connector named harness_gitconnector is successfully created.
    • Finally, select Test under CONNECTIVITY STATUS to ensure the connection is successful.
  2. Create Kubernetes connector.

    • Copy the contents of kubernetes-connector.yml.
    • In Harness, in Project Setup, select Connectors.
    • Select Create via YAML Builder and paste in the copied YAML.
    • In the YAML, replace DELEGATE_NAME with the installed delegate name. To obtain the delegate name, navigate to Default Project > Project Setup > Delegates.
    • Select Save Changes and verify that the new connector named harness_k8sconnector is successfully created.
    • Finally, select Test under CONNECTIVITY STATUS to verify the connection is successful.

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. In Default Project, select Environments.
    • Select New Environment and toggle to YAML to use the YAML editor.
    • Copy the contents of environment.yml and paste it into the YAML editor and select Save.
    • In Infrastructure Definitions, select Infrastructure Definition and select Edit YAML.
    • Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
    • Select Save and verify that the environment and infrastructure definition is created successfully.

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. In Default Project, select Services.
    • Select New Service.
    • Name the service harnessguestbook.
    • Select Save, and then in the Configuration tab, toggle to YAML to use the YAML editor.
    • Select Edit YAML and copy the contents of service.yml and paste it into the YAML editor.
    • Select Save and verify that the Service harness_guestbook is successfully created.

Pipeline

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.

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.

  • In Default Project, select Pipelines.

    • Select New Pipeline.
    • Enter the name guestbook_canary_pipeline.
    • Select Inline to store the pipeline in Harness.
    • Select Start and, in the Pipeline Studio, toggle to YAML to use the YAML editor.
    • Select Edit YAML to enable edit mode, and choose any of the following execution strategies. Paste the respective YAML based on your selection.
  • Copy the contents of canary-pipeline.yml and paste it into the YAML editor.

  • Select Save.

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

Canary

  1. 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.