Harness CLI Examples
In this section, we'll walk through an example to show how you can use the Harness CLI utility tool. We'll set up a pipeline and all the things it needs to deploy a sample guestbook application to your Kubernetes environment.
Let's Begin
Refer Install and Configure Harness CLI doc to setup and configure Harness CLI.
Fork the harnessed-example-apps repository through the GitHub web interface.
Clone the Forked harnessed-example-apps repo and change directory.
git clone https://github.com/GITHUB_ACCOUNTNAME/harnesscd-example-apps.git
cd harnesscd-example-appsnoteReplace
GITHUB_ACCOUNTNAME
with your GitHub Account name.Make sure you have a delegate configured and running smoothly. If not, you can also refer to the Install Harness Delegate on Kubernetes or Docker guide for steps on setting up the delegate using Helm, Terraform Helm Provider, or Kubernetes manifest.
Now, let's create all the resources that is required to execute a pipeline successfully. Let's start with creating a Harness Secret to store GitHub PAT.
- Obtain GitHub personal access token with repo permissions. For steps, go to the GitHub documentation on creating a personal access token.
- Create a Harness Secret to store GitHub PAT. This will be used in the next step to create GitHub connector.
harness secret --token GITHUB_PAT apply
Note: Replace
GITHUB_PAT
with GitHub PAT that you obtained in the previous step.
Create a GitHub connector.
harness connector --file guestbook/harnesscd-pipeline/github-connector.yml apply --git-user GITHUB_ACCOUNTNAME
Note: Replace
GITHUB_ACCOUNTNAME
with your GitHub Account Name.Create a Kubernetes connector.
harness connector --file guestbook/harnesscd-pipeline/kubernetes-connector.yml apply --delegate-name DELEGATE_NAME
Note: Replace
DELEGATE_NAME
with the Delegate name.Create a Environment.
harness environment --file guestbook/harnesscd-pipeline/environment.yml apply
Create a Infrastructure Definition.
harness infrastructure --file guestbook/harnesscd-pipeline/infrastructure-definition.yml apply
Create a Service.
harness service --file guestbook/harnesscd-pipeline/service.yml apply
Now, let's create a Pipeline of deployement type Canary with just a single command.
harness pipeline --file guestbook/harnesscd-pipeline/canary-pipeline.yml apply
Finally, it's time to execute the pipeline. Traverse through
Harness UI
>Default Project
>Pipelines
> Clickguestbook_canary_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 successfully used
harness
CLI utility tool to create and execute a pipeline.