| name | kubernetes-patterns |
| description | Use when deploying to Kubernetes, writing manifests, or designing K8s architecture. Covers Deployments, Services, Ingress, HPA autoscaling, RBAC, network policies, security contexts, resource limits, and Helm chart patterns. |
| metadata | {"author":"bipinks"} |
Kubernetes Patterns
Deployment Patterns
Production-Ready Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web-app
version: v1.2.0
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
version: v1.2.0
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 2000
containers:
- name: web-app
image: registry.example.com/web-app:v1.2.0
ports:
- containerPort: 8080
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-credentials
key: url
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: web-app
HorizontalPodAutoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-app
minReplicas: 3
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 2
periodSeconds: 60
scaleDown:
Network Policy
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: web-app-netpol
spec:
podSelector:
matchLabels:
app: web-app
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: ingress-nginx
ports:
- port: 8080
egress:
- to:
- podSelector:
matchLabels:
app: database
ports:
- port: 5432
- to:
- namespaceSelector: {}
ports:
- port: 53
protocol: UDP
Best Practices
- Resource limits — Set both requests and limits for every container
- Health checks — Configure liveness, readiness, and startup probes
- Pod disruption budgets — Protect availability during maintenance
- Network policies — Default deny, then explicitly allow
- RBAC — Minimal permissions, namespace-scoped roles
- Secrets — Use external secrets operators (AWS Secrets Manager, Vault)
- Labels — Standard labels: app, version, environment, team, component
- Topology spread — Distribute pods across zones
- Security context — RunAsNonRoot, read-only filesystem, drop capabilities
- Resource quotas — Limit namespace resource consumption
Helm Chart Structure
charts/web-app/
├── Chart.yaml
├── values.yaml
├── values-production.yaml
├── templates/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── hpa.yaml
│ ├── pdb.yaml
│ ├── networkpolicy.yaml
│ └── _helpers.tpl
└── tests/
Source: bipinks/ghost-office — distributed by TomeVault.