Kubernetes Platform Engineering
Overview
Platform engineering on Kubernetes is about making the “golden path” easy: secure-by-default workloads, consistent delivery via GitOps, and predictable operations (capacity, upgrades, incident response).
Why This Matters
- Reliability: self-healing + controlled rollouts reduce incidents
- Security: least privilege and isolation by default
- Developer velocity: standard templates + paved roads
- Cost control: right-sizing and autoscaling without surprises
Core Concepts
1. Cluster Architecture
- Separate node pools by workload class (stateless, stateful, GPU, batch, system).
- Define upgrade strategy (surge capacity, maintenance windows, version skew policy).
- Decide multi-cluster approach (per env/region/tenant) and shared services (ingress, monitoring, secrets).
2. Workload Patterns
- Deployment for stateless services; use
PodDisruptionBudget, readinessProbe, and topologySpreadConstraints.
- StatefulSet for stable identity/storage (databases, queues) with explicit backup/restore.
- Job/CronJob for batch; enforce concurrency policies and deadlines.
- DaemonSet for node-level agents (logging, CNI, security).
3. Networking
- Use
Ingress/Gateway with TLS termination and standardized auth/rate limiting at the edge.
- Apply NetworkPolicies (default-deny + explicit allow) for zero-trust inside the cluster.
- Consider service mesh only when you need it (mTLS, traffic shifting, retries, L7 telemetry); keep complexity intentional.
4. Storage
- Standardize
StorageClass per tier (fast SSD, standard, archival) and backup policies.
- For stateful apps: set anti-affinity/zone spread; verify recovery time objectives (RTO/RPO).
- Avoid “pet” PVs by having a documented restore path and regular restore drills.
5. Security Baseline
- Enforce Pod Security (restricted baseline): non-root, read-only root filesystem, drop capabilities.
- RBAC least privilege: namespace-scoped roles, separate human vs automation identities.
- Secrets: prefer external secret managers (e.g., External Secrets + AWS/GCP/Azure secret store); avoid long-lived static secrets in Git.
- Admission policies: Kyverno / Gatekeeper for guardrails (image registries, resource limits, required labels).
6. Observability & Ops
- Metrics: Prometheus + dashboards per service (latency, errors, saturation, restarts).
- Logs: structured JSON with trace IDs; centralized retention policies.
- Traces: OpenTelemetry for request graphs across services.
- SLOs: define error budgets and link alerts to user impact.
7. GitOps & Delivery
- Git is source of truth: Argo CD / Flux reconciles desired state.
- Use Helm/Kustomize overlays per environment; keep secrets out-of-band.
- Progressive delivery: canary/blue-green via Argo Rollouts / Flagger (or mesh-based traffic shifting).
8. Cost & Capacity Management
- Require resource requests/limits; use VPA recommendations carefully (watch for restarts).
- Use HPA/KEDA for demand-based scaling; use cluster autoscaler/Karpenter for nodes.
- Separate spot/preemptible pools for tolerant workloads; enforce pod placement policies.
Quick Start (Minimal “Production-ish” Deployment)
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate: { maxUnavailable: 0, maxSurge: 1 }
selector: { matchLabels: { app: app } }
template:
metadata: { labels: { app: app } }
spec:
securityContext: { runAsNonRoot: true }
containers:
- name: app
image: your-registry/app:1.0.0
ports: [{ containerPort: 3000 }]
resources:
requests: { cpu: "100m", memory: "256Mi" }
limits: { cpu: "500m", memory: "512Mi" }
readinessProbe:
httpGet: { path: /readyz, port: 3000 }
initialDelaySeconds: 5
livenessProbe:
httpGet: { path: /healthz, port: 3000 }
initialDelaySeconds: 10
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: app
spec:
minAvailable: 1
selector: { matchLabels: { app: app } }
Production Checklist
Tools & Libraries
| Tool |
Purpose |
| Argo CD / Flux |
GitOps continuous delivery |
| Helm / Kustomize |
Packaging and environment overlays |
| Prometheus + Grafana |
Metrics + dashboards |
| Loki/ELK |
Central logging |
| OpenTelemetry |
Distributed tracing |
| External Secrets |
Secret manager integration |
| Kyverno / Gatekeeper |
Policy enforcement |
Anti-patterns
- No requests/limits: unpredictable scheduling and noisy-neighbor incidents
- Hand-applied changes:
kubectl apply drift instead of GitOps reconciliation
- Flat network: no NetworkPolicies; lateral movement is trivial
- Single replica: planned/unplanned disruption becomes downtime
Real-World Examples
Example: Progressive Delivery (Canary)
- Deploy new version at 5% traffic; watch SLOs; ramp to 25/50/100%; auto-rollback on regressions.
Example: Autoscaling
- HPA on CPU/requests-per-second + cluster autoscaler for nodes; cap max replicas to protect dependencies.
Example: Zero-Trust Networking
- Default-deny in each namespace; only allow traffic from ingress controller to app and app to explicit dependencies.
Common Mistakes
- Missing readiness probes (traffic hits pods before they’re ready)
- Running containers as root (wider blast radius on compromise)
- Unbounded egress (data exfiltration paths and surprise costs)
- Treating the cluster as the product (no SLOs, no runbooks, no ownership)
Integration Points
- CI (image build, SBOM, scanning, signing)
- CD (GitOps reconciler + progressive delivery)
- Cloud provider (EKS/GKE/AKS, IAM, load balancers, DNS)
- Observability + incident management (paging, runbooks, postmortems)
Further Reading
1---
2name: kubernetes-platform-engineering
3description: Production Kubernetes platform patterns covering cluster architecture, security, GitOps, observability, autoscaling, and operational guardrails
4metadata:
5 source: https://skillmd.com/skills/aibot88/kubernetes-platform-engineering
6---
7
8# Kubernetes Platform Engineering
9
10## Overview
11
12Platform engineering on Kubernetes is about making the “golden path” easy: secure-by-default workloads, consistent delivery via GitOps, and predictable operations (capacity, upgrades, incident response).
13
14## Why This Matters
15
16- **Reliability**: self-healing + controlled rollouts reduce incidents
17- **Security**: least privilege and isolation by default
18- **Developer velocity**: standard templates + paved roads
19- **Cost control**: right-sizing and autoscaling without surprises
20
21---
22
23## Core Concepts
24
25### 1. Cluster Architecture
26
27- Separate node pools by workload class (stateless, stateful, GPU, batch, system).
28- Define upgrade strategy (surge capacity, maintenance windows, version skew policy).
29- Decide multi-cluster approach (per env/region/tenant) and shared services (ingress, monitoring, secrets).
30
31### 2. Workload Patterns
32
33- **Deployment** for stateless services; use `PodDisruptionBudget`, `readinessProbe`, and `topologySpreadConstraints`.
34- **StatefulSet** for stable identity/storage (databases, queues) with explicit backup/restore.
35- **Job/CronJob** for batch; enforce concurrency policies and deadlines.
36- **DaemonSet** for node-level agents (logging, CNI, security).
37
38### 3. Networking
39
40- Use `Ingress`/Gateway with TLS termination and standardized auth/rate limiting at the edge.
41- Apply **NetworkPolicies** (default-deny + explicit allow) for zero-trust inside the cluster.
42- Consider service mesh only when you need it (mTLS, traffic shifting, retries, L7 telemetry); keep complexity intentional.
43
44### 4. Storage
45
46- Standardize `StorageClass` per tier (fast SSD, standard, archival) and backup policies.
47- For stateful apps: set anti-affinity/zone spread; verify recovery time objectives (RTO/RPO).
48- Avoid “pet” PVs by having a documented restore path and regular restore drills.
49
50### 5. Security Baseline
51
52- Enforce Pod Security (restricted baseline): non-root, read-only root filesystem, drop capabilities.
53- RBAC least privilege: namespace-scoped roles, separate human vs automation identities.
54- Secrets: prefer external secret managers (e.g., External Secrets + AWS/GCP/Azure secret store); avoid long-lived static secrets in Git.
55- Admission policies: Kyverno / Gatekeeper for guardrails (image registries, resource limits, required labels).
56
57### 6. Observability & Ops
58
59- Metrics: Prometheus + dashboards per service (latency, errors, saturation, restarts).
60- Logs: structured JSON with trace IDs; centralized retention policies.
61- Traces: OpenTelemetry for request graphs across services.
62- SLOs: define error budgets and link alerts to user impact.
63
64### 7. GitOps & Delivery
65
66- Git is source of truth: Argo CD / Flux reconciles desired state.
67- Use Helm/Kustomize overlays per environment; keep secrets out-of-band.
68- Progressive delivery: canary/blue-green via Argo Rollouts / Flagger (or mesh-based traffic shifting).
69
70### 8. Cost & Capacity Management
71
72- Require resource requests/limits; use VPA recommendations carefully (watch for restarts).
73- Use HPA/KEDA for demand-based scaling; use cluster autoscaler/Karpenter for nodes.
74- Separate spot/preemptible pools for tolerant workloads; enforce pod placement policies.
75
76## Quick Start (Minimal “Production-ish” Deployment)
77
78```yaml
79apiVersion: apps/v1
80kind: Deployment
81metadata:
82 name: app
83spec:
84 replicas: 2
85 strategy:
86 type: RollingUpdate
87 rollingUpdate: { maxUnavailable: 0, maxSurge: 1 }
88 selector: { matchLabels: { app: app } }
89 template:
90 metadata: { labels: { app: app } }
91 spec:
92 securityContext: { runAsNonRoot: true }
93 containers:
94 - name: app
95 image: your-registry/app:1.0.0
96 ports: [{ containerPort: 3000 }]
97 resources:
98 requests: { cpu: "100m", memory: "256Mi" }
99 limits: { cpu: "500m", memory: "512Mi" }
100 readinessProbe:
101 httpGet: { path: /readyz, port: 3000 }
102 initialDelaySeconds: 5
103 livenessProbe:
104 httpGet: { path: /healthz, port: 3000 }
105 initialDelaySeconds: 10
106---
107apiVersion: policy/v1
108kind: PodDisruptionBudget
109metadata:
110 name: app
111spec:
112 minAvailable: 1
113 selector: { matchLabels: { app: app } }
114```
115
116## Production Checklist
117
118- [ ] Requests/limits set; namespaces have `LimitRange`/`ResourceQuota`
119- [ ] `readinessProbe` + `livenessProbe` + graceful shutdown configured
120- [ ] PDB + topology spread/anti-affinity to survive node/zone events
121- [ ] NetworkPolicies enforce default-deny and least access
122- [ ] RBAC least privilege; service accounts scoped per app
123- [ ] Metrics/logs/traces exported; alerts tied to SLOs
124- [ ] Backup/restore drills for stateful components
125- [ ] Upgrade playbook exists (cluster + addons + workload compatibility)
126
127## Tools & Libraries
128
129| Tool | Purpose |
130|------|---------|
131| Argo CD / Flux | GitOps continuous delivery |
132| Helm / Kustomize | Packaging and environment overlays |
133| Prometheus + Grafana | Metrics + dashboards |
134| Loki/ELK | Central logging |
135| OpenTelemetry | Distributed tracing |
136| External Secrets | Secret manager integration |
137| Kyverno / Gatekeeper | Policy enforcement |
138
139## Anti-patterns
140
1411. **No requests/limits**: unpredictable scheduling and noisy-neighbor incidents
1422. **Hand-applied changes**: `kubectl apply` drift instead of GitOps reconciliation
1433. **Flat network**: no NetworkPolicies; lateral movement is trivial
1444. **Single replica**: planned/unplanned disruption becomes downtime
145
146## Real-World Examples
147
148### Example: Progressive Delivery (Canary)
149
150- Deploy new version at 5% traffic; watch SLOs; ramp to 25/50/100%; auto-rollback on regressions.
151
152### Example: Autoscaling
153
154- HPA on CPU/requests-per-second + cluster autoscaler for nodes; cap max replicas to protect dependencies.
155
156### Example: Zero-Trust Networking
157
158- Default-deny in each namespace; only allow traffic from ingress controller to app and app to explicit dependencies.
159
160## Common Mistakes
161
1621. Missing readiness probes (traffic hits pods before they’re ready)
1632. Running containers as root (wider blast radius on compromise)
1643. Unbounded egress (data exfiltration paths and surprise costs)
1654. Treating the cluster as the product (no SLOs, no runbooks, no ownership)
166
167## Integration Points
168
169- CI (image build, SBOM, scanning, signing)
170- CD (GitOps reconciler + progressive delivery)
171- Cloud provider (EKS/GKE/AKS, IAM, load balancers, DNS)
172- Observability + incident management (paging, runbooks, postmortems)
173
174## Further Reading
175
176- [Kubernetes Documentation](https://kubernetes.io/docs/)
177- [Kubernetes Production Best Practices](https://learnk8s.io/production-best-practices)
178- [Kubernetes Patterns](https://k8spatterns.io/)