{"id":3492,"date":"2026-12-05T06:19:13","date_gmt":"2026-12-05T06:19:13","guid":{"rendered":"https:\/\/www.rajeshkumar.xyz\/blog\/?p=3492"},"modified":"2026-12-05T06:19:16","modified_gmt":"2026-12-05T06:19:16","slug":"readiness-liveness-and-startup-probes-a-kubernetes-failure-injection-guide","status":"publish","type":"post","link":"https:\/\/www.rajeshkumar.xyz\/blog\/readiness-liveness-and-startup-probes-a-kubernetes-failure-injection-guide\/","title":{"rendered":"Readiness, Liveness and Startup Probes: A Kubernetes Failure-Injection Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Kubernetes Pod can show <code>Running<\/code> while its application is unable to serve requests correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An application may still be loading configuration, waiting for its database connection, recovering from a temporary problem, or stuck in a process that cannot make progress.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes needs a way to detect these conditions and respond correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It provides three important container health checks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Readiness probes<\/strong> determine whether a container can receive normal Service traffic.<\/li>\n\n\n\n<li><strong>Liveness probes<\/strong> determine whether a container should be restarted.<\/li>\n\n\n\n<li><strong>Startup probes<\/strong> protect applications that need extra time to initialize.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These probes solve different problems. Using the wrong probe can cause unnecessary restarts, failed requests, or traffic reaching an application that is not ready.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains the differences and shows how to test them through controlled failure injection. You will deploy a small application, simulate a slow startup, make it unready, trigger a liveness restart, inspect Kubernetes events, and restore the application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All experiments use an isolated Kubernetes namespace. Do not run these failure-injection exercises against production workloads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Understand the Three Kubernetes Probes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes uses the kubelet to run container probes. The kubelet performs a configured diagnostic at regular intervals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The result determines what Kubernetes does next.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Probe<\/th><th>Main question<\/th><th>What happens when it fails?<\/th><\/tr><tr><td>Readiness<\/td><td>Can this application receive traffic now?<\/td><td>Pod becomes not ready for normal Service traffic<\/td><\/tr><tr><td>Liveness<\/td><td>Is this application still healthy enough to continue running?<\/td><td>Container is restarted after the failure threshold<\/td><\/tr><tr><td>Startup<\/td><td>Has this application completed its initial startup?<\/td><td>Container is restarted if startup never succeeds within the allowed attempts<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The most important difference is their intended action.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A readiness failure does not restart the container. A liveness failure can restart it. A startup probe controls the initial period before liveness and readiness checks begin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes documents these behaviours in its <a href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/probes\/\">official probe documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. How a Readiness Probe Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A readiness probe checks whether an application can accept requests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A container may be running but temporarily unable to serve traffic. For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The application is loading configuration.<\/li>\n\n\n\n<li>A required cache is still warming.<\/li>\n\n\n\n<li>A local queue is full.<\/li>\n\n\n\n<li>A required dependency is unavailable.<\/li>\n\n\n\n<li>The application is recovering from a temporary fault.<\/li>\n\n\n\n<li>The application is performing maintenance.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When readiness fails, Kubernetes marks the Pod as not ready.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Pod remains running. Kubernetes continues checking readiness, so the Pod can become ready again when the application recovers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Pods selected by a Service, readiness affects their EndpointSlice conditions. An endpoint marked not ready is not normally selected for Service traffic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example readiness probe<\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">readinessProbe:\n  httpGet:\n    path: \/readyz\n    port: 8080\n  periodSeconds: 5\n  timeoutSeconds: 2\n  failureThreshold: 2\n  successThreshold: 1<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This example checks <code>\/readyz<\/code> every five seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two consecutive failures cause the readiness check to fail. One successful probe is enough to recover because <code>successThreshold<\/code> is one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What readiness failure should not do<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A temporary readiness failure should not automatically restart a healthy application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a service may temporarily lose its connection to a required database. The application process may still be healthy, but it cannot complete requests correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A readiness check can prevent that instance from receiving normal traffic until the dependency recovers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, do not include every optional dependency in readiness. Decide which dependencies are essential to serving the application&#8217;s actual requests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. How a Liveness Probe Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A liveness probe checks whether an application is still able to make progress.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is useful when a process can remain running but enter an unrecoverable state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Examples include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An application thread becomes permanently stuck.<\/li>\n\n\n\n<li>An internal deadlock prevents requests from completing.<\/li>\n\n\n\n<li>A worker process stops making progress.<\/li>\n\n\n\n<li>An internal state becomes corrupted and requires a restart.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When the liveness probe fails enough times in a row, the kubelet terminates the container. The container is then handled according to the Pod&#8217;s restart policy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example liveness probe<\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">livenessProbe:\n  httpGet:\n    path: \/livez\n    port: 8080\n  periodSeconds: 5\n  timeoutSeconds: 2\n  failureThreshold: 3<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">With this configuration, three consecutive failed checks cause Kubernetes to restart the container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The exact restart time depends on probe scheduling, timeouts, and container termination behaviour. Do not treat the multiplication of interval and threshold as an exact stopwatch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A critical liveness mistake<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Do not make liveness depend on every external service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine that all application Pods use the same database. The database becomes temporarily unavailable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If every Pod&#8217;s liveness endpoint fails because the database is unavailable, Kubernetes may restart all the Pods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This does not repair the database. It can increase the recovery workload and make the application less stable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A useful design is:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Liveness checks whether the application process itself can make progress.<\/li>\n\n\n\n<li>Readiness checks whether the application can currently serve its required workload.<\/li>\n\n\n\n<li>Dependency failures should be handled through appropriate timeouts, circuit breakers, retry rules, and readiness behaviour.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes explicitly warns that poorly designed liveness probes can lead to cascading failures under load.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. How a Startup Probe Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A startup probe checks whether an application has completed its initial startup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is especially useful for applications that need time to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Load large configuration files.<\/li>\n\n\n\n<li>Initialise application components.<\/li>\n\n\n\n<li>Warm caches.<\/li>\n\n\n\n<li>Load machine-learning models.<\/li>\n\n\n\n<li>Perform required startup checks.<\/li>\n\n\n\n<li>Complete controlled database initialization.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When a startup probe is configured, Kubernetes does not begin liveness or readiness probing until the startup probe succeeds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This prevents a slow application from being restarted by an overly aggressive liveness check during initialization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example startup probe<\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">startupProbe:\n  httpGet:\n    path: \/startupz\n    port: 8080\n  periodSeconds: 5\n  timeoutSeconds: 2\n  failureThreshold: 12<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The configured failure window is approximately:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Startup allowance = failureThreshold \u00d7 periodSeconds<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this example:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">12 \u00d7 5 = 60 seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The application gets roughly 60 seconds of startup-probe failure tolerance before Kubernetes treats startup as failed. Actual timing can vary because of probe scheduling and timeouts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the startup probe succeeds, it stops running. Liveness and readiness probes then take over.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is important: a startup probe is not a replacement for ongoing readiness and liveness checks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Readiness vs Liveness vs Startup: Practical Comparison<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Behaviour<\/th><th>Readiness<\/th><th>Liveness<\/th><th>Startup<\/th><\/tr><tr><td>Checks application availability<\/td><td>Yes<\/td><td>Checks process health<\/td><td>Checks initial startup<\/td><\/tr><tr><td>Runs throughout container lifecycle<\/td><td>Yes<\/td><td>After startup succeeds, when configured<\/td><td>Only until first success<\/td><\/tr><tr><td>Can make Pod unready<\/td><td>Yes<\/td><td>Not its primary function<\/td><td>Before startup succeeds, Pod is not ready<\/td><\/tr><tr><td>Can restart container<\/td><td>No<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>Handles slow initialization<\/td><td>Can help<\/td><td>Not its purpose<\/td><td>Main purpose<\/td><\/tr><tr><td>Useful for temporary overload<\/td><td>Often<\/td><td>Usually not<\/td><td>No<\/td><\/tr><tr><td>Detects unrecoverable deadlock<\/td><td>Not reliably<\/td><td>Yes, when correctly designed<\/td><td>No<\/td><\/tr><tr><td>Controls normal Service traffic<\/td><td>Yes<\/td><td>Indirectly through container health<\/td><td>Delays readiness until startup passes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A common production configuration uses all three probes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This provides separate controls for initialization, ongoing health, and traffic eligibility.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Understand Probe Mechanisms<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes supports four main probe mechanisms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">HTTP GET probe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The kubelet sends an HTTP GET request to the Pod IP address and configured port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The probe succeeds when the response status is between 200 and 399.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">readinessProbe:\n  httpGet:\n    path: \/readyz\n    port: 8080<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">HTTP probes are useful for web applications and APIs that expose dedicated health endpoints.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">TCP socket probe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The kubelet attempts to open a TCP connection to the configured port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">livenessProbe:\n  tcpSocket:\n    port: 8080\n  periodSeconds: 10<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">A successful connection shows that something is listening on the port. It does not prove that the application can process business requests correctly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exec probe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes runs a command inside the container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">readinessProbe:\n  exec:\n    command:\n      - sh\n      - -c\n      - test -f \/tmp\/ready<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The probe succeeds when the command exits with status code zero.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Exec probes are useful for checks based on local files or process state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, they create a process for each execution. Frequent exec probes across many containers can add CPU overhead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">gRPC probe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A gRPC probe checks an application&#8217;s gRPC Health Checking Protocol endpoint.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">livenessProbe:\n  grpc:\n    port: 50051<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The health service must return the <code>SERVING<\/code> status for the probe to succeed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Built-in gRPC probes became stable in Kubernetes v1.27. They do not support named ports or probe-level authentication configuration. Review the protocol and TLS requirements before using them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Understand the Most Important Probe Settings<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The behaviour of a probe depends on its configuration.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Setting<\/th><th>Meaning<\/th><th>Common default<\/th><\/tr><tr><td><code>initialDelaySeconds<\/code><\/td><td>Time to wait before starting the probe<\/td><td>0 seconds<\/td><\/tr><tr><td><code>periodSeconds<\/code><\/td><td>Time between probe checks<\/td><td>10 seconds<\/td><\/tr><tr><td><code>timeoutSeconds<\/code><\/td><td>Maximum time allowed for one check<\/td><td>1 second<\/td><\/tr><tr><td><code>failureThreshold<\/code><\/td><td>Consecutive failures required to declare failure<\/td><td>3<\/td><\/tr><tr><td><code>successThreshold<\/code><\/td><td>Consecutive successes required to recover after failure<\/td><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A liveness or startup probe must have <code>successThreshold: 1<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Readiness probes can use a higher success threshold when recovery should require several successful checks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example calculation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose a liveness probe uses:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTTP\" data-shcb-language-slug=\"http\"><span><code class=\"hljs language-http\"><span class=\"hljs-attribute\">periodSeconds<\/span>: 5\n<span class=\"hljs-attribute\">failureThreshold<\/span>: 3\n<span class=\"hljs-attribute\">timeoutSeconds<\/span>: 2<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTTP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">http<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The kubelet checks every five seconds. It needs three consecutive failures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The rough configured failure window is:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 \u00d7 5 = 15 seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is not a guaranteed restart time. Probe scheduling, timeouts, and termination grace periods affect the actual result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Choose realistic values<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Very short intervals can create unnecessary load.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Very long intervals can delay fault detection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Choose thresholds based on actual application behaviour, normal startup time, expected response latency, and recovery characteristics.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. Prepare the Failure-Injection Lab<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now test the three probes with a small application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lab demonstrates:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>A slow startup.<\/li>\n\n\n\n<li>A readiness endpoint failure.<\/li>\n\n\n\n<li>A liveness endpoint failure that triggers a restart.<\/li>\n\n\n\n<li>An intentionally unsuitable startup threshold.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Lab requirements<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A working Kubernetes cluster.<\/li>\n\n\n\n<li><code>kubectl<\/code> configured for that cluster.<\/li>\n\n\n\n<li>Permission to create Deployments, Services, ConfigMaps, and Namespaces.<\/li>\n\n\n\n<li>Ability to download the Python container image.<\/li>\n\n\n\n<li>A non-production environment.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The lab uses one replica and a small HTTP server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file named:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>probe-lab.yaml<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It will contain a ConfigMap, Deployment, and Service.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the application<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The application provides three health endpoints:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/startupz<\/code> returns failure during its simulated 20-second initialization.<\/li>\n\n\n\n<li><code>\/readyz<\/code> returns failure when a marker file exists.<\/li>\n\n\n\n<li><code>\/livez<\/code> returns failure for three probe requests after failure injection.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Use this ConfigMap:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">apiVersion: v1\nkind: Namespace\nmetadata:\n  name: probe-lab\n---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: probe-demo-app\n  namespace: probe-lab\ndata:\n  server.py: |\n    from http.server import BaseHTTPRequestHandler, HTTPServer\n    from pathlib import Path\n    import time\n\n    TMP = Path(\"\/tmp\")\n    STARTED_AT = time.monotonic()\n    STARTUP_DELAY = 20\n\n    class Handler(BaseHTTPRequestHandler):\n        def do_GET(self):\n            path = self.path.split(\"?\", 1)&#91;0]\n            healthy = False\n\n            if path == \"\/startupz\":\n                healthy = (\n                    time.monotonic() - STARTED_AT &gt;= STARTUP_DELAY\n                )\n\n            elif path == \"\/readyz\":\n                healthy = not (TMP \/ \"ready.fail\").exists()\n\n            elif path == \"\/livez\":\n                marker = TMP \/ \"live-fail-count\"\n\n                if marker.exists():\n                    try:\n                        remaining = int(marker.read_text().strip())\n                    except (ValueError, OSError):\n                        remaining = 0\n\n                    if remaining &gt; 0:\n                        if remaining == 1:\n                            marker.unlink(missing_ok=True)\n                        else:\n                            marker.write_text(str(remaining - 1))\n\n                        healthy = False\n                    else:\n                        marker.unlink(missing_ok=True)\n                        healthy = True\n                else:\n                    healthy = True\n\n            elif path == \"\/\":\n                healthy = True\n\n            self.send_response(200 if healthy else (\n                404 if path not in &#91;\n                    \"\/startupz\", \"\/readyz\", \"\/livez\", \"\/\"\n                ] else 500\n            ))\n            self.end_headers()\n            self.wfile.write(\n                b\"healthy\" if healthy else b\"unhealthy\"\n            )\n\n        def log_message(self, format, *args):\n            pass\n\n    HTTPServer((\"0.0.0.0\", 8080), Handler).serve_forever()<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The three endpoints deliberately have different behaviour.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The startup endpoint simulates an application that needs time to initialize. The readiness endpoint allows you to withdraw the Pod from normal Service traffic. The liveness endpoint provides three consecutive failures and then removes its failure marker, allowing the restarted container to recover.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a teaching application, not a production health-check implementation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create the Deployment<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add this Deployment to the same YAML file:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: probe-demo\n  namespace: probe-lab\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: probe-demo\n  template:\n    metadata:\n      labels:\n        app: probe-demo\n    spec:\n      automountServiceAccountToken: false\n      securityContext:\n        fsGroup: 10001\n      containers:\n        - name: web\n          image: python:3.12-slim\n          imagePullPolicy: IfNotPresent\n          command:\n            - python\n            - \/app\/server.py\n          ports:\n            - name: http\n              containerPort: 8080\n\n          startupProbe:\n            httpGet:\n              path: \/startupz\n              port: http\n            periodSeconds: 5\n            timeoutSeconds: 2\n            failureThreshold: 12\n\n          readinessProbe:\n            httpGet:\n              path: \/readyz\n              port: http\n            periodSeconds: 5\n            timeoutSeconds: 2\n            failureThreshold: 2\n            successThreshold: 1\n\n          livenessProbe:\n            httpGet:\n              path: \/livez\n              port: http\n            periodSeconds: 5\n            timeoutSeconds: 2\n            failureThreshold: 3\n\n          resources:\n            requests:\n              cpu: 50m\n              memory: 64Mi\n            limits:\n              cpu: 250m\n              memory: 128Mi\n\n          securityContext:\n            runAsNonRoot: true\n            runAsUser: 10001\n            allowPrivilegeEscalation: false\n            readOnlyRootFilesystem: true\n\n          volumeMounts:\n            - name: app\n              mountPath: \/app\n              readOnly: true\n            - name: tmp\n              mountPath: \/tmp\n\n      volumes:\n        - name: app\n          configMap:\n            name: probe-demo-app\n        - name: tmp\n          emptyDir: {}<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The application runs as a non-root user. Its application file is mounted read-only. The temporary volume allows the lab to create failure markers without making the container&#8217;s root filesystem writable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create the Service<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the Service:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">---\napiVersion: v1\nkind: Service\nmetadata:\n  name: probe-demo\n  <span class=\"hljs-keyword\">namespace<\/span>: <span class=\"hljs-title\">probe<\/span>-<span class=\"hljs-title\">lab<\/span>\n<span class=\"hljs-title\">spec<\/span>:\n  <span class=\"hljs-title\">selector<\/span>:\n    <span class=\"hljs-title\">app<\/span>: <span class=\"hljs-title\">probe<\/span>-<span class=\"hljs-title\">demo<\/span>\n  <span class=\"hljs-title\">ports<\/span>:\n    - <span class=\"hljs-title\">name<\/span>: <span class=\"hljs-title\">http<\/span>\n      <span class=\"hljs-title\">port<\/span>: 80\n      <span class=\"hljs-title\">targetPort<\/span>: <span class=\"hljs-title\">http<\/span>\n  <span class=\"hljs-title\">type<\/span>: <span class=\"hljs-title\">ClusterIP<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The Service selects the Pod using the <code>app: probe-demo<\/code> label.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes uses readiness to determine whether the Pod should receive normal traffic through this Service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">9. Deploy the Lab and Test Startup Behaviour<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apply the YAML:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">kubectl<\/span> <span class=\"hljs-selector-tag\">apply<\/span> <span class=\"hljs-selector-tag\">-f<\/span> <span class=\"hljs-selector-tag\">probe-lab<\/span><span class=\"hljs-selector-class\">.yaml<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Watch the Pod:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">During the simulated initialization, the Pod should remain not ready.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After approximately 20 seconds, the application begins returning success from <code>\/startupz<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The startup probe should succeed. Kubernetes can then begin the readiness and liveness checks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Expected progression:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Stage<\/th><th>Expected behaviour<\/th><\/tr><tr><td>Container starts<\/td><td>Application begins its initialization<\/td><\/tr><tr><td>First startup checks<\/td><td><code>\/startupz<\/code> returns HTTP 500<\/td><\/tr><tr><td>Initialization completes<\/td><td><code>\/startupz<\/code> returns HTTP 200<\/td><\/tr><tr><td>Startup probe succeeds<\/td><td>Readiness and liveness checks begin<\/td><\/tr><tr><td>Readiness succeeds<\/td><td>Pod becomes ready<\/td><\/tr><tr><td>Liveness succeeds<\/td><td>Container continues running<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the Pod:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect the Pod&#8217;s events:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl describe pod -n probe-lab -l app=probe-demo<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">You should see startup-probe failures during initialization, followed by successful checks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The restart count should normally remain zero during this initial startup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The exact timing depends on when the kubelet schedules its first probe.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">10. Failure Injection 1: Make the Readiness Probe Fail<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now simulate a temporary application condition where the process is healthy but cannot accept normal traffic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>kubectl exec<\/code> to create the readiness failure marker:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl exec -n probe-lab deploy\/probe-demo -- python -c <span class=\"hljs-string\">\"from pathlib import Path; Path('\/tmp\/ready.fail').touch()\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Watch the Pod:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">After the configured readiness failures, you should see the Pod become not ready.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The container should remain running.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the Pod:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect its Service endpoints:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> endpointslices \\\n  -n probe-lab \\\n  -l kubernetes.io\/service-name=probe-demo \\\n  -o yaml<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Look at the endpoint&#8217;s <code>conditions.ready<\/code> field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The endpoint should be marked not ready while the readiness check fails.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Restore readiness<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Remove the marker:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl exec -n probe-lab deploy\/probe-demo -- python -c <span class=\"hljs-string\">\"from pathlib import Path; Path('\/tmp\/ready.fail').unlink(missing_ok=True)\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Watch the Pod again:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The readiness probe should succeed again, allowing the Pod to become ready.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What this experiment proves:<\/strong> Readiness failure removes the Pod from normal Service traffic without requiring a container restart.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">11. Failure Injection 2: Trigger a Liveness Restart<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now simulate a process-health problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a marker that causes the next three liveness requests to fail:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl exec -n probe-lab deploy\/probe-demo -- python -c <span class=\"hljs-string\">\"from pathlib import Path; Path('\/tmp\/live-fail-count').write_text('3')\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Watch the Pod:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The liveness endpoint fails three consecutive requests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes should restart the container after the configured failure threshold is reached.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the Pod&#8217;s restart count:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">You can inspect the individual container status:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pod -n probe-lab -l app=probe-demo \\\n  -o jsonpath='{.items&#91;<span class=\"hljs-number\">0<\/span>].status.containerStatuses&#91;<span class=\"hljs-number\">0<\/span>].restartCount}<span class=\"hljs-string\">'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect recent events:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl describe pod -n probe-lab -l app=probe-demo<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">After the restart, the application performs its simulated 20-second startup again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The startup probe protects it while it initializes. Once startup succeeds, the other probes resume.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What this experiment proves:<\/strong> A liveness failure can restart the container, and a startup probe can protect the restarted application during initialization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The failure marker is deliberately limited to three requests. This prevents the lab from repeatedly triggering liveness failures after recovery.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">12. Failure Injection 3: Misconfigure the Startup Probe<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now test what happens when the startup allowance is too short.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The application needs approximately 20 seconds to initialize.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its current startup configuration allows 12 failures at five-second intervals. That provides a roughly 60-second failure window.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this experiment, reduce the threshold to two.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run this patch:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl patch deployment probe-demo \\\n  -n probe-lab \\\n  --type=<span class=\"hljs-string\">'json'<\/span> \\\n  -p=<span class=\"hljs-string\">'&#91;{\"op\":\"replace\",\"path\":\"\/spec\/template\/spec\/containers\/0\/startupProbe\/failureThreshold\",\"value\":2}]'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This creates a new Deployment revision.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Watch the Pods:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The startup probe will fail before the application completes its simulated initialization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes will restart the container after the configured number of consecutive startup failures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The new container must start its initialization again. It may repeatedly restart while the incorrect threshold remains in place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This demonstrates why startup thresholds must reflect the application&#8217;s actual initialization time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Restore the correct threshold<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Return the startup threshold to 12:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl patch deployment probe-demo \\\n  -n probe-lab \\\n  --type=<span class=\"hljs-string\">'json'<\/span> \\\n  -p=<span class=\"hljs-string\">'&#91;{\"op\":\"replace\",\"path\":\"\/spec\/template\/spec\/containers\/0\/startupProbe\/failureThreshold\",\"value\":12}]'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Watch the rollout:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -w<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">When the updated Deployment starts, allow the application to initialize.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inspect the final state:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> deployment,pods -n probe-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>What this experiment proves:<\/strong> A startup probe must allow enough time for normal initialization. An overly strict threshold can cause repeated restarts even when the application would eventually become healthy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">13. Troubleshoot Failed Kubernetes Probes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When a Pod does not become ready or repeatedly restarts, do not immediately change the threshold.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First identify which probe failed and why.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Useful commands<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check Pod status:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> pods -n probe-lab -o wide<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Describe the Pod:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl describe pod -n probe-lab -l app=probe-demo<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Review current logs:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl logs -n probe-lab deployment\/probe-demo<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Review logs from a previous container instance:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">kubectl logs -n probe-lab \\\n  -l app=probe-demo \\\n  --previous<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Check recent namespace events:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> events -n probe-lab \\\n  --sort-by=.metadata.creationTimestamp<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Inspect endpoint readiness:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> endpointslices \\\n  -n probe-lab \\\n  -l kubernetes.io\/service-name=probe-demo<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Interpret common symptoms<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Symptom<\/th><th>Possible cause<\/th><th>What to inspect<\/th><\/tr><tr><td>Pod is Running but not Ready<\/td><td>Readiness check failing<\/td><td>Probe path, HTTP status, dependencies, EndpointSlice<\/td><\/tr><tr><td>Container restarts repeatedly<\/td><td>Liveness or startup failure, process crash, or other termination<\/td><td>Pod events, restart count, current and previous logs<\/td><\/tr><tr><td>Startup probe keeps failing<\/td><td>Startup threshold is too short, endpoint is wrong, or application never initializes<\/td><td>Startup endpoint, container logs, initialization time<\/td><\/tr><tr><td>Readiness changes repeatedly<\/td><td>Unstable readiness condition or threshold too sensitive<\/td><td>Dependency health, application latency, probe frequency<\/td><\/tr><tr><td>Probe times out<\/td><td>Endpoint is slow or resource constrained<\/td><td>CPU, memory, application latency, timeout value<\/td><\/tr><tr><td>Service does not send traffic to a Pod<\/td><td>Endpoint is not ready or Service selector is incorrect<\/td><td>EndpointSlice conditions, Pod labels, Service selector<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The messages in <code>kubectl describe pod<\/code> are especially important. They help distinguish failed probes from image errors, container crashes, scheduling issues, and other causes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">14. Production Probe Design Recommendations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The lab demonstrates probe mechanics. Production configuration needs more careful design.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Keep health endpoints lightweight<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A probe should not perform expensive operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid triggering a complete database scan or lengthy business transaction for every health request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The endpoint should return a clear result quickly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Separate process health from traffic readiness<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use separate endpoints when the conditions are different.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/startupz<\/code> checks application initialization.<\/li>\n\n\n\n<li><code>\/livez<\/code> checks whether the process can still make progress.<\/li>\n\n\n\n<li><code>\/readyz<\/code> checks whether the application can serve the required workload.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A single endpoint may be suitable for multiple probes in simple applications, but separate endpoints make the intended behaviour clearer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Avoid dependency-driven restart loops.<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A temporary database or API outage should not automatically restart every application container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use readiness for conditions that prevent correct request handling. Use liveness for failures that genuinely require process recovery.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Size startup allowance from evidence<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Measure the application&#8217;s startup time under realistic conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Include slow nodes, cold caches, model loading, configuration retrieval, and expected initialization work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set the startup failure window to cover realistic startup variation, not just the fastest observed startup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Test probes under resource pressure<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A probe can fail because the application is overloaded.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test normal CPU and memory usage, but also run controlled load tests in a separate environment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Monitor whether short timeouts produce false restarts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Protect sensitive health endpoints<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Probe endpoints should reveal only the minimum information required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not expose secrets, environment variables, internal credentials, or detailed dependency information in their responses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Review probe behaviour after deployments<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Application startup behaviour can change after code or configuration changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check probe success, restart counts, readiness transitions, and execution latency after releases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A previously suitable probe threshold may no longer fit a larger application or a new initialization step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">15. Failure-Injection Test Matrix<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use this matrix when testing the same workload in a staging cluster.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Test<\/th><th>Injected condition<\/th><th>Expected result<\/th><th>Evidence to collect<\/th><\/tr><tr><td>Normal startup<\/td><td>Standard initialization<\/td><td>Pod becomes ready<\/td><td>Startup success, zero restarts<\/td><\/tr><tr><td>Slow startup<\/td><td>Delayed initialization<\/td><td>Startup probe allows time<\/td><td>Startup events, restart count<\/td><\/tr><tr><td>Readiness failure<\/td><td>Application cannot accept traffic<\/td><td>Pod becomes unready; container continues<\/td><td>Pod condition, EndpointSlice<\/td><\/tr><tr><td>Readiness recovery<\/td><td>Application becomes available again<\/td><td>Pod returns to Ready<\/td><td>Successful readiness event<\/td><\/tr><tr><td>Liveness failure<\/td><td>Application cannot make progress<\/td><td>Container restarts<\/td><td>Restart count, events<\/td><\/tr><tr><td>Startup misconfiguration<\/td><td>Threshold too short<\/td><td>Repeated startup restarts<\/td><td>Startup events, previous logs<\/td><\/tr><tr><td>Dependency failure<\/td><td>Required dependency unavailable<\/td><td>Readiness reflects serving ability<\/td><td>Dependency metrics, Pod readiness<\/td><\/tr><tr><td>Recovery after restart<\/td><td>Application initializes again<\/td><td>Pod returns to Ready<\/td><td>Startup success, ready condition<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Record the Kubernetes version, image version, probe settings, test time, and observed result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This makes the test repeatable and helps identify changes between application releases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">16. Clean Up the Lab<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After completing the exercises, delete the test namespace:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">delete<\/span> namespace probe-lab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This removes the lab Deployment, Service, ConfigMap, and temporary resources.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Always verify the namespace is gone:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-25\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">kubectl <span class=\"hljs-keyword\">get<\/span> namespaces<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-25\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Do not leave failure-injection resources running in a shared cluster.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What is the main difference between readiness and liveness probes?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Readiness checks whether an application can receive traffic. Liveness checks whether the container should be restarted. A readiness failure does not directly restart the container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does a readiness probe restart a Pod?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A failed readiness probe marks the Pod as not ready for normal Service traffic. The container continues running while Kubernetes keeps checking it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What happens when a liveness probe fails?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After the configured number of consecutive failures, the kubelet terminates the container. The container is then handled according to the Pod&#8217;s restart policy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why do I need a startup probe?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A startup probe gives a slow-starting application time to initialize. Liveness and readiness checks do not begin until startup succeeds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use all three probes together?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. This is a common design for applications that require startup time and also need separate runtime health and traffic-readiness checks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does a TCP probe prove that the application works?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. It proves that a TCP connection can be opened. It does not prove that the application can complete a real request.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What should I use for a Kubernetes web application?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An HTTP probe is often a good choice when the application exposes lightweight, reliable health endpoints. Select separate paths for startup, liveness, and readiness where their conditions differ.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does my Pod restart even though the application works locally?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The probe may use the wrong path or port. It may time out, depend on an unavailable service, or use an unsuitable threshold. Inspect events, logs, and the probe configuration before changing it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Readiness, liveness, and startup probes solve three different Kubernetes problems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Readiness controls traffic eligibility. Liveness provides a recovery mechanism for an unhealthy process. Startup protects applications that need extra initialization time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most reliable way to understand them is to test each behaviour separately.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use an isolated namespace. Inject one failure at a time. Inspect Pod conditions, EndpointSlices, events, and restart counts. Then restore normal behaviour and verify recovery.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A good probe configuration should help an application recover without causing unnecessary restarts or sending traffic to an instance that cannot serve it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction A Kubernetes Pod can show Running while its application is unable to serve requests correctly. An application may still&#8230; <\/p>\n","protected":false},"author":7,"featured_media":3493,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,736,734,735,713,712],"tags":[142,70,760,170,756,747,757,759,26,758],"series":[],"class_list":["post-3492","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-career-growth","category-careers","category-devops","category-devops-careers","category-engineering-culture","tag-devops","tag-devopsschool","tag-failureinjection","tag-kubernetes","tag-kubernetesprobes","tag-kubernetestroubleshooting","tag-livenessprobe","tag-readinessprobe","tag-sre","tag-startupprobe"],"_links":{"self":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/3492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/comments?post=3492"}],"version-history":[{"count":1,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/3492\/revisions"}],"predecessor-version":[{"id":3494,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/3492\/revisions\/3494"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/media\/3493"}],"wp:attachment":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/media?parent=3492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/categories?post=3492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/tags?post=3492"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/series?post=3492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}