Skip to main content
In this guide, you’ll learn how to automate token replacement in your Kubernetes manifests using GitHub Actions. We will cover:
  • Defining repository-level variables for namespace, replicas, and image
  • Installing and configuring the cschleiden/replace-tokens@v1 action
  • Dynamically fetching the Ingress controller’s external IP
  • Applying placeholder replacement in kubernetes/development/*.yaml
  • Verifying the transformed manifests before deployment

Placeholder tokens in your manifests

Under kubernetes/development/, manifests contain tokens like {_NAMESPACE_}, {_REPLICAS_}, {_IMAGE_}, and {_INGRESS_IP_}:
All tokens must be replaced before applying these files to the cluster.

1. Define repository variables

Navigate to Settings > Secrets and variables > Actions in your GitHub repository. Here you can add both non-secret variables and secrets.
The image shows a GitHub repository settings page focused on "Secrets and variables," displaying environment and repository secrets like DOCKERHUB_PASSWORD, KUBECONFIG, and MONGO_PASSWORD.
Use Variables for non-sensitive configuration (e.g., NAMESPACE, REPLICAS) and Secrets for credentials (KUBECONFIG, DOCKERHUB_PASSWORD).
Add the following repository variables:
The image shows a GitHub settings page where a new action variable is being added, with "NAMESPACE" as the name and "develop" as the value.
Once added, your list should look like this:
The image shows a GitHub repository settings page, specifically the "Secrets and variables" section under "Actions," displaying environment and repository variables.
Ensure you also have DOCKERHUB_USERNAME defined for constructing the container image reference:
The image shows a GitHub repository settings page, specifically the "Secrets and variables" section under "Actions," displaying a list of repository variables such as DOCKERHUB_USERNAME and MONGO_USERNAME.

2. Choose a token-replacement action

From the GitHub Marketplace, install cschleiden/replace-tokens@v1. This action will scan files and replace tokens based on your specified prefix and suffix.
The image shows a GitHub Marketplace search results page for "replace tokens" actions, listing various tools for automating token replacement in files.
Example configuration:

3. Fetch the Ingress IP dynamically

Hard-coding the external IP limits flexibility. Instead, retrieve it at runtime using kubectl and store it in GITHUB_ENV:
In your workflow, you’ll capture this value:

4. Complete GitHub Actions workflow

Below is a full example workflow that ties everything together:

5. Outcome

After the workflow completes:
  • namespace will be set to development
  • replicas updated to 2
  • image resolved as <your-dockerhub-username>/solar-system:<commit-sha>
  • Ingress host entries generated with the actual load balancer IP
This pattern can be replicated for other environments (e.g., kubernetes/production/) by adjusting repository variables and glob patterns in the workflow.

Watch Video