Skip to main content

Deploy using Kustomize

Last updated on

This topic explains how to deploy a sample application (Guestbook) using Kustomize with Harness Continuous Delivery (CD).

Harness CD offers two ways to deploy the Guestbook application:

  • CD pipeline: You build a Harness pipeline that deploys the Kustomize manifests to your target cluster.
  • GitOps workflow: You install a Harness GitOps Agent, connect it to your Git repo and target cluster, and let Harness (using Argo CD) sync the desired state from Git into your cluster.
note

Sign up today to get started with Harness CD.


What will you learn in this topic?


Before you begin

Ensure you have the following:


Deploy the application

note

Harness resources such as delegates, secrets, and connectors can be created at the Account, Organization, or Project scope. For simplicity, this tutorial uses Project-scoped resources throughout. If you use resources from a different scope, update the configuration accordingly when you create connectors, environments, services, and the deployment pipeline.

Go to Organizations and projects to understand the Harness resource hierarchy and scopes.

You can deploy the Guestbook application using either a Harness CD pipeline or a Harness GitOps workflow.

Run the following command to check your system resources and optionally install a local cluster:

bash <(curl -fsSL https://raw.githubusercontent.com/harness-community/scripts/main/delegate-preflight-checks/cluster-preflight-checks.sh)

Deploy with a CD pipeline

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 development, test, staging, or production clusters, when running a variety of scans and tests to ensure the quality and stability standards you and your team have defined.

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

Perform the following steps to deploy the Guestbook application using the Harness CD Pipeline UI:

  1. Log in to Harness Manager.
  2. Select Projects, and then select Default Project.
  3. After selecting the project, configure the core resources Harness requires to run a deployment, including a delegate, a secret, two connectors, an environment, a service, and a deployment pipeline, as explained in the following sections.
warning

For the pipeline to run successfully, follow the remaining 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, and so on. The delegate is installed in the target infrastructure, for example, a Kubernetes cluster, and performs operations including deployment and integration. Go to Delegate Overview to understand the delegate.

Perform the following steps to set up a delegate:

  1. Under Project Setup, select Delegates.

  2. Select Tokens, and then create a delegate token:

    1. Select New Token.
    2. Enter the name delegate_token.
    3. Select Apply.
    4. Copy the token value by selecting the copy icon and store the token somewhere safe.
    5. Select Close.
  3. Select Delegates, and then select Install delegate. For this tutorial, install the delegate using Helm.

  4. Add the Harness Helm chart repo to your local Helm registry using the following command.

    helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
  5. Update the repo using the following command:

    helm repo update harness-delegate
  6. Copy and run the install command from the Delegate installation wizard as shown in the following example:

    Here, the ACCOUNT_ID, MANAGER_ENDPOINT and DELEGATE_TOKEN are auto-populated values you will get from the wizard itself.

    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
  7. Select Verify to verify that the delegate is installed successfully and can connect to the Harness Manager.

note

You can also follow the Install Harness Delegate on Kubernetes or Docker steps to install the delegate using the Terraform Helm Provider or a 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 manager. Go to Harness Secret Manager Overview to understand secrets in Harness.

Perform the following steps to add a secret:

  1. Under Project Setup, select Secrets.
  2. Select New Secret, and then select Text.
  3. Enter the secret name harness_gitpat.
  4. For the Secret Value, paste the GitHub personal access token you saved earlier.
  5. Select Save.

Connectors

Connectors in Harness enable integration with third 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. Go to Connectors to explore connector how-tos.

Set up the GitHub connector

Perform the following steps to set up a GitHub connector:

  1. Under Project Setup, select Connectors.
  2. Select Create via YAML Builder and copy the contents of github-connector.yml into the YAML editor.
  3. Replace GITHUB_USERNAME with your GitHub account username in the YAML (assuming you have already forked the harnesscd-example-apps repo as noted in Before you begin).
  4. Select Save Changes and verify that the new connector named harness_gitconnector is successfully created.
  5. Select Test under Connectivity Status to ensure the connection is successful.

Set up the Kubernetes connector

Perform the following steps to set up a Kubernetes connector:

  1. Under Project Setup, select Connectors.
  2. Select Create via YAML Builder and copy the contents of kubernetes-connector.yml into the YAML editor.
  3. Replace DELEGATE_NAME with the installed delegate name. To obtain the delegate name, navigate to Default Project > Project Setup > Delegates.
  4. Select Save Changes and verify that the new connector named harness_k8sconnector is successfully created.
  5. Select Test under Connectivity Status to verify the connection is successful.

Environment

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

Perform the following steps to set up an environment:

  1. In Default Project, select Environments.
  2. Select New Environment and toggle to YAML to use the YAML editor.
  3. Copy the contents of environment.yml, paste it into the YAML editor, and then select Save.
  4. In the Infrastructure Definitions tab, select Infrastructure Definition, and then select Edit YAML.
  5. Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
  6. Select Save and verify that the environment and infrastructure definition are created successfully.

Services

In Harness, services represent what you deploy to an environment. You use services to configure variables, manifests, and artifacts. The Services dashboard provides service statistics such as deployment frequency and failure rate. Go to Services overview to understand services.

Perform the following steps to set up a service:

  1. In Default Project, select Services.
  2. Select New Service, enter the name harnessguestbook, and then select Save.
  3. On the Configuration tab, toggle to YAML to use the YAML editor.
  4. Select Edit YAML, copy the contents of service.yml, and paste it into the YAML editor.
  5. 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 use 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. Go to CD pipeline basics to understand CD pipelines.

Pick a deployment strategy from the following:

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. Go to When to use Canary deployments to understand when to use them.

Perform the following steps to set up a pipeline with canary deployment:

  1. In Default Project, select Pipelines.
  2. Select New Pipeline.
  3. Enter the name guestbook_canary_pipeline.
  4. Select Inline to store the pipeline in Harness.
  5. Select Start and, in the Pipeline Studio, toggle to YAML to use the YAML editor.
  6. Select Edit YAML to enable edit mode, copy the contents of canary-pipeline.yml, and paste it into the YAML editor.
  7. Select Save.

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

Canary

Run the pipeline

Perform the following steps to execute the pipeline:

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

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

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

    kubectl get pods -n default
  4. 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

Deploy your own application

You can use your own microservice application with this tutorial by following the steps below:

  • Use 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. Ensure 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 uses Kustomize for deploying applications.

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


Next steps

You have deployed the Guestbook application with Harness CD and GitOps using Kustomize.

Continue your learning journey with the following: