> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/troubleshooting-and-resources/resources/new-user/pipeline-execution-walkthrough.md).

# 5. Deployment Pipeline Execution Walkthrough

Learn how a deployment pipeline execution uses Harness entities and settings

This topic explains how a Continuous Delivery (CD) pipeline execution uses Harness entities and settings at runtime. It walks through a Kubernetes rolling deployment example so you can see the order in which Harness evaluates the service, environment, infrastructure definition, and execution steps.

***

## What you will learn from this topic

* How to follow [pipeline entity evaluation](#pipeline-example) for a Kubernetes rolling deployment
* How Harness evaluates the [service](#service) (manifests, artifacts, config files, and variables) at runtime
* How the [environment and infrastructure definition](#environment-and-infrastructure-definition) select the target cluster and apply overrides
* How the [Kubernetes Rollout Deployment](#kubernetes-rollout-deployment-step) and [Kubernetes Delete](#kubernetes-delete-step) steps assign delegate tasks
* How to continue with [CD tutorials](/continuous-delivery/troubleshooting-and-resources/tutorials/cd-gitops-tutorials.md) after you understand execution order

***

## Before you begin

This topic assumes the following knowledge:

* **CD modeling basics:** Familiarity with services, environments, and Deploy stages. Go to [Create services](/continuous-delivery/use-continuous-delivery/cd-building-blocks/services/create-services.md) and [Create environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environments.md) for setup guidance.
* **Delegates:** A Harness Delegate that can reach your Git provider and target Kubernetes cluster. Go to [Delegate overview](https://developer.harness.io/docs/platform/delegates/delegate/delegate-concepts/delegate-overview) for delegate concepts.

***

## Pipeline example

The following example uses a Kubernetes rolling deployment.

The pipeline consists of:

* A Harness CD Deploy stage
* A Harness service, environment, and infrastructure definition
* A rolling deployment strategy that uses execution steps to deploy to an existing Kubernetes cluster
* A final cleanup step to delete the Kubernetes deployment at the end of the pipeline

![Kubernetes rolling deployment pipeline overview](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-0b7ae90ba33876e3381c0c9b9f7f5cfe9573c00d%2F0c8d610885c229a7d1802482ded35c47693dcdc1f025341577999349964c8cc6.png?alt=media)

<details>

<summary>YAML example</summary>

```yaml
pipeline:
  name: Golden PM Signoff Pipeline
  identifier: Golden_PM_Signoff_Pipeline
  projectIdentifier: PM_Signoff
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: deployKubernetes
        identifier: Deploy_Kubernetes
        description: ""
        type: Deployment
        spec:
          deploymentType: Kubernetes
          service:
            serviceRef: als
            serviceInputs:
              serviceDefinition:
                type: Kubernetes
                spec:
                  artifacts:
                    primary:
                      primaryArtifactRef: <+input>
                      sources: <+input>
          execution:
            steps:
              - step:
                  name: Rollout Deployment
                  identifier: rolloutDeployment
                  type: K8sRollingDeploy
                  timeout: 10m
                  spec:
                    skipDryRun: false
                    pruningEnabled: false
                  when:
                    stageStatus: Success
              - step:
                  type: K8sDelete
                  name: Cleanup Suite
                  identifier: Cleanup_Suite
                  spec:
                    deleteResources:
                      type: ReleaseName
                      spec:
                        deleteNamespace: false
                  timeout: 10m
            rollbackSteps:
              - step:
                  name: Rollback Rollout Deployment
                  identifier: rollbackRolloutDeployment
                  type: K8sRollingRollback
                  timeout: 10m
                  spec:
                    pruningEnabled: false
          environment:
            environmentRef: k8sdev
            deployToAll: false
            infrastructureDefinitions: <+input>
        tags: {}
        failureStrategies:
          - onFailure:
              errors:
                - PolicyEvaluationFailure
              action:
                type: MarkAsSuccess
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback
        when:
          pipelineStatus: Success
    - stage:
        name: Deploy
        identifier: Deploy
        description: ""
        type: Deployment
        spec:
          deploymentType: Kubernetes
          service:
            serviceRef: als
            serviceInputs:
              serviceDefinition:
                type: Kubernetes
                spec:
                  artifacts:
                    primary:
                      primaryArtifactRef: <+input>
                      sources: <+input>
          environment:
            environmentRef: k8sdev
            deployToAll: false
            infrastructureDefinitions:
              - identifier: devrancher1
                inputs:
                  identifier: devrancher1
                  type: KubernetesRancher
                  spec:
                    connectorRef: <+input>
                    cluster: <+input>
                    namespace: <+input>
          execution:
            steps:
              - step:
                  name: Rollout Deployment
                  identifier: rolloutDeployment
                  type: K8sRollingDeploy
                  timeout: 10m
                  spec:
                    skipDryRun: false
                    pruningEnabled: false
            rollbackSteps:
              - step:
                  name: Rollback Rollout Deployment
                  identifier: rollbackRolloutDeployment
                  type: K8sRollingRollback
                  timeout: 10m
                  spec:
                    pruningEnabled: false
        tags: {}
        failureStrategies:
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback
  allowStageExecutions: true
```

</details>

***

## Walkthrough of the execution

The sections below follow the order Harness evaluates entities during a Deploy stage run.

### Service

The first entity evaluated during pipeline execution is the Harness service. A Harness service represents the microservice or application you want to deploy.

![Service selection in the Deploy stage](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-0b7ae90ba33876e3381c0c9b9f7f5cfe9573c00d%2F0c8d610885c229a7d1802482ded35c47693dcdc1f025341577999349964c8cc6.png?alt=media)

A Harness service is made up of the following entities.

**Manifest definition**

The manifest definition is used to fetch files from the Harness File Store or a remote source such as GitHub, GitLab, or Bitbucket.

When the stage **Rollout Deployment** step runs, a Harness Delegate fetches the manifests for deployment.

In this example, Harness uses a Harness Bitbucket connector to fetch the manifest.

![Bitbucket connector used to fetch the Kubernetes manifest](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c1ab2f1379d5d6e3c61c46d730d79c11f4f5ba8e%2F77e84ac51371ea84e703528c89ea1ce75dc2d3e13a634a3a0e7ed350d0d95562.png?alt=media)

Manifest fetch process:

![Manifest fetch process during service evaluation](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5f3abbf9cc341f5de78956b2845e71d2727a1f4f%2F3c43b3302b31c37f0c91e826d42f7e86bcfa17f3aff68f35831eaf5a48887b19.png?alt=media)

**Artifact configuration (optional)**

You can add an artifact to the service and use the artifact expression `image: <+artifacts.primary.image>` in your `values.yaml` file to fetch the image tag information and pass it into the manifest.

![Optional artifact configuration on the service](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-6481a784affb7616ebf1ee16bc897fd654b72798%2Fadf1528b6db53170e2bef7b8e96dd55e4e3fe256f9895ce9952b81ab337c9518.png?alt=media)

Artifact resolution process:

![Artifact resolution process during service evaluation](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-19b9e1f9bc88c6dc1b4fee97b68710f9259604ba%2F01248f98e478bb7d27549135fe3ca7b60a7eeae30b7c832ef62e7ff3846764a4.png?alt=media)

**Configuration files (optional)**

The service configuration files are fetched during the service evaluation and stored on the Delegate.

Harness can fetch JSON, Python script, XML, and similar files, and then use these files during deployment.

![Optional configuration files on the service](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-540d4230a9ef9c52ba78856e7b41d3d603136b75%2F9ea6e614fb430935b293312a635e6365de5c5110f54247313e56e6e42e744fff.png?alt=media)

Configuration file fetch process:

![Configuration file fetch process during service evaluation](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-de8c2612375e409f5e4168c2440e52921f02389a%2F896f6ecff8cc8c8889043fbb5656484b607be65b12e56800119035482f881024.png?alt=media)

**Variables (optional)**

You can configure variables in a service and reference them in the service `values.yaml` file or in pipeline execution steps.

![Optional service variables](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-9371ba30812cbf9bc29e548ab43422b1793ba052%2F19bb0370626e37fbbe4661ab091561a6cc3273d1cb6f02c5b584b7dd2a2f160f.png?alt=media)

You can also override service variables in the environment configured in the stage, as explained in the next section.

### Environment and infrastructure definition

The next entities evaluated during pipeline execution are the stage environment and infrastructure definition.

![Environment and infrastructure definition on the Deploy stage](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c421c6d6e963917dad114b65f148bcdfdaa6fbc1%2Fb052e20f319cb8d113b8cdf8001832eb7629f1002568d5d5595aeb426467c774.png?alt=media)

A Harness environment defines **where** the service will be deployed in terms of Production and Pre-Production environments. Within an environment, you can have multiple infrastructure definitions, and you select the one to use for each pipeline stage.

Each infrastructure definition defines the specific infrastructure where the pipeline will deploy, for example a cloud platform or Kubernetes cluster.

The infrastructure definition for Kubernetes (including Helm and Kustomize) and Native Helm also contains a **Release Name**. The release name is used to track the deployed service and to sync instances so you know how many pods are deployed on a cluster.

An infrastructure definition uses a specific Harness connector, such as Kubernetes Cluster or Physical Data Center, to connect to the target infrastructure for deployment at pipeline execution.

Infrastructure connection process:

![Infrastructure definition connection process](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-29ae867b18c543448cca957b75e62a1843344f7b%2F796208cc2b0cda81beb45f88163ede6debc5cdcc109b6f212f49b1f47ca5f9c5.png?alt=media)

**Overrides (optional)**

When a service that uses variables is added to a pipeline stage, you can override the variables using the environment in that stage.

You can set service variable overrides at the environment level. At runtime, Harness overrides the corresponding service variables and computes the values according to the environment variables.

Overrides let you specify different service variable values for different environments (development, QA, and so on). Go to [Overrides](/continuous-delivery/use-continuous-delivery/cd-building-blocks/overrides-v2.md) to configure overrides.

### Kubernetes Rollout Deployment step

The next entities evaluated during pipeline execution are the stage execution steps.

In this example, a **Rollout Deployment** step deploys the service to the environment.

![Rollout Deployment step in the execution](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-783ab748097f4510a08111daffd898954057fc6b%2Fffac7e13dca40a4c238eb1bb1b2762654e05b190093f10b354f80178a8d5225d.png?alt=media)

When the **Rollout Deployment** step runs, the Delegate eligible to perform the Kubernetes Rollout Deployment step is assigned the task. Harness evaluates Delegates in a round-robin style.

The **Rollout Deployment** step is made up of two tasks that Harness provides out of the box:

1. Fetch files task.

   1. The fetch files task uses the Git connector configured in the service to fetch the manifests.
   2. Harness also renders and resolves any of the Harness variables defined in the service `values.yaml` file and adds them to the manifest or Helm chart using Go or Helm templating.
   3. Harness fetches any secrets referenced in the `values.yaml` file and resolves them in the manifest. Harness masks secret output in its logs.

   Example deployment log for the fetch files task:

   ![Fetch files task log in Rollout Deployment](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-f87754bd861bc72c60a2011f3f563d6018af6535%2Fa28e8959ecb23d7ce24125f04126a5f3dc880d4856539f2c0a73337bc0781509.png?alt=media)
2. Rollout deployment task.

   1. The Kubernetes rollout deployment task uses the infrastructure definition and Harness Kubernetes Cluster connector to authenticate and deploy into the target cluster.
   2. The task uses the `kubectl apply` and `describe` commands to check for steady state.

   Example deployment log for the rollout task:

   ![Rollout deployment task log](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-26c9971a3aff237a8d7c4303311722bf388a0a18%2Fcd7de6d61e060c5f9171063bc9958c402c48e5616cc824d8cfeafd759b31dece.png?alt=media)

Delegate selection process:

![Delegate selection for the Rollout Deployment step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-22a79f5b7f868a8898febb4b1af5b116b2eb3e35%2Fb295504b69a4921aa5dff2fa709df9b2fb2e289992103b24858ae90b175b2e8c.png?alt=media)

Deployment process:

![Kubernetes rollout deployment process](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-05ada261a5d4bf9944c1495160cadd94064d6de5%2Fddb79c3787d1c5e83e6f241761b699d006bddb6679be8f5ee7880e358a258986.png?alt=media)

### Kubernetes Delete step

During execution of the Kubernetes Delete step, Harness selects the Delegate that has access to the infrastructure definition connector and performs the Kubernetes delete step within that cluster.

Harness attempts to delete the resources specified in the step according to the Delegate RBAC configured on the cluster.

![Kubernetes Delete step in the execution](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-305e1215e3c27b09d1738824310a0c5d2fcc157a%2F55eefd44ef75d9e1022e29b2aec219df6859062b3b4297aefb651d3da0c0ac32.png?alt=media)

Delete process:

![Kubernetes Delete step process](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-24bb322d3a24748b4078544ab2c439ba05a93577%2F8e5058eff9a68513461e2f0b9982e966d99d6bc7fb49d5b73c94e736d12770aa.png?alt=media)

***

## Next steps

* [CD and GitOps tutorials](/continuous-delivery/troubleshooting-and-resources/tutorials/cd-gitops-tutorials.md): Practice deployments after you understand execution order.
* [Create services](/continuous-delivery/use-continuous-delivery/cd-building-blocks/services/create-services.md): Configure manifests, artifacts, and variables used at runtime.
* [Create environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environments.md): Define where the service deploys and attach infrastructure definitions.
* [Overrides](/continuous-delivery/use-continuous-delivery/cd-building-blocks/overrides-v2.md): Override service values per environment without duplicating pipelines.

{% @harness-feedback/feedback %}
