TExcelTAD
Home › GitOps: Argo CD & Flux › The Running Example: linkly-deploy

The Running Example: linkly-deploy

Every lesson in this course deploys the same app: linkly, the Go link shortener that Kubernetes Packaging packaged as a Helm chart and that the planned DevOps Capstone runs end to end. Here you set up the repository a GitOps agent will watch: linkly-deploy.

Two repositories

GitOps teams almost always split code from configuration:

Repository Contains Changed by Triggers
acme/linkly (app) Go source, Dockerfile, chart source, CI workflow developers CI: test, scan, build ghcr.io/acme/linkly:<version>, push the chart to oci://ghcr.io/acme/charts
acme/linkly-deploy (config) which chart version and image tag run where, plus per-environment values pull requests (people or bots) the GitOps agent

Why split? The deploy repo's history becomes a clean log of deployments rather than every code commit; its access rules can differ (more reviewers for production); and CI pushing a tag bump to it can't loop back into another app build. The Repository Layouts lesson covers the alternatives.

The layout

text
linkly-deploy/
├── charts/linkly/             # a vendored copy of the chart (later lessons pull it from OCI instead)
├── apps/linkly/
│   ├── staging/values.yaml    # what differs in staging
│   └── production/values.yaml # what differs in production
└── clusters/
    ├── staging/               # what the agent on the staging cluster reads (Argo CD Applications or Flux objects)
    └── production/

Environments are folders on one branch, not branches. Promotion is a commit that changes apps/linkly/production/values.yaml; the promotion lesson explains why branch-per-environment is a trap.

Build it

The chart is the trimmed version of the helm-kustomize chart: a ConfigMap, a Deployment, a Service and a Gateway API HTTPRoute. The session writes the repository, commits it with a fixed date (so the commit hash is the same on every run), then renders both environments the way an agent would:

bash · try it yourself
git init -q linkly-deploy && cd linkly-deploy
mkdir -p charts/linkly/templates apps/linkly/staging apps/linkly/production clusters/staging clusters/production
cat > charts/linkly/Chart.yaml <<'EOF'
apiVersion: v2
name: linkly
version: 0.3.0
appVersion: "1.4.0"
EOF
cat > charts/linkly/values.yaml <<'EOF'
replicaCount: 2
image: {repository: ghcr.io/acme/linkly, tag: ""}
logLevel: info
host: lnk.example.com
EOF
cat > charts/linkly/templates/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata: {name: {{ .Release.Name }}-config}
data: {LOG_LEVEL: {{ .Values.logLevel | quote }}, BASE_URL: "https://{{ .Values.host }}"}
EOF
cat > charts/linkly/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 }}"
          ports: [{name: http, containerPort: 8080}]
          envFrom: [{configMapRef: {name: {{ .Release.Name }}-config}}]
EOF
cat > charts/linkly/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 > charts/linkly/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
cat > apps/linkly/staging/values.yaml <<'EOF'
replicaCount: 1
image: {tag: 1.5.0-rc.1}
logLevel: debug
host: lnk.staging.example.com
EOF
cat > apps/linkly/production/values.yaml <<'EOF'
replicaCount: 3
image: {tag: 1.4.0}
EOF
touch clusters/staging/.keep clusters/production/.keep
git add . && git commit -qm "linkly-deploy: chart 0.3.0, staging and production"
git log --oneline
tree --noreport -a -I .git
for env in staging production; do
  echo "--- $env"
  helm template linkly charts/linkly -f apps/linkly/$env/values.yaml > ../$env.yaml
  yq 'select(.kind == "Deployment") | "replicas=" + (.spec.replicas | tostring) + " image=" + .spec.template.spec.containers[0].image' ../$env.yaml
  kubeconform -strict -summary ../$env.yaml
done
40b2f3e linkly-deploy: chart 0.3.0, staging and production
.
├── apps
│   └── linkly
│       ├── production
│       │   └── values.yaml
│       └── staging
│           └── values.yaml
├── charts
│   └── linkly
│       ├── Chart.yaml
│       ├── templates
│       │   ├── configmap.yaml
│       │   ├── deployment.yaml
│       │   ├── httproute.yaml
│       │   └── service.yaml
│       └── values.yaml
└── clusters
    ├── production
    │   └── .keep
    └── staging
        └── .keep
--- staging
replicas=1 image=ghcr.io/acme/linkly:1.5.0-rc.1
Summary: 4 resources found in 1 file - Valid: 4, Invalid: 0, Errors: 0, Skipped: 0
--- production
replicas=3 image=ghcr.io/acme/linkly:1.4.0
Summary: 4 resources found in 1 file - Valid: 4, Invalid: 0, Errors: 0, Skipped: 0

Both renders are valid against the Kubernetes and Gateway API schemas, and the only differences are the ones the values files ask for. This is the habit to keep for the whole course: before an agent ever sees a change, render it and validate it, exactly as Rendering & Validating in CI does for charts.

What the agents will read

The clusters/ folders are still empty. They will hold the objects that tell an agent what to deploy:

  • for Argo CD, an Application per environment pointing at charts/linkly with apps/linkly/<env>/values.yaml (Applications);
  • for Flux, a GitRepository source plus a HelmRelease or Kustomization per environment (The Source Controller).

One repository can serve both tools, which is how the course compares them on identical input.

Test yourself

Why keep deployment configuration in a separate repository from the application code?

  1. Git can't store YAML next to Go code
  2. The config repo's history becomes a log of deployments with its own access rules, and tag bumps don't trigger app builds
  3. Argo CD can only read repositories without source code
  4. It makes images smaller

In linkly-deploy, how are the staging and production environments represented?

  1. As two branches
  2. As two folders on the main branch, each with its own values file
  3. As two tags
  4. As two Helm charts