Project Workshop — FastAPI on Kubernetes
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Kubernetes · kubectl · YAML
Expected effort: 15–24 focused hours · Minimum meaningful tests: 12What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | Pod: spec/containers/resources/liveness+readiness probes produces the specified behavior inside Core workload objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | Deployment: replicas/RollingUpdate/revisionHistoryLimit produces the specified behavior inside Core workload objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | DaemonSet: one pod per node produces the specified behavior inside Core workload objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | StatefulSet: ordered deployment/stable network identity produces the specified behavior inside Core workload objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | ClusterIP/NodePort/LoadBalancer/ExternalName produces the specified behavior inside Services, ConfigMaps & Secrets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | DNS: service.namespace.svc.cluster.local produces the specified behavior inside Services, ConfigMaps & Secrets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | ConfigMap: env/envFrom/volume mounting produces the specified behavior inside Services, ConfigMaps & Secrets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | Secret types: Opaque/TLS produces the specified behavior inside Services, ConfigMaps & Secrets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.5 | Sealed Secrets + External Secrets Operator produces the specified behavior inside Services, ConfigMaps & Secrets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | CRUD: apply/get/describe/delete/edit produces the specified behavior inside kubectl essentials | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | Debugging: logs/exec/port-forward/cp produces the specified behavior inside kubectl essentials | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | Rolling updates: set image/rollout status/history/undo produces the specified behavior inside kubectl essentials | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | JSONPath queries in get output produces the specified behavior inside kubectl essentials | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | Namespace isolation limits produces the specified behavior inside Namespaces & policy | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | ResourceQuota aggregate caps produces the specified behavior inside Namespaces & policy | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | LimitRange defaults and bounds produces the specified behavior inside Namespaces & policy | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.4 | default-deny NetworkPolicy plus explicit ingress/egress produces the specified behavior inside Namespaces & policy | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.5 | kubectl explain recursive schema inspection produces the specified behavior inside Namespaces & policy | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1delivery/2├── app/3├── Dockerfile4├── compose.yaml5├── .github/workflows/6├── deploy/{base,overlays,helm}/7├── cloud/{sam,terraform}/8├── observability/{prometheus,grafana,otel,alerts}/9├── tests/{smoke,policy,load}/10└── runbooks/Build plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Core workload objects | Pod: spec/containers/resources/liveness+readiness probes; Deployment: replicas/RollingUpdate/revisionHistoryLimit; DaemonSet: one pod per node | Demonstration plus focused tests |
| 2 | Services, ConfigMaps & Secrets | ClusterIP/NodePort/LoadBalancer/ExternalName; DNS: service.namespace.svc.cluster.local; ConfigMap: env/envFrom/volume mounting | Demonstration plus focused tests |
| 3 | kubectl essentials | CRUD: apply/get/describe/delete/edit; Debugging: logs/exec/port-forward/cp; Rolling updates: set image/rollout status/history/undo | Demonstration plus focused tests |
| 4 | Namespaces & policy | Namespace isolation limits; ResourceQuota aggregate caps; LimitRange defaults and bounds | Demonstration plus focused tests |
| 5 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1apiVersion: apps/v12kind: Deployment3metadata: {name: url-api}4spec:5 replicas: 36 strategy: {type: RollingUpdate, rollingUpdate: {maxUnavailable: 0, maxSurge: 1}}7 selector: {matchLabels: {app: url-api}}8 template:9 metadata: {labels: {app: url-api}}10 spec:11 terminationGracePeriodSeconds: 3012 containers:13 - name: api14 image: registry.example/url-api@sha256:immutable15 ports: [{containerPort: 8000}]16 resources:17 requests: {cpu: 100m, memory: 128Mi}18 limits: {cpu: 500m, memory: 256Mi}19 readinessProbe: {httpGet: {path: /ready, port: 8000}, periodSeconds: 5}20 livenessProbe: {httpGet: {path: /health, port: 8000}, periodSeconds: 10}Expected result
1The controller maintains three ready replicas and performs a zero-unavailable rolling update.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | apiVersion: apps/v1 | Declares one level of a desired-state or automation document. |
| 2 | kind: Deployment | Declares one level of a desired-state or automation document. |
| 3 | metadata: {name: url-api} | Declares one level of a desired-state or automation document. |
| 4 | spec: | Declares one level of a desired-state or automation document. |
| 5 | replicas: 3 | Implements the next yaml statement in the example's data flow. |
| 6 | strategy: {type: RollingUpdate, rollingUpdate: {maxUnavailable: 0, maxSurge: 1}} | Implements the next yaml statement in the example's data flow. |
| 7 | selector: {matchLabels: {app: url-api}} | Begins a declarative database or protocol operation; subsequent lines refine its contract. |
| 8 | template: | Implements the next yaml statement in the example's data flow. |
| 9 | metadata: {labels: {app: url-api}} | Declares one level of a desired-state or automation document. |
| 10 | spec: | Declares one level of a desired-state or automation document. |
| 11 | terminationGracePeriodSeconds: 30 | Implements the next yaml statement in the example's data flow. |
| 12 | containers: | Implements the next yaml statement in the example's data flow. |
| 13 | - name: api | Implements the next yaml statement in the example's data flow. |
| 14 | image: registry.example/url-api@sha256:immutable | Implements the next yaml statement in the example's data flow. |
| 15 | ports: [{containerPort: 8000}] | Implements the next yaml statement in the example's data flow. |
| 16 | resources: | Implements the next yaml statement in the example's data flow. |
| 17 | requests: {cpu: 100m, memory: 128Mi} | Implements the next yaml statement in the example's data flow. |
| 18 | limits: {cpu: 500m, memory: 256Mi} | Adds a relational selection, combination, ordering, bound, or returned-value rule to the statement. |
| 19 | readinessProbe: {httpGet: {path: /ready, port: 8000}, periodSeconds: 5} | Implements the next yaml statement in the example's data flow. |
| 20 | livenessProbe: {httpGet: {path: /health, port: 8000}, periodSeconds: 10} | Implements the next yaml statement in the example's data flow. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Core workload objects | A liveness probe that depends on a downstream database can restart every healthy pod during a database outage. | Set requests, graceful termination, conservative probes, and disruption-aware rollouts. |
| Services, ConfigMaps & Secrets | Environment variables do not update in running processes and base64 is not encryption. | Use workload identity or external secret synchronization and trigger safe rollouts on config changes. |
| kubectl essentials | Manual edits drift from Git and disappear during reconciliation. | Prefer committed manifests and use imperative commands for diagnosis. |
| Namespaces & policy | Namespaces alone are not a security boundary, and NetworkPolicy without an enforcing CNI changes nothing. | Apply default-deny then add DNS and required service paths, and verify policy in a real cluster/CNI. |
Engineering checklist for this stack
- To do: run with least privilege and immutable artifacts
- To do: declare resource bounds and health behavior
- To do: separate secrets from versioned configuration
- To do: prove rollback and restore
- To do: correlate deployment version with metrics, logs, and traces
Test strategy
Implement at least 12 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 4 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1set -euo pipefail2docker build --check .3trivy image --exit-code 1 "$IMAGE_DIGEST"4helm lint ./deploy/helm5helm template test ./deploy/helm | kubeconform -strict6pytest -q tests/smoke7locust --headless --users 100 --spawn-rate 10 --run-time 2mFailure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?