Mini Project: Promoting linkly
The project ties the course together: a GitOps repository that deploys the linkly chart from an OCI registry to staging and production, validates every environment in CI, promotes a new release from staging to production by commit, shows reviewers the rendered diff, and rolls back by revert. Argo CD picks the environments up through one ApplicationSet; a Flux version of the same setup follows.
The design
| Decision | Choice | Lesson |
|---|---|---|
| repositories | chart and image built in acme/linkly; desired state in acme/linkly-deploy |
Running Example |
| environments | folders apps/linkly/<env>/ on main, each with release.yaml (chart version, namespace) and values.yaml |
Repository Layouts |
| what is promoted | chartVersion and image.tag, nothing else |
Promotion |
| chart source | OCI registry, versioned, immutable | Helm & Kustomize Sources |
| Argo CD | one ApplicationSet (Git files generator) with chart + values as multiple sources, a locked-down AppProject | ApplicationSets, Projects |
| safety | render + kubeconform for every environment, a release-version policy for production, a rendered diff in each PR | Toolkit, Field Notes |
Step 1: publish two chart versions
In real life the app repo's CI publishes charts. Here the session pushes 0.3.0 (in production today) and 0.4.0 (adds a PodDisruptionBudget when there is more than one replica) to the local registry, then builds the deploy repo, validates both environments, and commits:
# --- app repo CI: publish the chart versions ---------------------------------
mkdir -p chart/templates
cat > chart/values.yaml <<'EOF'
replicaCount: 2
image: {repository: ghcr.io/acme/linkly, tag: ""}
logLevel: info
host: lnk.example.com
EOF
cat > chart/templates/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: {{ .Release.Name }}}
spec:
replicas: {{ .Values.replicaCount }}
selector: {matchLabels: {app.kubernetes.io/name: linkly}}
template:
metadata: {labels: {app.kubernetes.io/name: linkly}}
spec:
containers:
- name: linkly
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
env: [{name: LOG_LEVEL, value: {{ .Values.logLevel | quote }}}]
ports: [{name: http, containerPort: 8080}]
EOF
cat > chart/templates/service.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata: {name: {{ .Release.Name }}}
spec:
selector: {app.kubernetes.io/name: linkly}
ports: [{name: http, port: 80, targetPort: http}]
EOF
cat > chart/templates/httproute.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata: {name: {{ .Release.Name }}}
spec:
parentRefs: [{name: public, namespace: gateway-system}]
hostnames: [{{ .Values.host | quote }}]
rules: [{backendRefs: [{name: {{ .Release.Name }}, port: 80}]}]
EOF
publish() { # chart version, app version
printf 'apiVersion: v2\nname: linkly\nversion: %s\nappVersion: "%s"\n' "$1" "$2" > chart/Chart.yaml
helm package chart >/dev/null && helm push linkly-$1.tgz oci://localhost:5000/charts --plain-http 2>&1 | grep Pushed
}
publish 0.3.0 1.4.1
cat > chart/templates/pdb.yaml <<'EOF'
{{- if gt (int .Values.replicaCount) 1 }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: {name: {{ .Release.Name }}}
spec:
minAvailable: 1
selector: {matchLabels: {app.kubernetes.io/name: linkly}}
{{- end }}
EOF
publish 0.4.0 1.5.0
# --- the deploy repo ------------------------------------------------------------
git init -q linkly-deploy && cd linkly-deploy
mkdir -p apps/linkly/staging apps/linkly/production
printf 'chartVersion: 0.4.0\nnamespace: linkly-staging\n' > apps/linkly/staging/release.yaml
printf 'replicaCount: 1\nimage: {tag: 1.5.0}\nlogLevel: debug\nhost: lnk.staging.example.com\n' > apps/linkly/staging/values.yaml
printf 'chartVersion: 0.3.0\nnamespace: linkly-prod\n' > apps/linkly/production/release.yaml
printf 'replicaCount: 3\nimage: {tag: 1.4.1}\n' > apps/linkly/production/values.yaml
cat > render.sh <<'EOF'
#!/usr/bin/env bash
# render.sh ENV: what Argo CD would apply for that environment, rendered from the OCI chart
set -euo pipefail
dir=apps/linkly/$1
helm template linkly oci://localhost:5000/charts/linkly --plain-http \
--version "$(yq .chartVersion $dir/release.yaml)" -n "$(yq .namespace $dir/release.yaml)" \
-f $dir/values.yaml 2>/dev/null
EOF
cat > ci.sh <<'EOF'
#!/usr/bin/env bash
# CI for every pull request: render + validate every environment, enforce release versions in production.
set -uo pipefail
status=0
for dir in apps/linkly/*/; do
env=$(basename "$dir")
printf '%-11s chart %s, image %s: ' "$env" "$(yq .chartVersion $dir/release.yaml)" "$(yq .image.tag $dir/values.yaml)"
./render.sh "$env" | kubeconform -strict -summary - || status=1
done
tag=$(yq .image.tag apps/linkly/production/values.yaml)
[[ "$tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "production image tag '$tag' is not a release"; status=1; }
exit $status
EOF
chmod +x render.sh ci.sh
./ci.sh && git add . && git commit -qm "linkly-deploy: staging on chart 0.4.0, production on 0.3.0" && git log --onelinePushed: localhost:5000/charts/linkly:0.3.0
Pushed: localhost:5000/charts/linkly:0.4.0
production chart 0.3.0, image 1.4.1: Summary: 3 resources found parsing stdin - Valid: 3, Invalid: 0, Errors: 0, Skipped: 0
staging chart 0.4.0, image 1.5.0: Summary: 3 resources found parsing stdin - Valid: 3, Invalid: 0, Errors: 0, Skipped: 0
8022fce linkly-deploy: staging on chart 0.4.0, production on 0.3.0
Step 2: wire up Argo CD
One AppProject, one ApplicationSet. The Git files generator reads each release.yaml, so its keys (chartVersion, namespace) become template parameters, and {{.path.basename}} is the environment. The chart comes from the registry; the values from the same Git folder through a ref source:
mkdir -p argocd && cd argocd
cat > project.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata: {name: linkly, namespace: argocd}
spec:
sourceRepos: [https://github.com/acme/linkly-deploy.git, ghcr.io/acme/charts]
destinations: [{server: https://kubernetes.default.svc, namespace: linkly-*}]
clusterResourceWhitelist: []
roles:
- name: viewer
policies: ["p, proj:linkly:viewer, applications, get, linkly/*, allow"]
EOF
cat > applicationset.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata: {name: linkly, namespace: argocd}
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- git:
repoURL: https://github.com/acme/linkly-deploy.git
revision: main
files: [{path: apps/linkly/*/release.yaml}]
template:
metadata:
name: 'linkly-{{.path.basename}}'
labels: {env: '{{.path.basename}}'}
spec:
project: linkly
sources:
- repoURL: ghcr.io/acme/charts
chart: linkly
targetRevision: '{{.chartVersion}}'
helm:
releaseName: linkly
valueFiles: ['$values/{{.path.path}}/values.yaml']
- repoURL: https://github.com/acme/linkly-deploy.git
targetRevision: main
ref: values
destination: {server: https://kubernetes.default.svc, namespace: '{{.namespace}}'}
syncPolicy:
automated: {prune: true, selfHeal: true}
syncOptions: [CreateNamespace=true, ServerSideApply=true]
retry: {limit: 3, backoff: {duration: 10s, factor: 2, maxDuration: 2m}}
EOF
kubeconform -strict -summary .
cd .. && mkdir -p apps/linkly/staging apps/linkly/production
printf 'chartVersion: 0.4.0\nnamespace: linkly-staging\n' > apps/linkly/staging/release.yaml
printf 'chartVersion: 0.3.0\nnamespace: linkly-prod\n' > apps/linkly/production/release.yaml
echo "--- what the files generator produces from these files:"
for f in apps/linkly/*/release.yaml; do
env=$(basename "$(dirname "$f")")
echo "linkly-$env: chart $(yq .chartVersion "$f"), values \$values/$(dirname "$f")/values.yaml -> $(yq .namespace "$f")"
doneSummary: 2 resources found in 2 files - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0
--- what the files generator produces from these files:
linkly-production: chart 0.3.0, values $values/apps/linkly/production/values.yaml -> linkly-prod
linkly-staging: chart 0.4.0, values $values/apps/linkly/staging/values.yaml -> linkly-staging
Apply the two files once (or add them to an app of apps root), and Argo CD creates linkly-staging and linkly-production. A sample argocd app list afterwards:
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
argocd/linkly-production https://kubernetes.default.svc linkly-prod linkly Synced Healthy Auto-Prune <none> ghcr.io/acme/charts 0.3.0
argocd/linkly-staging https://kubernetes.default.svc linkly-staging linkly Synced Healthy Auto-Prune <none> ghcr.io/acme/charts 0.4.0Step 3: promote, review, roll back
Staging has run chart 0.4.0 with linkly 1.5.0 long enough. The promotion is a branch and a pull request that copies exactly the two promotable values. CI validates it and attaches the rendered diff, which is what reviewers approve. After the merge, the production Application goes OutOfSync and syncs; if it misbehaves, a revert restores the previous state. The session rebuilds step 1's state compactly (same charts, same repo), then runs the cycle:
mkdir -p chart/templates
printf 'replicaCount: 2\nimage: {repository: ghcr.io/acme/linkly, tag: ""}\n' > chart/values.yaml
cat > chart/templates/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata: {name: {{ .Release.Name }}}
spec:
replicas: {{ .Values.replicaCount }}
selector: {matchLabels: {app.kubernetes.io/name: linkly}}
template:
metadata: {labels: {app.kubernetes.io/name: linkly}}
spec:
containers: [{name: linkly, image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"}]
EOF
publish() {
printf 'apiVersion: v2\nname: linkly\nversion: %s\nappVersion: "%s"\n' "$1" "$2" > chart/Chart.yaml
helm package chart >/dev/null && helm push linkly-$1.tgz oci://localhost:5000/charts --plain-http >/dev/null 2>&1
}
publish 0.3.0 1.4.1
cat > chart/templates/pdb.yaml <<'EOF'
{{- if gt (int .Values.replicaCount) 1 }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: {name: {{ .Release.Name }}}
spec:
minAvailable: 1
selector: {matchLabels: {app.kubernetes.io/name: linkly}}
{{- end }}
EOF
publish 0.4.0 1.5.0
git init -q linkly-deploy && cd linkly-deploy
mkdir -p apps/linkly/staging apps/linkly/production
printf 'chartVersion: 0.4.0\nnamespace: linkly-staging\n' > apps/linkly/staging/release.yaml
printf 'replicaCount: 1\nimage: {tag: 1.5.0}\n' > apps/linkly/staging/values.yaml
printf 'chartVersion: 0.3.0\nnamespace: linkly-prod\n' > apps/linkly/production/release.yaml
printf 'replicaCount: 3\nimage: {tag: 1.4.1}\n' > apps/linkly/production/values.yaml
render() { d=apps/linkly/$1; helm template linkly oci://localhost:5000/charts/linkly --plain-http \
--version "$(yq .chartVersion $d/release.yaml)" -n "$(yq .namespace $d/release.yaml)" -f $d/values.yaml 2>/dev/null; }
git add . && git commit -qm "linkly-deploy: staging on chart 0.4.0, production on 0.3.0"
# --- the promotion pull request ---------------------------------------------------
git switch -q -c promote/linkly-1.5.0
render production > ../before.yaml
s=apps/linkly/staging p=apps/linkly/production
yq -i ".chartVersion = \"$(yq .chartVersion $s/release.yaml)\"" $p/release.yaml
yq -i ".image.tag = \"$(yq .image.tag $s/values.yaml)\"" $p/values.yaml
git commit -qam "production: promote linkly chart 0.4.0 / image 1.5.0 from staging"
git diff --stat main
echo "--- rendered diff for reviewers:"
render production > ../after.yaml
diff -u ../before.yaml ../after.yaml | grep -E '^[-+][^-+]'
render production | kubeconform -strict -summary -
# --- merge, then roll back ----------------------------------------------------------
git switch -q main && git merge -q --ff-only promote/linkly-1.5.0
git revert --no-edit HEAD >/dev/null
git log --oneline
echo "production after revert: chart $(yq .chartVersion apps/linkly/production/release.yaml), image $(yq .image.tag apps/linkly/production/values.yaml)" apps/linkly/production/release.yaml | 2 +-
apps/linkly/production/values.yaml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
--- rendered diff for reviewers:
+# Source: linkly/templates/pdb.yaml
+apiVersion: policy/v1
+kind: PodDisruptionBudget
+metadata: {name: linkly}
+spec:
+ minAvailable: 1
+ selector: {matchLabels: {app.kubernetes.io/name: linkly}}
- containers: [{name: linkly, image: "ghcr.io/acme/linkly:1.4.1"}]
+ containers: [{name: linkly, image: "ghcr.io/acme/linkly:1.5.0"}]
Summary: 2 resources found parsing stdin - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0
5e180dc Revert "production: promote linkly chart 0.4.0 / image 1.5.0 from staging"
b39c641 production: promote linkly chart 0.4.0 / image 1.5.0 from staging
7984826 linkly-deploy: staging on chart 0.4.0, production on 0.3.0
production after revert: chart 0.3.0, image 1.4.1
The rendered diff tells reviewers more than the two-line Git diff: the image changes and the new chart adds a PodDisruptionBudget to production (3 replicas > 1). That is the kind of side effect that should be approved knowingly, not discovered.
Step 4: the same repo with Flux
The repository layout doesn't change. Each environment gets an OCIRepository for its chart version and a HelmRelease whose values come from a ConfigMap that Kustomize generates from the same values.yaml. Promotion is still the same two-line commit (the --tag of the OCIRepository is the chart version):
mkdir -p clusters/production && cd clusters/production
flux create source oci linkly-chart --url=oci://ghcr.io/acme/charts/linkly --tag=0.4.0 \
--interval=10m --namespace=linkly-prod --export > linkly.yaml
flux create helmrelease linkly --namespace=linkly-prod --chart-ref=OCIRepository/linkly-chart \
--values-from=ConfigMap/linkly-values --interval=10m --export >> linkly.yaml
yq -i 'select(.kind == "HelmRelease") |= (.spec.upgrade.remediation = {"retries": 3, "strategy": "rollback"} | .spec.test.enable = true)' linkly.yaml
cat > kustomization.yaml <<'EOF'
namespace: linkly-prod
resources: [linkly.yaml]
configMapGenerator:
- name: linkly-values
files: [values.yaml=../../apps/linkly/production/values.yaml]
generatorOptions: {disableNameSuffixHash: true}
EOF
mkdir -p ../../apps/linkly/production && printf 'replicaCount: 3\nimage: {tag: 1.5.0}\n' > ../../apps/linkly/production/values.yaml
kustomize build --load-restrictor LoadRestrictionsNone . > rendered.yaml
yq -N '.kind + "/" + .metadata.name' rendered.yaml
kubeconform -strict -summary rendered.yamlConfigMap/linkly-values
HelmRelease/linkly
OCIRepository/linkly-chart
Summary: 3 resources found in 1 file - Valid: 3, Invalid: 0, Errors: 0, Skipped: 0
Kustomize refuses files outside the overlay's folder by default; --load-restrictor LoadRestrictionsNone (or keeping the values file next to the kustomization) solves that. kustomize-controller builds with the restriction disabled, so this works as is in Flux.
Extend it
- Add a
qaenvironment by creatingapps/linkly/qa/only: the ApplicationSet generateslinkly-qawithout edits. Make sure CI and the AppProject still accept it. - Turn the promotion into a script that refuses to run unless staging's Application is Synced and Healthy on the candidate (use the gate from the promotion lesson and
argocd app get -o json). - Enable Progressive Syncs with a
RollingSyncstrategy keyed on theenvlabel, so a template change reaches staging before production. - Replace the Deployment with an Argo Rollouts canary using the Gateway API plugin (Rollouts), and add the HTTPRoute weights to
ignoreDifferences. - Add Renovate to propose new chart versions for staging automatically, and require CODEOWNERS approval for
apps/linkly/production/.
Test yourself
In this project, which values does a promotion copy from staging to production?
- The whole folder
- chartVersion and image.tag
- replicaCount and host
- Only the namespace
Why attach the rendered diff to the promotion pull request?
- Git can't diff YAML
- It shows the objects that will actually change, including side effects of a new chart version such as the added PodDisruptionBudget
- Argo CD requires it
- It speeds up the sync
How does the ApplicationSet know which chart version each environment runs?
- From the image tag
- The Git files generator reads
chartVersionfrom eachrelease.yamland passes it totargetRevision - From the namespace name
- Argo CD always uses the latest chart