Platform Engineering · Lesson 196

Capstone: Build a Multi-Tenant OpenShift Platform for Application Teams

An OpenShift cluster becomes a platform when many teams can use it safely without asking an administrator for every change. This capstone builds that: a project per team and environment from a template, identity groups mapped to roles, quotas and default-deny network policies in every project, the restricted security context constraint, GitOps per tenant, monitoring for user workloads, and an upgrade rehearsal with real tenant workloads on the nodes. Two problems appear on purpose: a team that wants its container to run as root, and a disruption budget that stops every node drain.

Difficulty: Master · Know this first: Lesson 102, Lesson 103, Lesson 178

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar splits the platform project, in working days. It is a worked example, not a measurement. The guardrail hops are built once; the onboarding check and the rehearsal are where tenant workloads meet them.

Try it: will this workload let the nodes drain?

Set a deployment's replicas and its disruption budget, and the size of the worker pool. See how many evictions the budget allows and how long a rolling upgrade of the pool takes.

allowed disruptions = replicas − minAvailable (when all are healthy), upgrade ≈ ceil(nodes ÷ maxUnavailable) × 10 min

1allowed disruptions
2.0 hpool upgrade
drainsnode drain

Drains: the budget allows 1 pod at a time to move

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

The capstone grows in four levels: first isolated projects, then self-service for teams, then a platform that can be maintained with tenants on it, and finally one that runs as a product.

Basic — Isolated projects

At the basic level each team gets projects that are isolated from the others: group-based role bindings, a quota and limit range, default-deny network policies with the router allowed in, and restricted-v2 for every pod.

Deliverables: the project template, the network policies and quota, and a test showing one tenant cannot reach another.

Try it: Basic

Two tenants' pods can reach each other. Which piece is missing?

Now do it: Apply the policies in Go deeper to two test projects and prove cross-project traffic is blocked.

Intermediate — Self-service for teams

At the intermediate level teams onboard and deploy without tickets.

  • Onboarding as a pull request: a team, its group, and its environments create projects from the template.
  • Argo CD AppProjects per team, limited to their repositories and projects.
  • User workload monitoring, so teams own their metrics and alerts.

Try it: Intermediate

How do you stop team A's Argo CD application from deploying into team B's project?

Now do it: Write the AppProject for one team with dev, test, and prod projects.

Advanced — Maintainable with tenants on it

At the advanced level the platform team can upgrade and repair without negotiating each time.

  • The onboarding check covers arbitrary UIDs, requests, disruption budgets, probes, and image sources.
  • Upgrade rehearsals in a staging cluster with tenant workloads, and a published upgrade calendar.
  • Policy as code (an admission policy) rejecting budgets that allow zero disruptions and images from unknown registries.

Try it: Advanced

A deployment of 3 replicas has a PDB with minAvailable 3. Will a drain proceed?

Now do it: Run tenant_onboarding.py and add a workload that would pass every check.

Master — A platform run as a product

At the master level the platform has users, a roadmap, and measures.

  • Measures: time to onboard a team, time from commit to production, upgrade duration, and exceptions granted.
  • Exceptions are rare, reviewed, time-limited, and visible.
  • Showback of quota and usage per team.
  • A golden path maintained like a product, with a template repository and documentation.

Trade-off: strict guardrails slow the first onboarding of legacy workloads; loose ones make every later upgrade and audit harder. A cluster per team avoids shared rules at the cost of many clusters to upgrade.

Try it: Master

Which measure tells you the platform is working for teams?

Now do it: Write the three measures you would report monthly for this platform.

Go deeper

The onboarding check and the quota sizing fit in one script. Each workload is tested against restricted-v2 (no root expectation, group-0 writable files, no privilege or host paths), for requests, and for a disruption budget that lets nodes drain. Standard library only; python3 tenant_onboarding.py.

The onboarding check

# tenant_onboarding.py - check a team's workloads against an OpenShift platform's rules before onboarding
# restricted-v2 SCC: no privileged, no host paths, drop ALL capabilities, run as any UID the project assigns
workloads = [
    {"name": "web", "runs_as_root": False, "writes_as_group_0": True, "privileged": False, "host_path": False,
     "requests": True, "replicas": 3, "pdb_min_available": 2},
    {"name": "legacy-api", "runs_as_root": True, "writes_as_group_0": False, "privileged": False, "host_path": False,
     "requests": True, "replicas": 2, "pdb_min_available": 2},
    {"name": "log-agent", "runs_as_root": True, "writes_as_group_0": False, "privileged": True, "host_path": True,
     "requests": False, "replicas": 1, "pdb_min_available": 0},
    {"name": "worker", "runs_as_root": False, "writes_as_group_0": False, "privileged": False, "host_path": False,
     "requests": True, "replicas": 1, "pdb_min_available": 1},
]

