Skip to main content

Physical Data Center

This tutorial helps you get started with Harness Continuous Delivery (CD). We will guide you through creating a CD pipeline with deployment type Secure Shell (SSH) that manages remote linux servers.

Before you begin

Verify that you have the following:

Getting Started with Harness CD


  1. Log in to Harness.

  2. Select Projects, and then select Default Project.

caution

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

Set up the Harness Delegate

What is the Harness 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 artifacts registries, cloud platforms, etc. The delegate is installed in the target infrastructure, for example, a Kubernetes cluster, and performs operations including deployment and integration. Learn more about the delegate in the Delegate Overview.

  1. In Project Setup, select Delegates.

    1. Select Delegates.

      1. Select Install delegate. For this tutorial, let's explore how to install the Docker delegate.

      2. In the command provided, ACCOUNT_ID, MANAGER_ENDPOINT and DELEGATE_TOKEN are auto-populated values that you can obtain from the delegate installation wizard.

        docker run --cpus=1 --memory=2g \
        -e DELEGATE_NAME=docker-delegate \
        -e NEXT_GEN="true" \
        -e DELEGATE_TYPE="DOCKER" \
        -e ACCOUNT_ID=ACCOUNT_ID \
        -e DELEGATE_TOKEN=DELEGATE_TOKEN \
        -e LOG_STREAMING_SERVICE_URL=https://app.harness.io/gratis/log-service/ \
        -e MANAGER_HOST_AND_PORT=MANAGER_ENDPOINT harness/delegate:23.05.79310
    2. 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 tutorial to install the Kubernetes Delegate using the Helm, Terraform Helm Provider or Kubernetes manifest.

Set up a Harness secret for your SSH private key

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. In Project Setup, select Secrets.
  2. Select New Secret > SSH Credential.
  3. Enter the secret name harness_sshprivatekey and click Continue.
  4. With SSH Key as the Auth Scheme, select Username/SSH Key as the Authentication method.
  5. Enter the username for the user account on the remote server in the Username field. For example: ubuntu
  6. Next, select Create or Select a Secret and click New Secret File.
  7. Enter the Secret Name ssh-private-key and click Browse to upload the SSH Private Key to Harness Secret Manager.
  8. Click Save and if needed modify the SSH port number.
  9. Finally, click Save and Continue.

Set up Harness connectors to your physical data center and Artifactory repository

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.

Create a Physical Data Center connector

  1. Copy the contents of pdc-connector.yml.
  2. In Harness, in Project Setup, select Connectors.
  3. Select Create via YAML Builder and paste the copied YAML.
  4. In the YAML, replace HOST_IP_OR_FQDN with the Host IP/FQDN and DELEGATE_NAME with the installed delegate name. To obtain the delegate name, navigate to Default Project > Project Setup > Delegates.
  5. Select Save Changes and verify that the new connector named harness_pdc is successfully created.
  6. Finally, select Test under CONNECTIVITY STATUS to ensure the connection is successful.

Create a Artifactory connector

For this tutorial, we'll use an artifact for a ToDo List app, todolist.war, which is available in a public Harness Artifactory repo.

  1. Copy the contents of artifactory-connector.yml.
  2. In Harness, in Project Setup, select Connectors.
  3. Select Create via YAML Builder and paste the copied YAML.
  4. Select Save Changes and verify that the new connector named harness_artifactrepo is successfully created.
  5. Finally, select Test under CONNECTIVITY STATUS to ensure the connection is successful.

Set up the Harness 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. 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 and paste it into the YAML editor and select Save.
  4. In Infrastructure Definitions, select Infrastructure Definition and 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 is created successfully.

Set up the Harness service

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

Set up the pipeline

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.

  1. In Default Project, select Pipelines.
  2. Select New Pipeline.
  3. Enter the name harness_ssh_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, and choose any of the following execution strategies. Paste the respective YAML based on your selection.
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. Copy the contents of pipeline-ssh-canary.yml and paste it into the YAML editor.
  2. Select Save.
  3. You can switch to the Visual editor and confirm the pipeline, stage, and execution steps are as shown below.

Canary

Finally, it's time to execute the pipeline.

  1. Select Run, and then select Run Pipeline to initiate the deployment.
  2. Observe the execution logs as Harness copies the artifact from source to the remote server.
  3. After a successful execution, you can check the artifact in your remote server using the following command:
ls -l ~/harness_ssh/harnessdevenv/todolist.war

Congratulations!🎉

You've just learned how to use Harness CD to copy an artifact to your remote servers via SSH.

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.