Skip to content

Commit 4fb18b7

Browse files
authored
kargo with pko for change management (#16669)
* init blog post on kargo * finish draft 1 * add dashboard image * some edits * minor fixes
1 parent c54b219 commit 4fb18b7

File tree

5 files changed

+233
-0
lines changed

5 files changed

+233
-0
lines changed
82.3 KB
Loading
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
---
2+
title: "Change Management with the Pulumi Kubernetes Operator and Kargo"
3+
h1: "Change Management with the Pulumi Kubernetes Operator and Kargo"
4+
authors:
5+
- "elisabeth-lichtie"
6+
tags: ["kargo", "kubernetes", "pko", "change management", "gitops", "argocd", "verification"]
7+
meta_desc: "Use Kargo with the Pulumi Kubernetes Operator to control how infrastructure changes are promoted across environments."
8+
date: "2025-11-25"
9+
meta_image: "kargo-change-mgmt.png"
10+
allow_long_title: true
11+
summary: |
12+
The Pulumi Kubernetes Operator (PKO) manages Pulumi stacks as Kubernetes resources, while Kargo provides controlled promotion of changes across environments. Used together, they let you manage infrastructure as code with Pulumi while systematically testing and promoting changes through dev, staging, and production environments.
13+
---
14+
15+
The [Pulumi Kubernetes Operator (PKO)](https://www.pulumi.com/docs/iac/guides/continuous-delivery/pulumi-kubernetes-operator/) enables you to manage Pulumi stacks as Kubernetes resources, but it doesn't provide much guidance on change management. [Kargo](https://kargo.io/) fills this gap by providing controlled, staged promotions with verification steps. Together, they let you keep your infrastructure defined in Pulumi while managing multi-environment rollouts in a systematic way.
16+
17+
<!--more-->
18+
19+
## What you can do with Argo CD, PKO, and Kargo
20+
21+
When you combine these tools, you gain several change management capabilities:
22+
23+
- **Control release timing**: Determine when updates to your Pulumi program are released to different environments, rather than deploying everywhere at once.
24+
- **Visualize deployments**: See which environments are running which versions of your infrastructure code at a glance.
25+
- **Automatic verification**: Automatically verify deployment success before promoting changes to the next environment.
26+
- **Approval gates**: Set up discrete approval requirements before promotion, ensuring human review when needed.
27+
- **Change tracking**: Maintain a clear audit trail of what changed, when, and how it moved through your environments.
28+
29+
## About Kargo
30+
31+
Kargo is a [continuous promotion platform](https://docs.kargo.io/user-guide/core-concepts/) that manages how changes move through application lifecycle stages. While it's commonly used for application deployments, it also works for infrastructure code managed by PKO.
32+
33+
The key concepts you'll work with:
34+
35+
**Freight**: A packaged set of artifacts that move together through your pipeline. When integrating with PKO, this will typically be the pulumi program that defines your infrastructure and the git commit with the latest version.
36+
37+
**Stages**: Promotion targets that represent different lifecycle phases (like dev, staging, production). Each stage corresponds to a different PKO Stack resource managing that environment's infrastructure.
38+
39+
**Promotions**: The process of moving freight from one stage to the next. Kargo updates the Stack resources to point to the promoted freight.
40+
41+
**Warehouses**: Monitors that watch your Git repository for infrastructure code changes and package new commits or releases as freight.
42+
43+
**Projects**: Organizational units that group related stages and warehouses, mapping to Kubernetes namespaces for access control.
44+
45+
When Kargo promotes freight to a stage, it updates the corresponding PKO Stack resource with the new Git reference. PKO then reconciles the stack, and your infrastructure changes are applied.
46+
47+
## Example architecture
48+
49+
### Workflow
50+
51+
To demonstrate how these tools work together, let's look at an example setup that manages infrastructure code through a controlled promotion pipeline:
52+
53+
![PKO and Kargo Architecture](PKO_Kargo_Architecture.png)
54+
55+
This architecture includes six main components working together:
56+
57+
1. **[Security Scanner repository](https://github.com/lichtie/security-scanner)**: Contains your Pulumi infrastructure code. Kargo watches this repository for new commits or releases.
58+
1. **Kargo**: Controls the release pipeline. When it detects new code in the security scanner repository, it triggers an update to promote that code to the next stage.
59+
1. **[Kargo manifests repository](https://github.com/lichtie/kargo-manifests)**: Stores the Kubernetes manifests that define PKO Stack resources. Kargo updates this repository with the new Git references when promoting freight.
60+
1. **Argo CD**: Watches the Kargo manifests repository and creates or updates Stack objects in Kubernetes when it detects changes.
61+
1. **Pulumi Kubernetes Operator**: Watches Stack objects and deploys them to Pulumi, triggering stack updates or previews.
62+
1. **Pulumi**: Performs the actual infrastructure deployments and previews based on PKO's instructions.
63+
64+
The workflow follows this pattern: Kargo detects new infrastructure code, updates the manifests repository with the new Git reference, Argo CD syncs the Stack objects to Kubernetes, PKO triggers Pulumi to deploy the changes, and Kargo verifies the successful deployment. This creates a closed loop where infrastructure changes are systematically promoted and verified at each stage.
65+
66+
### Dashboard and Management
67+
68+
![Kargo Dashboard](kargo_dash.png)
69+
70+
The Kargo dashboard brings operational visibility to this entire workflow. The timeline view at the top shows every freight version moving through your pipeline, making it immediately clear which infrastructure code version is running in each environment and how long it has been there.
71+
72+
The flow diagram above maps out your complete promotion path with color-coded stages. You can see at a glance where changes are flowing smoothly and where they are waiting at approval gates or blocked by failed verifications.
73+
74+
Status indicators on each stage show real-time health information, eliminating the need to manually check multiple systems or run status commands. This single-pane view reduces context switching, speeds up troubleshooting when issues arise, and gives an understanding of exactly what infrastructure is deployed where.
75+
76+
{{% notes type="info" %}}
77+
You can see the complete setup for this example, including configuration files and manifests, in the [pulumi-operator-with-kargo-change-management](https://github.com/lichtie/pulumi-operator-with-kargo-change-management) repository.
78+
{{% /notes %}}
79+
80+
## Setting up the environment
81+
82+
The example repository contains three Pulumi projects that deploy in sequence:
83+
84+
1. **cluster**: Creates a basic Amazon EKS cluster where everything will run.
85+
1. **cluster-setup**: Installs the required dependencies including PKO, cert-manager, Argo CD, Argo Rollouts, and AWS Cognito for authentication.
86+
1. **kargo**: Deploys Kargo via Helm and provides examples to set up the project with stages, approval gates, and analysis templates for the promotion pipeline.
87+
88+
## Configuring Kargo
89+
90+
Once Kargo is installed, you need to configure several components to set up your promotion pipeline.
91+
92+
### Creating a project
93+
94+
Start by creating a [Kargo project](https://docs.kargo.io/user-guide/how-to-guides/working-with-projects), which automatically creates a corresponding Kubernetes namespace.
95+
96+
### Git credentials
97+
98+
Kargo needs access to your Git repositories to monitor for changes and update manifests. Create a secret with your Git credentials, labeled so Kargo recognizes it:
99+
100+
```yaml
101+
apiVersion: v1
102+
kind: Secret
103+
metadata:
104+
name: github-creds
105+
namespace: kargo-managed-stack
106+
labels:
107+
kargo.akuity.io/cred-type: git
108+
stringData:
109+
repoURL: https://github.com/YOUR_REPO
110+
username: YOUR_USERNAME
111+
password: GITHUB_TOKEN
112+
```
113+
114+
### Setting up approver roles
115+
116+
To control who can approve promotions at approval gates, you can [create custom roles](https://docs.kargo.io/user-guide/security/access-controls/) with the `promote` permission. This requires three resources: a ServiceAccount with OIDC claim mapping, a Role with promotion permissions, and a RoleBinding to connect them. The easiest way to set up these resources is through the Kargo UI.
117+
118+
![Kargo Approver Role Setup](kargo_approver_role_setup.png)
119+
120+
The screenshot shows a role configured with the `promote` verb on specific stages (like `approvalgateqa`), which allows users bound to this role to approve promotions at that gate. The role also includes permissions to create promotions and view other resources.
121+
122+
### Project configuration
123+
124+
Use a ProjectConfig resource to control [promotion policies](https://docs.kargo.io/user-guide/how-to-guides/working-with-projects#configuring-promotion-policies) for your project. This example enables automatic promotion for preview and deployment stages:
125+
126+
```yaml
127+
apiVersion: kargo.akuity.io/v1alpha1
128+
kind: ProjectConfig
129+
metadata:
130+
name: kargo-managed-stack
131+
namespace: kargo-managed-stack
132+
spec:
133+
promotionPolicies:
134+
- stageSelector:
135+
name: devpreview
136+
autoPromotionEnabled: true
137+
- stageSelector:
138+
name: dev2preview
139+
autoPromotionEnabled: true
140+
- stageSelector:
141+
name: dev
142+
autoPromotionEnabled: true
143+
- stageSelector:
144+
name: dev2
145+
autoPromotionEnabled: true
146+
- stageSelector:
147+
name: qapreview
148+
autoPromotionEnabled: true
149+
- stageSelector:
150+
name: qa
151+
autoPromotionEnabled: true
152+
```
153+
154+
This configuration automatically promotes freight through preview stages and dev environments, while approval gates remain manual.
155+
156+
### Pulumi access token
157+
158+
Kargo needs access to the Pulumi API to verify that infrastructure deployments completed successfully. Create a secret in your project through the Kargo UI:
159+
160+
1. Navigate to your project in the Kargo UI
161+
1. Navigate to **Settings** → **Credentials**
162+
1. Select **Create a new credential** with:
163+
- Name: `pulumi-api-token`
164+
- Type: `Opaque`
165+
- Key: `PULUMI_ACCESS_TOKEN`
166+
- Value: Your Pulumi access token
167+
168+
This token allows Kargo's analysis templates to query the Pulumi API and confirm that stack updates and previews ran successfully before promoting freight to the next stage.
169+
170+
## Defining stages
171+
172+
[Stages](https://docs.kargo.io/user-guide/core-concepts/#stages) represent different points in your promotion pipeline. This example uses three types of stages to control how infrastructure changes move from development to production.
173+
174+
### Preview stages
175+
176+
Preview stages run `pulumi preview` operations to show what changes would be applied without actually deploying them. These stages help catch issues early by validating that the infrastructure code is valid and showing the expected changes:
177+
178+
- **devpreview** and **dev2preview**: Run previews for the dev environments
179+
- **qapreview**: Runs a preview for QA after passing approval gates
180+
181+
Preview stages automatically promote to their corresponding update stages once the preview completes successfully and verification passes.
182+
183+
### Update stages
184+
185+
Update stages run `pulumi up` to actually deploy the infrastructure changes:
186+
187+
- **dev** and **dev2**: Deploy changes to parallel dev environments for testing
188+
- **qa**: Deploy to the QA environment after all approvals
189+
190+
Update stages are configured to automatically promote once the deployment succeeds and verification confirms the infrastructure is in the expected state.
191+
192+
### Approval gates
193+
194+
Approval gates are stages that require manual approval before freight can proceed. They act as checkpoints where designated approvers review changes before they move forward:
195+
196+
- **approvalgatedev**: Manual checkpoint before dev deployments
197+
- **approvalgateqa**: Functional review gate before QA deployment
198+
- **approvalgateqasec**: Security review gate before QA deployment
199+
200+
The QA preview stage uses `availabilityStrategy: All`, meaning freight must pass through both `approvalgateqa` and `approvalgateqasec` before proceeding. This ensures both functional and security teams approve changes before they reach QA.
201+
202+
### Custom approver roles
203+
204+
Different approval gates may require different approvers. Using the [custom roles](#setting-up-approver-roles) described earlier, you can grant specific users or groups the `promote` permission on individual approval gates. For example, security team members might have the `promote` permission on `approvalgateqasec`, while functional testers have it on `approvalgateqa`. This ensures the right people review changes at each checkpoint.
205+
206+
## Verification
207+
208+
After each stage completes, Kargo can verify that the operation succeeded before promoting to the next stage. This example uses [analysis templates](https://docs.kargo.io/user-guide/reference-docs/analysis-templates/) to query the Pulumi API and confirm deployments completed successfully.
209+
210+
{{% notes type="info" %}}
211+
Kargo uses Argo Rollouts for verification, so Argo Rollouts must be installed in your cluster.
212+
{{% /notes %}}
213+
214+
### Analysis templates
215+
216+
Analysis templates define how to verify a stage. They can make HTTP requests, run queries, or execute any checks you need. For Pulumi verification, the templates:
217+
218+
1. **Wait for operations to complete**: Include a delay to give Pulumi time to finish the preview or update operation
219+
1. **Query the Pulumi API**: Make HTTP requests to the Pulumi API to retrieve the stack's latest update information
220+
1. **Verify the commit ID**: Check that the deployed commit matches the freight being promoted
221+
1. **Confirm success**: Ensure the operation completed without errors
222+
223+
The analysis template uses the `PULUMI_ACCESS_TOKEN` [secret created earlier](#pulumi-access-token) to authenticate with the Pulumi API.
224+
225+
### Custom verification standards
226+
227+
Analysis templates are flexible enough to enforce other standards your organization requires as well.
228+
229+
This gives you a way to codify your deployment standards and ensure they're enforced automatically as infrastructure changes move through environments.
230+
231+
## Conclusion
232+
233+
Combining the Pulumi Kubernetes Operator with Kargo gives you systematic control over how infrastructure changes move through your environments. Rather than manually managing deployments or pushing changes directly to production, you get automated promotions with verification steps, approval gates where human review is needed, and a clear audit trail of what changed and when. This approach is particularly valuable for teams managing multiple environments where infrastructure changes need to be tested and approved before reaching production. By defining your promotion pipeline as code with stages, approval gates, and verification templates, you ensure that your infrastructure changes follow the same rigorous process every time.
93.4 KB
Loading
254 KB
Loading
361 KB
Loading

0 commit comments

Comments
 (0)