Application Patterns
Purpose: For application developers, provides reference patterns for stateless web apps, stateful services, batch jobs, and multi-environment promotion.
Overview
This reference covers four deployment patterns used in openCenter clusters. Each pattern includes the Kubernetes resource types involved, a minimal manifest example, and notes on when to use it.
Pattern 1 — Stateless Web Application
The most common pattern. A Deployment with an HPA, a Service, and an HTTPRoute.
Resources: Deployment, Service, HTTPRoute, HorizontalPodAutoscaler
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-frontend
namespace: my-app
spec:
replicas: 2
selector:
matchLabels:
app: web-frontend
template:
metadata:
labels:
app: web-frontend
spec:
containers:
- name: web-frontend
image: harbor.opencenter.example.com/customer-apps/web-frontend:2.1.0-def456
ports:
- containerPort: 3000
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1000m
memory: 512Mi
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-frontend
namespace: my-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-frontend
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
When to use: HTTP APIs, SPAs, microservices that store no local state. Scale horizontally with HPA.
Pattern 2 — Stateful Service
For databases, caches, or message brokers that need stable network identity and persistent storage.
Resources: StatefulSet, Service (headless), PersistentVolumeClaim
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
namespace: my-app
spec:
serviceName: postgres
replicas: 3
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: harbor.opencenter.example.com/customer-apps/postgres:16.2-abc789
ports:
- containerPort: 5432
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: 2000m
memory: 4Gi
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: longhorn
resources:
requests:
storage: 50Gi
When to use: Databases, Redis clusters, Kafka brokers. Requires Longhorn or vSphere CSI for persistent volumes.
Pattern 3 — Batch Job
For one-off or scheduled workloads like data migrations, report generation, or ETL pipelines.
Resources: CronJob (or Job), ServiceAccount
apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-report
namespace: my-app
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: report-generator
image: harbor.opencenter.example.com/customer-apps/report-gen:1.0.0-fed321
command: ["python", "generate_report.py"]
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: 2000m
memory: 2Gi
restartPolicy: OnFailure
securityContext:
runAsNonRoot: true
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 5
When to use: Scheduled tasks, data pipelines, migration scripts. Set activeDeadlineSeconds to prevent runaway jobs.
Pattern 4 — Multi-Environment with Kustomize Overlays
For applications that deploy to dev, staging, and production with environment-specific configuration.
Directory structure:
my-app/
├── base/
│ ├── kustomization.yaml
│ ├── deployment.yaml
│ ├── service.yaml
│ └── httproute.yaml
└── overlays/
├── dev/
│ ├── kustomization.yaml
│ └── patch-replicas.yaml
├── staging/
│ ├── kustomization.yaml
│ └── patch-replicas.yaml
└── production/
├── kustomization.yaml
└── patch-replicas.yaml
# overlays/production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
patches:
- path: patch-replicas.yaml
images:
- name: my-app
newName: harbor.opencenter.example.com/platform-production/my-app
newTag: "2.1.0-def456"
# overlays/production/patch-replicas.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 5
When to use: Any application that needs different replica counts, resource limits, image tags, or feature flags per environment. The platform team points each cluster's FluxCD Kustomization at the appropriate overlay path.
Pattern Comparison
| Pattern | Scaling | Storage | Networking | Complexity |
|---|---|---|---|---|
| Stateless web app | HPA (horizontal) | None | HTTPRoute | Low |
| Stateful service | Manual or operator | PVC (Longhorn/CSI) | Headless Service | Medium |
| Batch job | N/A (runs to completion) | Optional | None (internal) | Low |
| Multi-environment | Per-overlay | Per-overlay | Per-overlay | Medium |
Further Reading
- Deploying Applications — End-to-end tutorial
- Manifest Structure Reference — Field-level details
- Gateway API & TLS — HTTPS routing configuration