{
    "slug": "kubernetes_basics",
    "term": "Kubernetes for PHP Developers",
    "category": "devops",
    "difficulty": "intermediate",
    "short": "The essential Kubernetes concepts PHP developers need — Pods, Deployments, Services, ConfigMaps, Secrets, and Ingress — for deploying and scaling PHP applications on Kubernetes.",
    "long": "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.",
    "aliases": [
        "K8s",
        "kubectl",
        "Kubernetes PHP",
        "pod deployment"
    ],
    "tags": [
        "devops",
        "kubernetes",
        "php",
        "containers"
    ],
    "misconception": "Kubernetes is only for large scale — Kubernetes simplifies deployment even for small teams: automatic rollbacks, health checks, and auto-scaling are valuable at any scale.",
    "why_it_matters": "Without Kubernetes (or equivalent), PHP deployments require manual coordination of server updates, rollbacks, and scaling — Kubernetes makes zero-downtime deploys and auto-scaling standard behaviour.",
    "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)."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "containerisation",
        "docker_multistage",
        "container_security",
        "health_check"
    ],
    "prerequisites": [
        "containerisation",
        "cloud_native_patterns",
        "cloud_auto_scaling"
    ],
    "refs": [
        "https://kubernetes.io/docs/concepts/workloads/controllers/deployment/"
    ],
    "bad_code": "# Minimal deployment — missing critical settings:\napiVersion: apps/v1\nkind: Deployment\nspec:\n  template:\n    spec:\n      containers:\n      - name: php\n        image: myapp:latest  # Non-deterministic tag\n        # No resource limits — can OOM other pods\n        # No readiness probe — traffic before ready\n        # No liveness probe — dead pods receive traffic",
    "good_code": "# Production-ready PHP deployment:\napiVersion: apps/v1\nkind: Deployment\nspec:\n  template:\n    spec:\n      containers:\n      - name: php\n        image: myapp:a3f2c1d  # Immutable SHA tag\n        resources:\n          requests: {memory: 256Mi, cpu: 100m}\n          limits:   {memory: 512Mi, cpu: 500m}\n        readinessProbe:\n          httpGet: {path: /health, port: 80}\n          initialDelaySeconds: 5\n        livenessProbe:\n          httpGet: {path: /health, port: 80}\n          periodSeconds: 10\n        envFrom:\n        - secretRef: {name: app-secrets}\n        - configMapRef: {name: app-config}",
    "quick_fix": "Set resource requests and limits on every PHP pod, configure readiness and liveness probes, and use a Horizontal Pod Autoscaler based on CPU or custom metrics",
    "severity": "medium",
    "effort": "high",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/kubernetes_basics",
        "html_url": "https://codeclaritylab.com/glossary/kubernetes_basics",
        "json_url": "https://codeclaritylab.com/glossary/kubernetes_basics.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Kubernetes for PHP Developers](https://codeclaritylab.com/glossary/kubernetes_basics) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/kubernetes_basics"
            }
        }
    }
}