Create Kubernetes Namespaces with Workflow Variables

Updated 1 month ago by Michael Cretzman

Namespaces for your Kubernetes deployments are typically set up in the Harness Service and Infrastructure Definition. In some cases, you might want to provide the namespace only at the time of deployment.

You can pass in a Kubernetes namespace as part of a Workflow deployment by using a Workflow variable in the Infrastructure Definition Namespace setting.

A value for the namespace Workflow variable can be provided manually or in response to an event using a Trigger.

In this topic:

Before You Begin

Step 1: Create the Workflow Variable

  1. Create a Workflow variable. For steps on create a Workflow variable, see Workflows.

For example, we'll name the variable namespace. and give it three allowed values: qa,stage,prod.

Each time the Workflow is deployed, you manually enter a value for the Workflow namespace variable or use a Trigger to pass in a value, and the ${workflow.variables.namespace} variable is replaced with a different namespace.

This can happen simultaneously because a different namespace is used each time. You can even update the variable as part of the Pipeline Stage that executes the Workflow.

Step 2: Use the Variable in the Infrastructure Definition

  1. In the Infrastructure Definition used by the Workflow, reference the variable in the Namespace setting.

To reference the variable we created, we use the expression ${workflow.variables.namespace}:

Option 1: Enter a Namespace Manually

  1. In your Workflow, click Deploy.
  2. For namespace, select one of the variable's allowed values.

  1. Click Submit. The Workflow deploys to the namespace you selected.

Option 2: Enter a Namespace with a Trigger

  1. Create a Trigger for the Workflow.
  2. In the Actions section, select the Workflow with the namespace variable. The namespace variable appears.

  1. For namespace, select one of the variable's allowed values.
    If your Workflow variable is not limited to allowed values, you can enter custom values. For more information, see Passing Variables into Workflows and Pipelines from Triggers.
  2. Click Submit. When the Trigger condition is met, the Workflow deploys to the namespace you selected.

Example: Trigger Parallel Workflow Executions

Typically, when a Workflow is triggered multiple times in succession, deploying on the same Infrastructure Definition, the deployment executions are queued automatically. Queuing prevents deployment collision.

Using the steps in this topic, you can have parallel executions for same Workflow on the same Infrastructure Definition by using Workflow variables to identify separate namespaces.

Next Steps


How did we do?