Kubernetes for PHP Developers
debt(d7/e7/b7/t5)
Closest to 'only careful code review or runtime testing' (d7). Tools listed (kubectl, k9s, prometheus, datadog) can surface issues like missing resource limits or absent readiness probes, but only after deployment — these are operational/runtime signals, not pre-deploy static analysis catches. Missing probes and resource limits won't be flagged until traffic hits a pod or a memory leak starves the node.
Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix touches multiple concerns simultaneously: resource requests/limits on every pod, readiness/liveness probes, HPA configuration, session storage migration (local files → Redis), and image tag discipline. These span Dockerfile, Helm charts/manifests, application config, and possibly infrastructure code — not a single-file change.
Closest to 'strong gravitational pull' (b7). Kubernetes shapes every aspect of PHP deployment: how images are built and tagged, how sessions are stored, how scaling decisions are made, how health is communicated. Every future change to the PHP application must account for pod lifecycle, ephemeral storage, and resource constraints. It applies broadly to web and queue-worker contexts.
Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The common_mistakes list contains several well-documented but non-obvious traps: no readiness probe causing traffic to hit unready PHP-FPM, ephemeral pods invalidating local session storage, and the `latest` tag breaking deterministic deploys. These are canonical Kubernetes gotchas that competent developers frequently stumble on before learning them.
Also Known As
TL;DR
Explanation
Key Kubernetes resources for PHP: Pod (one PHP-FPM container + nginx sidecar), Deployment (manages pod replicas, rolling updates, rollbacks), Service (stable DNS name for pods — ClusterIP for internal, LoadBalancer for external), ConfigMap (non-secret config — php.ini settings), Secret (sensitive config — DB passwords, API keys — base64 encoded), Ingress (HTTP routing, TLS termination), HorizontalPodAutoscaler (scale based on CPU/custom metrics). PHP-specific: session affinity if not using Redis sessions, shared persistent volumes for uploads (use S3 instead), readiness probes pointing to a health check endpoint.
Common Misconception
Why It Matters
Common Mistakes
- No readiness probe — Kubernetes sends traffic to pods before PHP-FPM is ready.
- No resource requests/limits — a memory-leaking PHP pod can starve other pods on the same node.
- Storing sessions in local PHP session files — pods are ephemeral; use Redis.
- Using latest image tag — non-deterministic; always use immutable image tags (commit SHA).
Code Examples
# Minimal deployment — missing critical settings:
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: php
image: myapp:latest # Non-deterministic tag
# No resource limits — can OOM other pods
# No readiness probe — traffic before ready
# No liveness probe — dead pods receive traffic
# Production-ready PHP deployment:
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: php
image: myapp:a3f2c1d # Immutable SHA tag
resources:
requests: {memory: 256Mi, cpu: 100m}
limits: {memory: 512Mi, cpu: 500m}
readinessProbe:
httpGet: {path: /health, port: 80}
initialDelaySeconds: 5
livenessProbe:
httpGet: {path: /health, port: 80}
periodSeconds: 10
envFrom:
- secretRef: {name: app-secrets}
- configMapRef: {name: app-config}