def review(w):
    problems = []
    if w["privileged"] or w["host_path"]:
        problems.append("needs a privileged SCC: a platform component, not a tenant workload")
    elif w["runs_as_root"]:
        problems.append("expects root: rebuild to run as an arbitrary UID, not anyuid")
    if not w["writes_as_group_0"] and not w["privileged"]:
        problems.append("files not group-0 writable: an arbitrary UID cannot write them")
    if not w["requests"]:
        problems.append("no requests: a requests quota rejects it unless a LimitRange sets defaults")
    allowed = w["replicas"] - w["pdb_min_available"]   # disruptions the PDB allows when all replicas are healthy
    if w["pdb_min_available"] and allowed < 1:
        problems.append(f"PDB allows {allowed} disruptions: node drains and cluster upgrades will stall")
    return problems

for w in workloads:
    p = review(w)
    print(f"{w['name']:<11} {'ready' if not p else 'fix: ' + '; '.join(p)}")

# Quota for the project: requests summed over the replicas, plus room for one rolling update
cpu_m = {"web": 250, "legacy-api": 500, "worker": 1000}
reps = {"web": 3, "legacy-api": 2, "worker": 1}
steady = sum(cpu_m[n] * reps[n] for n in cpu_m)
surge = max(cpu_m[n] for n in cpu_m)                    # maxSurge 1 on the largest deployment
print(f"requests.cpu quota: {steady}m steady + {surge}m for a rolling update = {steady + surge}m")
$ python3 tenant_onboarding.py
web         ready
legacy-api  fix: expects root: rebuild to run as an arbitrary UID, not anyuid; files not group-0 writable: an arbitrary UID cannot write them; PDB allows 0 disruptions: node drains and cluster upgrades will stall
log-agent   fix: needs a privileged SCC: a platform component, not a tenant workload; no requests: a requests quota rejects it unless a LimitRange sets defaults
worker      fix: files not group-0 writable: an arbitrary UID cannot write them; PDB allows 0 disruptions: node drains and cluster upgrades will stall
requests.cpu quota: 2750m steady + 1000m for a rolling update = 3750m

Read it like this: web is ready. legacy-api needs an image rebuild and a budget that allows a disruption. log-agent is a platform component that does not belong in a tenant project. worker blocks drains with a single replica and minAvailable 1. The quota is the steady requests plus one rolling update of the largest deployment.

Network policies and a quota from the project template

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
spec:
  podSelector: {}
  policyTypes: [Ingress]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-same-namespace
spec:
  podSelector: {}
  ingress:
    - from:
        - podSelector: {}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-from-openshift-ingress
spec:
  podSelector: {}
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              policy-group.network.openshift.io/ingress: ""
---
apiVersion: v1
kind: ResourceQuota
metadata:
  name: team-quota
spec:
  hard:
    requests.cpu: 3750m
    requests.memory: 8Gi
    limits.memory: 12Gi
    pods: "30"

All four parse as YAML and are standard resources. The ingress label selects the namespaces of the OpenShift router, so routes keep working under default deny. In the project template they sit alongside the project and its role bindings.

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. A shared cluster started a minor upgrade on a Friday evening.

Timeline

  • 18:00The control plane upgrades; the worker pool starts draining nodes one by one.
  • 18:40The pool stops on one node: a tenant's single-replica service has a budget with minAvailable 1, so eviction is refused.
  • 21:15The on-call engineer finds the tenant, agrees to scale the service to two replicas, and the drain resumes. The upgrade finishes after midnight.

What changed after

An admission policy rejects budgets that allow zero disruptions, the onboarding check tests budgets, and upgrades are rehearsed in staging with tenant workloads first.

If you remember nothing else

Design exercise

Build a multi-tenant OpenShift platform for 15 application teams, each with dev, test, and production, some bringing legacy images.

Clarifying questions to ask

What is the tenancy model? Which identity provider and groups? How are quotas sized? Which network policies are in the template? How are images checked and from which registries? How does each team deploy? What does the onboarding check test? How are upgrades rehearsed, and when?

Rough sizing

Say 15 teams, 45 projects, 40 worker nodes in two pools, about 300 deployments, and a minor upgrade every quarter.

Shape of the answer

A project request template with quota, LimitRange, default-deny network policies, and group role bindings; OIDC with group sync; restricted-v2 and Pod Security labels; allowed registries and signature checks for production; OpenShift GitOps with an AppProject per team; user workload monitoring; an onboarding check and an admission policy for budgets and images; staging upgrade rehearsals; a golden path repository.

Trade-offs to name

Strict defaults slow legacy onboarding by days and make every later upgrade and audit easier. Shared clusters are cheaper and need tenancy rules; clusters per team are simpler per team and multiply upgrades. Exceptions are sometimes necessary; make them rare, reviewed, and time-limited.

Saved on this device, in this browser.
Next in this series · Lesson 197
Large Language Models

A large language model is a program that learned patterns from a huge amount of written text, and then uses those patterns to write new text one piece at a time. That is the whole trick. It does not look up answers in a book.

Go to Lesson 197 →

Or browse the full course from the Lessons index.