Part IV — Expert Production Engineering · Chapter 22 · Lesson 1 of 5 · 2 min read
Lesson 1: Deployment, Service, Autoscaling, and Monitoring Resources
Lesson level: Expert
Purpose: Cloud-native resources cooperate through exact names and selectors. Review generated defaults and prove scheduling, routing, scraping, and scaling separately.
Learning Objectives
- Explain the relevant resource and security contracts.
- Review generated defaults against the application requirements.
- Validate normal and failure behavior in an approved environment.
1.1 Concepts
A Deployment manages replaceable replicas, a Service selects their network endpoints, a HorizontalPodAutoscaler changes replica count, and a ServiceMonitor describes metric discovery for an installed monitoring operator. RC2 has two generators: pealang.distributed_serving creates these four resource kinds; pealang.kubernetes_security creates Deployment, Service, PodDisruptionBudget, and NetworkPolicy. Neither generator alone produces the full hardened operational set. Compose a reviewed deployment rather than publishing both Deployments under the same name.
1.2 Annotated Example
Verified Python entry points are kubernetes_manifests(KubernetesConfig(...)) and secure_kubernetes_manifests(SecureKubernetesConfig(...)). Inspect their returned dictionaries. The ordinary Service lacks the app label required by its generated ServiceMonitor and lacks a port named http although the monitor references http. Add the matching Service label and named port in your application deployment. ServiceMonitor also needs the operator and its custom resource definition installed.
1.3 Guided Practice
Follow a request from Service selector to ready Pod. Follow a scrape from ServiceMonitor selector to the named Service port. Explain why CPU-based autoscaling needs resource requests and cluster metric availability.
1.4 Common Mistakes
Avoid mutable image tags, unmatched selectors, duplicated Deployments, and an HPA deployed without metric support. Do not equate emitted resources with a successful rollout.
1.5 Hands-On Lab
- Generate both resource sets with an explicit approved image and inspect every kind.
- Compose one Deployment using hardened security plus measured resource requests and limits.
- Correct Service labels and the named http port; validate monitoring discovery in an approved test cluster.
- Add an HPA with service-specific bounds and observe scale behavior under a preset workload.
Deliverable: Reviewed resources, environment prerequisites, test results, and unresolved operational gaps.
1.6 Review Questions
Why do the two generators need composition? Which Service fields does ServiceMonitor depend on? What must be installed before an HPA can use CPU metrics?
1.7 Applied Challenge
Build a resource relationship table linking each selector, port, image identity, probe, and scaling target to its corresponding resource.
Lesson Summary
Cloud-native resources cooperate through exact names and selectors. Review generated defaults and prove scheduling, routing, scraping, and scaling separately.
Lesson status: Draft complete; ready for review. Source-checked, not cluster-validated.