<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vasiliy Menshikov on Medium]]></title>
        <description><![CDATA[Stories by Vasiliy Menshikov on Medium]]></description>
        <link>https://medium.com/@menshikovvasiliy65?source=rss-921c3b4ad024------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Vasiliy Menshikov on Medium</title>
            <link>https://medium.com/@menshikovvasiliy65?source=rss-921c3b4ad024------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:02:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@menshikovvasiliy65/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Local Kubernetes Dev — Part 15: Common problems and how to fix them]]></title>
            <link>https://medium.com/@menshikovvasiliy65/local-kubernetes-dev-part-15-common-problems-and-how-to-fix-them-ff9bb75c03c7?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff9bb75c03c7</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 10:31:54 GMT</pubDate>
            <atom:updated>2026-09-13T10:31:54.184Z</atom:updated>
            <content:encoded><![CDATA[<p>“I built the image with docker build, but in k3d it’s ImagePullBackOff. How? The image exists!”</p><p>Because k3d nodes run on containerd, and it’s isolated from your Docker daemon. Docker has the image, the cluster doesn’t. The most disorienting moment for a k3d newcomer, and it’s fixed two ways: k3d image import, or (better) a local registry with the full name k3d-registry.localhost:5000/myapp:dev in the manifest.</p><p>In the new article (part 15) — a field guide to the statuses you hit every week, all diagnosed with the same three commands:<br>• ImagePullBackOff / ErrImagePull (+ the k3d containerd trap);<br>• CrashLoopBackOff (and why logs — previous is the key);<br>• Pending / FailedScheduling;<br>• OOMKilled (137) — and the sneaky node-level OOM inside the Docker VM;<br>• Service is silent: a break in the Service → endpoints → Pod chain (selector / ports / readiness);<br>• Tilt not picking up changes;<br>• k3d/Docker ate the disk.</p><p>Bookmark it: <a href="https://dorokhovich.com/blog/local-k8s-troubleshooting?utm_source=medium&amp;utm_medium=syndication&amp;utm_campaign=local-k8s-troubleshooting">https://dorokhovich.com/blog/local-k8s-troubleshooting?utm_source=medium&amp;utm_medium=syndication&amp;utm_campaign=local-k8s-troubleshooting</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff9bb75c03c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Local Kubernetes Dev — Part 14: Preparing for deployment and CI]]></title>
            <link>https://medium.com/@menshikovvasiliy65/local-kubernetes-dev-part-14-preparing-for-deployment-and-ci-8e69260e1a6c?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e69260e1a6c</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 13:50:28 GMT</pubDate>
            <atom:updated>2026-09-10T13:50:28.802Z</atom:updated>
            <content:encoded><![CDATA[<p>“I pushed a new image under the same :latest, ran kubectl apply — and nothing changed in the cluster.” Why?</p><p>Kubernetes triggers a rollout only if the pod template changed. The line image: myapp:latest didn’t change — so as far as the cluster is concerned there’s nothing to deploy, even though the registry already holds a different image. Worse, on a pod restart latest can pull a new (possibly broken) version — on its own, without a deploy from you. Prod changes versions “all by itself.”</p><p>In the new article (part 14) — the bridge from a fast local loop to a repeatable deploy:<br>• one manifest base + per-environment overlays (Helm values vs Kustomize patches), no copy-paste and no config drift;<br>• why latest in prod is pain, and what to use instead: immutable tags (sha, semver, digest) + docker/metadata-action;<br>• a minimal CI on GitHub Actions: build → push → apply;<br>• an explicit breakdown: what moves from local, what&#39;s prod-only, and what you must NOT drag into prod (Tilt live-update, uvicorn --reload, debug ports);<br>• the three weaknesses of push-based CI (keys in CI, drift, manual rollback) — and why they lead to GitOps.</p><p>Read it: <a href="https://dorokhovich.com/blog/local-k8s-preparing-for-deployment-and-ci?utm_source=medium&amp;utm_medium=syndication&amp;utm_campaign=local-k8s-preparing-for-deployment-and-ci">https://dorokhovich.com/blog/local-k8s-preparing-for-deployment-and-ci?utm_source=medium&amp;utm_medium=syndication&amp;utm_campaign=local-k8s-preparing-for-deployment-and-ci</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e69260e1a6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Local Kubernetes Dev — Part 10: Configuration and secrets]]></title>
            <link>https://medium.com/@menshikovvasiliy65/local-kubernetes-dev-part-10-configuration-and-secrets-49147d0e0ac4?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/49147d0e0ac4</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Mon, 31 Aug 2026 12:33:13 GMT</pubDate>
            <atom:updated>2026-08-31T12:33:13.437Z</atom:updated>
            <content:encoded><![CDATA[<p>“I’m using a Secret — so my password is protected.” Nope.</p><p>A Kubernetes Secret stores values in base64. Many people mistake this for encryption — and happily commit a manifest with a real password to git. But base64 unwraps with a single command:</p><p>echo ‘czNjcjN0’ | base64 -d # → s3cr3t</p><p>So a Secret with a real password in your repo = a leaked password. And git remembers everything: delete the file later and the value still lives on in history.</p><p>In the new article I go through it step by step:<br>• how ConfigMap differs from Secret and why base64 ≠ encryption;<br>• three ways to pass values into a Pod (env, envFrom, volume) and the trap of “I changed the ConfigMap but the Pod still runs on the old env”;<br>• how to avoid committing a secret: templates + .gitignore for local, Sealed Secrets for prod;<br>• how to keep different values for dev and prod without copy-pasting manifests (Kustomize secretGenerator / Helm values);<br>• what actually protects secrets in prod: Encryption at Rest and RBAC (where even list permission on secrets exposes their contents).</p><p>Part 10 of the local Kubernetes series. Read it and stop confusing encoding with encryption: <a href="https://dorokhovich.com/blog/local-k8s-configuration-and-secrets?utm_source=medium&amp;utm_medium=syndication&amp;utm_campaign=local-k8s-configuration-and-secrets">https://dorokhovich.com/blog/local-k8s-configuration-and-secrets?utm_source=medium&amp;utm_medium=syndication&amp;utm_campaign=local-k8s-configuration-and-secrets</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49147d0e0ac4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Tilt’s Live Update Fixed My Kubernetes Dev Loop and Gave Me an Hour a Day Back]]></title>
            <link>https://medium.com/@menshikovvasiliy65/how-tilts-live-update-fixed-my-kubernetes-dev-loop-and-gave-me-an-hour-a-day-back-23159cdc1af8?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/23159cdc1af8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Wed, 12 Aug 2026 13:50:23 GMT</pubDate>
            <atom:updated>2026-08-12T13:50:23.923Z</atom:updated>
            <content:encoded><![CDATA[<p>Change one line of Python. docker build. docker push. kubectl rollout restart. Wait for the pod. Check the logs. Repeat, forty times a day. I actually did the arithmetic on what that ritual was costing me one afternoon, and the number was ugly enough that I nearly gave up developing on Kubernetes entirely. Instead I found Tilt&#39;s Live Update, rebuilt my Kubernetes dev loop around it, and got roughly an hour a day back. This is how that went.</p><h3>Why this bugged me for weeks</h3><p>My team had just moved local development onto a k3d cluster for parity with prod. Good call in principle — and in practice my day looked like this for every single code change to our FastAPI service myapp:</p><pre>docker build -t k3d-registry.localhost:5000/myapp .<br>docker push k3d-registry.localhost:5000/myapp<br>kubectl rollout restart deploy/myapp -n myapp<br>kubectl logs -f deploy/myapp -n myapp   # wait, watch, hope</pre><p>A minute or two, minimum, per edit. Ten edits and half an hour of my life had dissolved into progress bars. But the raw time wasn’t even the worst of it — the <em>context switching</em> was. By the time the pod finally came up, I’d forgotten what I was checking in the first place. Kubernetes had taken my tight, genuinely joyful edit-run loop and turned it into molasses, and I could feel my patience for the whole platform draining by the day.</p><p>I was one bad afternoon away from ripping the app back out of the cluster — and throwing away all the parity we’d just bought — when I came across a write-up on <a href="https://dorokhovich.com/blog/local-k8s-tilt-fast-dev-loop?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-tilt-fast-dev-loop">using Tilt for a fast local Kubernetes dev loop</a>. It described the exact pain I was drowning in, and it gave me a way out.</p><h3>The three-line Tiltfile that started it</h3><p>Tilt’s config is a file called Tiltfile (no extension) written in Starlark, which is basically a trimmed-down Python. Run tilt up and it executes top to bottom, builds a graph of what to build and deploy, then watches your files and rebuilds only what changed. My first working version was almost embarrassingly short:</p><pre># Tiltfile</pre><pre># How to build the myapp image from the current directory<br>docker_build(&#39;k3d-registry.localhost:5000/myapp&#39;, &#39;.&#39;)</pre><pre># What to deploy — our existing manifests<br>k8s_yaml([&#39;k8s/deployment.yaml&#39;, &#39;k8s/service.yaml&#39;])</pre><pre># Fine-tuning: forward the container&#39;s port 8080 to localhost:8080<br>k8s_resource(&#39;myapp&#39;, port_forwards=&#39;8080:8080&#39;)</pre><p>Three functions carry almost any Tiltfile, all documented in <a href="https://docs.tilt.dev/api.html">Tilt’s API reference</a>: docker_build for <em>how</em> to build, k8s_yaml for <em>what</em> to deploy, and k8s_resource for the fine-tuning like port-forwards and grouping. The clever bit is how Tilt ties them together - it scans the YAML, finds the workload, matches the built image to the manifest <em>by tag</em>, swaps in a uniquely-tagged fresh build, and deploys. The one rule I had to internalize immediately: the tag in docker_build must exactly match the image: in deployment.yaml. Mismatch it and Tilt cheerfully builds one image while the Deployment asks for another - instant ImagePullBackOff, and a confusing ten minutes before you realize what you did.</p><p>After tilt up, my service was live at localhost:8080 with no manual kubectl port-forward. Already better. But the real prize came next.</p><h3>Live Update: the feature that gave me my day back</h3><p>This is the part that actually changed things. The normal rebuild-image-then-redeploy-pod cycle takes tens of seconds even for a tiny service — Docker layers, registry push, cluster pull, pod restart, all of it. <strong>Live Update</strong> skips the whole dance: instead of rebuilding, Tilt copies changed files <em>directly into the running container</em> and, if needed, runs commands there. Seconds, not minutes.</p><p>You configure it inside docker_build via live_update, and the steps run in a strict order:</p><pre>docker_build(<br>    &#39;k3d-registry.localhost:5000/myapp&#39;,<br>    &#39;.&#39;,<br>    live_update=[<br>        # if deps change, just rebuild the whole image<br>        fall_back_on([&#39;requirements.txt&#39;]),<br>        # sync code instantly into /code/app (the WORKDIR from our Dockerfile)<br>        sync(&#39;./app&#39;, &#39;/code/app&#39;),<br>        # reinstall deps only if that file changed<br>        run(&#39;pip install -r requirements.txt&#39;, trigger=[&#39;requirements.txt&#39;]),<br>    ],<br>)</pre><p>Tilt’s decision tree is refreshingly simple, and <a href="https://docs.tilt.dev/live_update_reference.html">the Live Update reference</a> spells out the exact ordering: a fall_back_on file changed means a full rebuild; a file matched by a sync gets a fast live update; a file in the context but covered by no sync triggers a full docker build; an untracked file does nothing. Two rules tripped me up until I read them twice. sync paths must live inside the build context - if Tilt is watching it, you can sync it - and run() cannot come before sync(), because you have to put the files in place before you act on them. Also worth knowing: the very first deploy is always a full one, since Live Update needs an already-running container to copy into.</p><h3>Hot reload closes the loop</h3><p>Live Update drops the new file into the container, but how does the running process actually pick it up? For us, delightfully, FastAPI via uvicorn hot-reloads on its own. The launch command:</p><pre>uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload --reload-dir app</pre><p>Per <a href="https://github.com/Kludex/uvicorn/blob/main/docs/settings.md">uvicorn’s settings docs</a>, --reload runs an internal watcher that restarts the process when .py files change, and --reload-dir app narrows the watch so it doesn&#39;t twitch on every temp file. So when your framework self-reloads, sync alone is enough: files land in the container, uvicorn&#39;s watcher notices, the app reloads, and there&#39;s nothing else to wire up.</p><p>If your stack <em>can’t</em> hot-reload — a Go binary, or uvicorn without --reload - the synced files just sit there while the old process runs stale code, which is the classic &quot;my changes didn&#39;t apply&quot; trap that&#39;ll cost you an afternoon of confusion. For that case, <a href="https://github.com/tilt-dev/tilt-extensions/tree/master/restart_process">Tilt&#39;s </a><a href="https://github.com/tilt-dev/tilt-extensions/tree/master/restart_process">restart_process extension</a> gives you docker_build_with_restart, which re-runs your entrypoint after each sync. For our FastAPI service plain --reload was simpler, and since it&#39;s dev-only, we never ship --reload in the production image.</p><h3>The dashboard I didn’t know I needed</h3><p>tilt up also brings up a web UI at localhost:10350, and it quietly ended my tab-juggling. On one screen I get every resource with two statuses - did the build and deploy succeed, and what is the pod doing <em>right now</em> - along with the Pod ID behind a copy button, endpoints as clickable links, and the part I use constantly: filterable logs, by build versus runtime, by level, by keyword. When a pod won&#39;t start, I stopped grep-ing through kubectl logs across three terminals and just filtered the dashboard. There&#39;s a Trigger Update button for manual rebuilds, and a manual mode if you&#39;d rather save often and deploy on demand:</p><pre>trigger_mode(TRIGGER_MODE_MANUAL)<br>k8s_resource(&#39;myapp&#39;, trigger_mode=TRIGGER_MODE_AUTO)  # but keep this one automatic</pre><h3>Is Tilt the only option? My honest take</h3><p>Tilt isn’t alone here — it usually gets compared with Skaffold, from Google, and DevSpace. All three build, deploy, and sync for a fast loop, and the real differences come down to UI-first versus CLI-first and Starlark versus YAML. Tilt bets on the visual dashboard and Live Update; the Starlark config is flexible but a steeper climb than YAML, and it shines for beginners and mixed-experience teams precisely because you can <em>see</em> the whole cluster state. <a href="https://skaffold.dev/docs/filesync/">Skaffold</a> is CLI-only with YAML config, file sync, profiles, and a dedicated skaffold debug - familiar and declarative, but no visual panel. <a href="https://www.devspace.sh/docs/configuration/dev/connections/file-sync">DevSpace</a> is a YAML CLI with two-way sync, reverse port-forward, and dev containers.</p><p>If your team lives in YAML and loves the terminal, Skaffold or DevSpace is a great fit, and I won’t pretend that choice is anything but subjective. For getting a newcomer developing comfortably on Kubernetes, though, the dashboard won it for me — less blind fumbling in the terminal, more actually understanding what’s happening.</p><h3>How it feels now</h3><p>The per-edit time went from a minute or two down to a second or two, and the list of things I run by hand collapsed from build-push-restart-logs to simply saving the file. The image only rebuilds when dependencies change now, not on every keystroke. Logs and status live on one dashboard instead of scattered across N terminals. The port-forward is declared once in the Tiltfile instead of manually re-established every time a pod restarts. And my focus, which used to get shredded on every deploy, stays intact.</p><p>The arithmetic that sold me was blunt: forty edits times roughly ninety seconds saved is about an hour a day I got back, and that’s before you count the context-switching tax, which I suspect was the bigger number anyway. The whole setup took a single afternoon.</p><p>What lingers, though, isn’t the hour. It’s that the pain was never Kubernetes — it was my <em>loop</em>. A tiny Tiltfile, Live Update, and uvicorn’s --reload turned the whole experience from molasses back into the tight edit-run rhythm I&#39;d been quietly grieving, and I got to keep cluster parity while doing it. If you&#39;re still rebuilding images by hand and watching progress bars, that&#39;s the trade I&#39;d make again in a heartbeat: an afternoon of setup for a loop that finally respects your attention.</p><h3>Sources &amp; further reading</h3><ul><li><a href="https://docs.tilt.dev/api.html">Tilt docs — API reference (</a><a href="https://docs.tilt.dev/api.html">docker_build, </a><a href="https://docs.tilt.dev/api.html">k8s_yaml, </a><a href="https://docs.tilt.dev/api.html">k8s_resource)</a></li><li><a href="https://docs.tilt.dev/live_update_reference.html">Tilt docs — Live Update reference (</a><a href="https://docs.tilt.dev/live_update_reference.html">fall_back_on / </a><a href="https://docs.tilt.dev/live_update_reference.html">sync / </a><a href="https://docs.tilt.dev/live_update_reference.html">run ordering)</a></li><li><a href="https://github.com/tilt-dev/tilt-extensions/tree/master/restart_process">Tilt </a><a href="https://github.com/tilt-dev/tilt-extensions/tree/master/restart_process">restart_process extension (</a><a href="https://github.com/tilt-dev/tilt-extensions/tree/master/restart_process">docker_build_with_restart)</a></li><li><a href="https://github.com/Kludex/uvicorn/blob/main/docs/settings.md">Uvicorn — settings (</a><a href="https://github.com/Kludex/uvicorn/blob/main/docs/settings.md">--reload, </a><a href="https://github.com/Kludex/uvicorn/blob/main/docs/settings.md">--reload-dir)</a></li><li><a href="https://skaffold.dev/docs/filesync/">Skaffold docs — File Sync</a></li><li><a href="https://www.devspace.sh/docs/configuration/dev/connections/file-sync">DevSpace docs — Configure File Synchronization</a></li><li><a href="https://dorokhovich.com/blog/local-k8s-tilt-fast-dev-loop?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-tilt-fast-dev-loop">A full Tilt fast-dev-loop walkthrough someone put together</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23159cdc1af8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Stopped Being Scared of Rails Migrations (and Learned to Love Zero-Downtime Deploys)]]></title>
            <link>https://medium.com/@menshikovvasiliy65/how-i-stopped-being-scared-of-rails-migrations-and-learned-to-love-zero-downtime-deploys-f388947f9e31?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/f388947f9e31</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Fri, 31 Jul 2026 09:49:34 GMT</pubDate>
            <atom:updated>2026-07-31T09:49:34.850Z</atom:updated>
            <content:encoded><![CDATA[<p>I used to have a little ritual before every risky deploy: write the up, write a matching down, and tell myself that if anything went wrong I could just roll it back. It was a comfort blanket. And like most comfort blankets, it was hiding the fact that I was cold. This is the story of how I learned that rails zero downtime migrations aren&#39;t about being able to undo things - they&#39;re about designing so you never need to.</p><h3>Why this bugged me for years</h3><p>The migration that finally broke the spell looked completely, boringly safe in review. It added a compound index to speed up product search:</p><pre>class OptimizeProductSearch &lt; ActiveRecord::Migration[7.0]<br>  def up<br>    add_index :products, [:category_id, :price, :created_at],<br>              name: &#39;idx_products_category_price_date&#39;<br>  end</pre><pre>  def down<br>    remove_index :products, name: &#39;idx_products_category_price_date&#39;<br>  end<br>end</pre><p>The up built the index over 15-45 minutes under shared locks - slow queries, a sad p95, but survivable. The trap was the down. When a deploy went sideways and the pipeline cheerfully auto-rolled-back, the DROP INDEX grabbed an <strong>exclusive lock</strong> for a few seconds. On our busiest table, that was a brief but total outage. Sit with that for a second: the rollback - the thing I&#39;d added specifically to keep us safe - <em>was</em> the incident. I found <a href="https://dorokhovich.com/blog/rails-database-schema-evolution?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=rails-database-schema-evolution">a writeup that argues exactly this point</a>, that in high-load systems a rollback-first mindset manufactures the worst failure modes, and reading it was a little embarrassing, because it named a thing I&#39;d been doing to myself for years.</p><p>Once I saw it, I saw it everywhere. Dropping an index or column freezes the fast path with exclusive locks at exactly the moment traffic is highest. Data migrations lose information, so recreating the original is wishful thinking. Rolling code back while the DB is half-migrated leaves a ghost state nobody can reason about mid-incident. And teams that fear schema changes quietly stop shipping the refactors they actually need — which is the slow, invisible cost that hurts most.</p><p>The irreversibility one deserves a concrete example, because people underestimate it. We had a migration that normalized free-form addresses into city, country, and postal_code, then dropped the original address column. The down gamely tried to reconstruct the address by string-joining the pieces back together - but the formatting, the ordering, the apartment numbers were simply gone. That migration was irreversible without data loss, full stop. Writing a fantasy down for it was worse than useless; it handed me false confidence I&#39;d cash in at the worst possible time.</p><h3>The thing that finally clicked</h3><p>The fix turned out to be a discipline, not a gem. It’s what Martin Fowler calls <a href="https://martinfowler.com/bliki/ParallelChange.html">Parallel Change</a>, and what database folks call expand and contract. Every change becomes a little sequence of small, individually-deployable steps, each one compatible with the app version before it. You <strong>expand</strong> — add new structures without blocking, and leave the old ones alone. You <strong>migrate</strong> — backfill, dual-write, move reads over gradually. Then you <strong>contract</strong> — remove the legacy stuff, but only after a full compatibility window has passed.</p><p>That compatibility window is the part everyone skips and everyone regrets. The new schema has to keep supporting the <em>previous</em> app version for at least one deploy cycle. Do that, and rolling code back is a non-event — the old code still runs perfectly against the expanded schema, no ghost state, no cold sweat. The whole trick is just refusing to collapse those three steps back into one clever migration, no matter how much your inner tidiness gremlin wants you to.</p><h3>Dual-writes are the bridge</h3><p>During the window I write to both the old and new structures, so either app version reads consistent data, and I move reads over slowly:</p><pre>class User &lt; ApplicationRecord<br>  has_many :user_statuses, -&gt; { order(:effective_from) }</pre><pre>  def status=(new_status)<br>    if has_attribute?(:status)<br>      write_attribute(:status, new_status)  # legacy field<br>    end<br>    user_statuses.create!(                  # always maintain the new system<br>      status_type: UserStatus.status_types[new_status] || 0,<br>      effective_from: Time.current<br>    )<br>  end<br>end</pre><p>When touching every write path felt too risky, I leaned on a database trigger to auto-sync legacy writes into the new table for the length of the rollout, then dropped the trigger in the contract phase. Either way the rule is the same, and it’s the whole point: nobody, ever, reads a half-populated new table.</p><h3>Never take a lock you can’t afford</h3><p>The other half of zero-downtime is refusing to grab a lock that’ll hurt. The rule the <a href="https://guides.rubyonrails.org/active_record_migrations.html">Rails migrations guide</a> and strong_migrations both nudge you toward: add nullable columns with no default (fast), backfill asynchronously in batches, then add the NOT NULL constraint in a separate later migration.</p><pre>class AddColumnWithoutDowntime &lt; ActiveRecord::Migration[7.0]<br>  disable_ddl_transaction!</pre><pre>  def up<br>    add_column :large_table, :new_field, :string  # fast, no default<br>    queue_background_migration(&#39;FillNewFieldJob&#39;)  # backfill in batches<br>    # change_column_null later, once backfill completes<br>  end<br>end</pre><p>The background job walks the table in ordered batches and re-enqueues itself until it runs out of rows, so a table with tens of millions of rows never holds one long transaction or a table-wide lock. On Postgres the same instinct means <a href="https://www.postgresql.org/docs/current/sql-createindex.html">building indexes concurrently</a> — CREATE INDEX CONCURRENTLY skips the write-blocking lock, at the cost of a second table scan. Cheap trade. Take it.</p><h3>The rehearsal that ended most of my incidents</h3><p>Here’s the embarrassingly cheap thing that fixed the most pain: I started running migrations against production-sized data in staging before they ever touched production. A change that runs in 40 milliseconds on a seed database can run for 40 minutes against 50 million rows, and there is no way to feel that difference on your laptop. So I’d generate a production-scale dataset, run each pending migration inside a transaction I rolled back for repeatability, and record duration, memory delta, and any blocking queries it kicked off. The output was a short report the team actually read before sign-off. Nine times out of ten the rehearsal caught the problem — a missing concurrent flag, an unbatched backfill — back when it was still boring to fix, which is the only time fixing anything is fun.</p><h3>Make the safety rails automatic</h3><p>Discipline that depends on everyone remembering is discipline that evaporates at 2 AM. So I pushed the rules into tooling. If you’re on Rails, the <a href="https://github.com/ankane/strong_migrations">strong_migrations gem</a> already codifies most of this and is the fastest possible start - it fails the build on unsafe operations and prints the safe rewrite right there in your face. I layered a little duration estimator on top. A CI check refuses the deploy if a recent migration adds a NOT NULL column with no default, creates a blocking index, or is estimated to run long:</p><pre>if total_estimated_time &gt; 300  # 5 minutes<br>  unless ENV[&#39;FORCE_LONG_MIGRATION&#39;] == &#39;true&#39;<br>    puts &#39;Set FORCE_LONG_MIGRATION=true to proceed&#39;<br>    exit 1<br>  end<br>end</pre><p>I also instrument the migrations themselves — subscribing to sql.active_record notifications, logging any migration query over a second and pushing its duration to StatsD, so a slow migration shows up on a dashboard instead of in an incident channel. And before anything risky runs in production, a safety-net step snapshots the affected tables so there&#39;s a credible recovery point. Estimators, circuit breakers around big data migrations, a staging rehearsal task - you build the set once and reuse it across every service, and it pays you back forever.</p><h3>How it feels now</h3><p>Forward-only evolution didn’t just change my migrations, it changed how the deploy button <em>feels</em>. Instead of fear I have a checklist: design for backward compatibility, expand first and contract later, split the scary change into small ones so data migrates asynchronously while reads drift over, and recover forward with fixes and checkpoints instead of fantasy rollbacks. None of it is clever. It’s mostly the willingness to turn one terrifying migration into three boring ones — and I’ve made my peace with boring.</p><p>The part I didn’t expect was cultural. When schema changes stopped being scary, the team stopped avoiding them, and all those long-postponed refactors we’d been quietly routing around finally shipped. That’s the real payoff. If your database changes still page your on-call, start with just two things: the compatibility window, and the pre-deploy check. They’re the two highest-leverage moves, and they’re the ones that let you sleep.</p><h3>Sources &amp; further reading</h3><ul><li>Martin Fowler — Parallel Change (expand and contract): <a href="https://martinfowler.com/bliki/ParallelChange.html">https://martinfowler.com/bliki/ParallelChange.html</a></li><li>strong_migrations — catch unsafe migrations in development (GitHub): <a href="https://github.com/ankane/strong_migrations">https://github.com/ankane/strong_migrations</a></li><li>PostgreSQL — CREATE INDEX, including the CONCURRENTLY option: <a href="https://www.postgresql.org/docs/current/sql-createindex.html">https://www.postgresql.org/docs/current/sql-createindex.html</a></li><li>Rails — Active Record Migrations guide: <a href="https://guides.rubyonrails.org/active_record_migrations.html">https://guides.rubyonrails.org/active_record_migrations.html</a></li><li>A thorough end-to-end zero-downtime schema evolution playbook someone published, estimators and staging rehearsal task included: <a href="https://dorokhovich.com/blog/rails-database-schema-evolution?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=rails-database-schema-evolution">https://dorokhovich.com/blog/rails-database-schema-evolution?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=rails-database-schema-evolution</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f388947f9e31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Bug That Made Me Fall Back in Love With rack.response_finished]]></title>
            <link>https://medium.com/@menshikovvasiliy65/the-bug-that-made-me-fall-back-in-love-with-rack-response-finished-28c89b9ea9fd?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/28c89b9ea9fd</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Thu, 30 Jul 2026 09:42:03 GMT</pubDate>
            <atom:updated>2026-07-30T09:42:03.946Z</atom:updated>
            <content:encoded><![CDATA[<p>There is a particular kind of production bug that doesn’t feel like a bug. It feels like weather. Every few days something leaks, a worker gets cranky, p99 creeps up during a traffic spike, and you shrug and restart it because it clears up on its own. For the better part of a year that was my relationship with rack.response_finished - except I didn&#39;t know that was the name of my problem yet. I just knew our Rails app was quietly bleeding resources and I kept blaming the wrong things.</p><p>This is the story of how it finally clicked, why it bugged me for so long, and how I migrated a high-traffic app to rack.response_finished without spending a single night watching a dashboard with my stomach in knots.</p><h3>Why this bugged me for years</h3><p>Our symptoms were the vague kind that make you feel a little crazy. Occasional resource leaks under load. Tail latency that crept up when traffic spiked and settled back down when it didn’t. Metrics that never quite matched what I believed was happening. We streamed large files and Server-Sent Events, so the Rack triplet [status, headers, body] was returning long before the last byte ever reached the client.</p><p>Here’s the piece I genuinely did not appreciate for months: our middleware was freeing resources — closing DB connections, clearing caches, wiping thread-locals — well before the client had the full response. I found a lovely deep-dive on exactly <a href="https://dorokhovich.com/blog/rack-response-finished?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=rack-response-finished">what happens between returning a Rack triplet and delivering that last byte</a>, and reading it was the moment the fog lifted. All those vague symptoms suddenly had one concrete cause. We’d been treating a lifecycle bug as an infrastructure flake — restarting workers, bumping pool sizes, side-eyeing the load balancer. It was none of that. It was an assumption I’d baked into how we wrapped response bodies, and I’d never once questioned it.</p><h3>The thing I’d been doing without thinking</h3><p>For years, if you wanted a “run this when the request is done” hook, you wrapped the body in <a href="https://www.rubydoc.info/gems/rack/Rack/BodyProxy">Rack::BodyProxy</a>. It&#39;s a tidy little object that calls your block when the wrapped body closes. Elegant on paper. The trouble is every middleware that wanted a callback added its own wrapper, so a single request ended up dragging a Russian-doll stack of proxies around:</p><pre>original_body = [&quot;Hello World&quot;]<br>body = Rack::BodyProxy.new(original_body) { logger.info &quot;Request finished&quot; }<br>body = Rack::BodyProxy.new(body) { metrics.record_latency }<br>body = Rack::BodyProxy.new(body) { cleanup_thread_locals }<br>body = Rack::BodyProxy.new(body) { close_db_connections }</pre><p>The Shopify Rails infrastructure folks wrote up this exact pain in <a href="https://railsatscale.com/2025-08-26-friendship-ended-with-rack-bodyproxy/">“Friendship Ended with Rack::BodyProxy”</a>, and honestly it was validating to read, because it named three things that had been nagging at me.</p><p>First, allocation pressure. Every proxy is one more object. At tens of thousands of requests a second, even tiny per-request allocations add up — and because these callbacks capture closures, the objects hang around long enough to get promoted into older GC generations, which is exactly where you don’t want churn.</p><p>Second, timing you can’t trust. #close gets called by the server, sure, but the spec never promised it happens <em>after</em> the client has everything. Depending on the server and buffering, my callbacks could fire before, during, or after transmission. I was cleaning up at a moment I couldn&#39;t actually pin down.</p><p>Third — and this is the one that was actually paging me at 3am — exceptions skipped cleanup entirely. If the body raised while iterating, the proxy’s callback might just never run:</p><pre>class ProblematicBody<br>  def each<br>    yield &quot;Part 1&quot;<br>    raise &quot;Something went wrong&quot;  # BodyProxy#close might not be called<br>    yield &quot;Part 2&quot;<br>  end<br>end</pre><p>That right there was the leak. A stream raises halfway through a big download, the cleanup silently gets skipped, and the resource just… stays open. Multiply by traffic and you get weather.</p><h3>The thing that finally clicked</h3><p>The replacement is so much calmer, and I mean that emotionally as much as technically. Instead of N proxy objects, there’s one standard key in env holding an array of callbacks:</p><pre>def call(env)<br>  callbacks = env[&quot;rack.response_finished&quot;] ||= []<br>  callbacks &lt;&lt; lambda do |env, status, headers, error|<br>    # Runs AFTER complete response delivery<br>    cleanup_resources<br>    log_metrics(status, headers)<br>  end</pre><pre>  @app.call(env)<br>end</pre><p>What sold me wasn’t the elegance, it was the promise. Unlike BodyProxy#close, these callbacks are guaranteed to run in three cases: a clean finish after all data is sent, an application exception even if the body never started iterating, and a server exception during network trouble. Each callback gets (env, status, headers, error), and per <a href="https://github.com/rack/rack/pull/1952">Rack&#39;s Lint spec</a> they fire in reverse registration order, so you can branch on what actually happened. It shipped as part of <a href="https://github.com/rack/rack/blob/main/CHANGELOG.md">Rack 3.x</a>, and Puma added real server-side support (<a href="https://github.com/puma/puma/pull/3681">puma#3681</a>) so it isn&#39;t a quiet no-op in production.</p><p>The one guarantee I kept coming back to: the callbacks run even when the body raises mid-stream. That single sentence killed my entire class of leaks. I remember reading it and feeling almost annoyed at how simple the fix was.</p><h3>How I migrated without holding my breath</h3><p>I couldn’t flip everything at once — our services spanned Rack versions, and I’m allergic to big-bang changes on infrastructure I can’t fully see. So the critical middleware learned to speak both dialects and pick whichever the server offered:</p><pre>class SafeMigrationMiddleware<br>  def initialize(app)<br>    @app = app<br>  end</pre><pre>  def call(env)<br>    status, headers, body = @app.call(env)</pre><pre>    if env[&quot;rack.response_finished&quot;]<br>      register_new_callback(env)<br>    else<br>      body = wrap_with_proxy(body)  # fallback<br>    end</pre><pre>    [status, headers, body]<br>  end</pre><pre>  private</pre><pre>  def register_new_callback(env)<br>    callbacks = env[&quot;rack.response_finished&quot;] ||= []<br>    callbacks &lt;&lt; method(:cleanup_resources)<br>  end</pre><pre>  def wrap_with_proxy(body)<br>    Rack::BodyProxy.new(body) { cleanup_resources }<br>  end</pre><pre>  def cleanup_resources(*)  # accepts any number of args<br>    logger.info &quot;Request completed&quot;<br>  end<br>end</pre><p>The cleanup_resources(*) splat is on purpose - the new API hands you four arguments, the proxy hands you none, and a splat lets one method serve both paths without a branch. Small thing, but it made the diff read cleanly, which matters to me more than I&#39;ll admit.</p><p>Then I refused to guess. I put a StatsD counter on each path so I could watch, in real numbers, how much traffic had moved to the new mechanism:</p><pre>if env[&quot;rack.response_finished&quot;]<br>  StatsD.increment(&#39;middleware.response_finished.new_api&#39;)<br>  register_new_callback(env)<br>else<br>  StatsD.increment(&#39;middleware.response_finished.fallback&#39;)<br>  body = wrap_with_proxy(body)<br>end</pre><h3>The mistake I almost shipped</h3><p>Callbacks run in the same thread as the request. That makes thread-local cleanup delightful, and it makes slow work a trap. My first draft casually fired off a notification email inside the callback, which is a wonderful way to block a worker for seconds at a time. Fast cleanup belongs in the callback; anything with I/O belongs in a background job:</p><pre># Good: fast cleanup<br>callbacks &lt;&lt; lambda do |env, status, headers, error|<br>  Thread.current[:request_id] = nil<br>  ActiveRecord::Base.clear_active_connections!<br>end</pre><p>Rails itself gets happier here too: ActionDispatch::Executor can now reliably clear thread-locals right after the response completes, and gems like rack-timeout, newrelic_rpm, skylight, and sentry-ruby line up their timing and errors far more accurately.</p><h3>How it feels now</h3><p>I want to be honest about the size of the win, because it’s easy to oversell a refactor you’re proud of. Average latency barely moved — most requests were never the problem. What changed was the <em>shape</em> of things. Objects allocated per request dropped on our streaming endpoints, major GC ran a little less often, and the p99 tail got quieter during spikes because fewer long-lived closures were being promoted into old-gen. And the leak alerts that used to page me during big downloads simply stopped, because the cleanup now runs even when the body raises.</p><p>The order of operations mattered as much as the code. I audited every middleware that touched BodyProxy, bumped Rack to 3.x in development first, shipped the dual-API middleware, and let the StatsD counters tell me when the new path dominated. I only pulled the fallback after a service had run for weeks at effectively 100% new-API with zero callback errors. I left it in longer than felt necessary, on purpose - rushing that last step is exactly how you turn a calm migration into a scary one. Profiling before and after with memory_profiler and ruby-prof gave me actual numbers instead of a vibe, which is the difference between &quot;trust me&quot; and a graph.</p><p>If I could hand one note back to the version of me who kept restarting workers: the leak was never infrastructure. It was an abstraction I’d stopped questioning because it looked so tidy. BodyProxy was elegant right up until it wasn&#39;t, and the replacement is simpler <em>and</em> more honest about what it promises. That combination - less clever, more trustworthy - is the trade I&#39;ll take every single time now. If you run a busy Rack app, start the dual-API pattern today; you get to learn the new mechanism at zero risk, and future-you gets to sleep.</p><h3>Sources &amp; further reading</h3><ul><li>Rack — Add rack.response_finished to Rack::Lint (PR #1952, the spec and reverse-order contract): <a href="https://github.com/rack/rack/pull/1952">https://github.com/rack/rack/pull/1952</a></li><li>Rack CHANGELOG (where rack.response_finished and Rack 3.x changes land): <a href="https://github.com/rack/rack/blob/main/CHANGELOG.md">https://github.com/rack/rack/blob/main/CHANGELOG.md</a></li><li>Puma — Add support for rack.response_finished (server-side implementation, PR #3681): <a href="https://github.com/puma/puma/pull/3681">https://github.com/puma/puma/pull/3681</a></li><li>Rails at Scale — “Friendship Ended with Rack::BodyProxy” (Shopify’s writeup of the same migration): <a href="https://railsatscale.com/2025-08-26-friendship-ended-with-rack-bodyproxy/">https://railsatscale.com/2025-08-26-friendship-ended-with-rack-bodyproxy/</a></li><li>Rack::BodyProxy API documentation (RubyDoc): <a href="https://www.rubydoc.info/gems/rack/Rack/BodyProxy">https://www.rubydoc.info/gems/rack/Rack/BodyProxy</a></li><li>A production migration writeup someone put together, with the full dual-API middleware and monitoring metrics laid out: <a href="https://dorokhovich.com/blog/rack-response-finished?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=rack-response-finished">https://dorokhovich.com/blog/rack-response-finished?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=rack-response-finished</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28c89b9ea9fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Rescued My Broken Local Kubernetes Development Environment in One Afternoon (Docker + k3d +…]]></title>
            <link>https://medium.com/@menshikovvasiliy65/how-i-rescued-my-broken-local-kubernetes-development-environment-in-one-afternoon-docker-k3d-5b23ddaa5ff6?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b23ddaa5ff6</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Wed, 29 Jul 2026 08:26:40 GMT</pubDate>
            <atom:updated>2026-07-29T08:26:40.821Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Rescued My Broken Local Kubernetes Development Environment in One Afternoon (Docker + k3d + Tilt)</h3><p>There’s a specific flavor of shame in a local Kubernetes development environment that only you can’t get working. Everyone else on the team runs kubectl get pods and gets an answer. You run it and get connection refused, again, and you quietly start to wonder if the problem is you. It wasn&#39;t me, it turned out - it was that I&#39;d never actually <em>built</em> the thing, I&#39;d just accreted it. This is the story of how I tore my broken setup down and rebuilt it, deliberately, in a single afternoon.</p><h3>Why this bugged me for years</h3><p>I’d inherited a FastAPI service — Python 3.12, listening on 8080, backed by PostgreSQL — that the team ran on “local Kubernetes.” That phrase meant something different on every laptop, and mine was easily the worst offender. kubectl installed three different ways. A Docker Desktop that half-started on a good day. A helm binary that wasn&#39;t on my PATH. And, crucially, no cluster at all. Every single kubectl command greeted me with the same connection refused, and I&#39;d learned to just... route around it, which is the worst possible response and exactly the one I kept choosing.</p><p>I burned two full mornings guessing. Then I got tired of guessing and followed a single opinionated write-up that treats the workstation itself as the deliverable — the idea being that you’re not done until kubectl get pods -A responds without errors against a real local cluster. That reframing did something to my brain. If you want the full chapter with every OS variant, <a href="https://dorokhovich.com/blog/local-k8s-workstation-setup?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-workstation-setup">someone wrote up the exact workstation setup here</a>, and it&#39;s the map I wish I&#39;d had two mornings earlier.</p><h3>The thing that finally clicked: install bottom-up</h3><p>The mindset shift that fixed everything was embarrassingly simple — install in dependency order. Docker first, because nothing runs without it, then kubectl, k3d, helm, and Tilt last. On my Mac that collapsed to almost one command:</p><pre># Docker Desktop from docker.com (daemon + GUI), then:<br>brew install kubectl helm k3d tilt</pre><p>k3d is the quiet hero of this whole story. It’s just <a href="https://k3d.io/">k3s packaged into Docker containers</a> — k3s being a lightweight, CNCF-certified Kubernetes distribution — so a local cluster is featherweight next to “real” Kubernetes. If you’re agonizing over <strong>k3d vs kind vs minikube</strong>, here’s what decided it for me: k3d spins up a cluster in under five seconds, ships a built-in image registry that Tilt adores, and barely touches RAM, whereas minikube boots a whole VM and <a href="https://kind.sigs.k8s.io/">kind</a> — Kubernetes-IN-Docker, originally built to test Kubernetes itself — sits somewhere in the middle. For a tight inner dev loop I rebuild dozens of times a day, and those saved seconds compound into genuinely real time. The one hard requirement is Docker 20.10.5 or newer; k3d’s <a href="https://github.com/k3d-io/k3d">own repository</a> lists a working Docker install as the sole prerequisite. Everything else is just host headroom — 8 GB of RAM is a comfortable floor, 16 GB means you never think about it, and you’ll want 10 to 20 GB of free disk for images and layers.</p><p>On Linux the shape is identical, except you install Docker Engine with no GUI and you must add yourself to the docker group or every command demands sudo:</p><pre>sudo usermod -aG docker $USER<br># then log out and back in so the group takes effect</pre><p>One caution I learned the hard way: those curl ... | bash installers for k3d, helm, and Tilt are convenient, but you&#39;re piping someone else&#39;s code from the internet straight into a shell. On a work machine I now download the script, skim it, then run it - or reach for the apt/dnf packages the official docs offer for kubectl and helm, which are cleaner to maintain long-term anyway.</p><h3>Naming what each tool actually does</h3><p>Here’s the confession at the heart of this: before that afternoon, I genuinely could not have told you which tool did what, and that fuzziness is exactly why my setup was so fragile. The mental model that finally stuck goes like this. Docker builds images and runs the containers everything else sits inside. k3d spins up the cluster itself — k3s in Docker — and tears it down just as fast. kubectl and helm manage resources and packaged charts inside that cluster. Tilt runs the fast inner dev loop, watching your files and rebuilding and redeploying on every save, and its <a href="https://docs.tilt.dev/tutorial/5-live-update.html">Live Update</a> can even sync changed files straight into a running container, collapsing edit-build-push-deploy into seconds. And k9s is the optional terminal UI that replaces a wall of kubectl commands.</p><p>Once I could name the job of each binary, the errors stopped being mysterious and started being addressable. A connection refused is Docker. A stuck rebuild is Tilt. A missing chart is helm. The abstraction layers finally lined up in my head, and honestly that was more valuable than any single command I learned.</p><h3>The smoke test that ends the guessing</h3><p>This is the part I wish I’d run on day one instead of day three. Rather than debugging four tools in isolation, you prove the whole chain works together at once: create a throwaway cluster, switch to it, look at the system pods, delete it.</p><pre>k3d cluster create dev<br>k3d kubeconfig merge dev --kubeconfig-switch-context<br>kubectl get pods -A<br>k3d cluster delete dev</pre><p>When that kubectl get pods -A printed coredns, traefik, and metrics-server all sitting in Running, I actually said it out loud to my empty room: the workstation was ready. That single sequence is the entire difference between &quot;I think it&#39;s installed&quot; and &quot;I proved it works,&quot; and I&#39;ve never set up a machine without it since. Naming the cluster dev and reusing it later is deliberate too - k3d makes clusters so cheap to create and destroy that a named, reusable dev cluster becomes the stable target for the rest of your toolchain.</p><h3>The gotchas that used to eat my mornings</h3><p>Almost every failure at this stage is one of a small handful of classics, and just running the list saved me hours. The most common by far is simply that the Docker daemon isn’t running — k3d and Tilt both die with connection refused, so start Docker Desktop or sudo systemctl start docker and wait for it to fully come up. After a reboot you may hit port already in use, in which case just recreate the cluster.</p><p>The trickiest one, and the one that bit me hardest, is too many open files. Pods and Tilt both watch files, and they collide with system inotify limits; the symptom shows up as too many open files in pod logs or the kubelet. On a Linux or Docker host the fix is:</p><pre>sudo sysctl fs.inotify.max_user_watches=1048576<br>sudo sysctl fs.inotify.max_user_instances=8192</pre><p>Make it survive reboots by putting those in a file under /etc/sysctl.d/, and as a fallback for stubborn machines you can create a k3d cluster with only a server node and no agents, which cuts the total open files.</p><p>Windows has its own trap: do all your dev work inside WSL2, including the repo itself. A teammate kept the code on C:\ and ran the tools from WSL2, and the result was a crawling filesystem and Tilt file sync that silently refused to trigger uvicorn --reload. Move the repo into the WSL2 home directory and the whole problem evaporates. And two quieter ones round it out - if Docker Desktop refuses to start with a virtualization complaint, enable hardware virtualization (VT-x / AMD-V, plus SLAT for WSL2) in BIOS/UEFI, and if you try to squeeze into 4 GB, expect OOM once PostgreSQL and a few pods pile in. Give Docker 8 GB or more under Settings then Resources and the random pod deaths stop.</p><h3>The little upgrade: k9s made me delete half my muscle memory</h3><p>Instead of hammering kubectl get pods, kubectl describe, and kubectl logs all day, I now open <a href="https://github.com/derailed/k9s">k9s</a> - a terminal UI that continually watches the cluster - and navigate with arrow keys. Logs, restarts, deletes, all from one screen.</p><pre>brew install derailed/k9s/k9s</pre><p>For anyone still finding their feet, it’s a genuinely lovely visual replacement for dozens of repetitive commands, and I felt a small pang deleting keystrokes I’d spent years memorizing.</p><h3>How it feels now</h3><p>The change is night and day, and it’s less about any single number than about the shift from flailing to knowing. What used to be two mornings of guessing is now a checklist-driven afternoon. kubectl get pods -A returns system pods in Running instead of connection refused. Tilt hot reload, which used to be silently broken behind that WSL2 path issue, now fires on every save. Debugging a pod is arrow keys in k9s instead of three kubectl invocations each time. And the biggest one, the one that&#39;s hard to put in a table: I&#39;m actually confident it works now, because I watched the smoke test pass with my own eyes.</p><p>With the toolchain proven, the natural next step is spinning up a real dev cluster for the service — built-in registry, port forwarding, the works — rather than a throwaway. But if you’re setting this up for the first time, please don’t improvise the way I did for two mornings. Install bottom-up, run the smoke test before you touch a line of application code, and keep the gotcha list within reach.</p><p>The thing that genuinely stuck with me is this: a local Kubernetes environment is not “done” when the binaries are installed. It’s done when you’ve <em>watched</em> the smoke test pass. I’d spent years treating my dev environment as something that accreted rather than something I built, and the fix was simply to build it on purpose, prove it, and only then start stacking real work on top. Prove it first. Everything after that is easier.</p><h3>Sources &amp; further reading</h3><ul><li>k3d — k3s in Docker, official documentation: <a href="https://k3d.io/">https://k3d.io/</a></li><li>k3d install requirements and cluster options (GitHub): <a href="https://github.com/k3d-io/k3d">https://github.com/k3d-io/k3d</a></li><li>kind — Kubernetes IN Docker, official documentation: <a href="https://kind.sigs.k8s.io/">https://kind.sigs.k8s.io/</a></li><li>Tilt Live Update tutorial (official docs): <a href="https://docs.tilt.dev/tutorial/5-live-update.html">https://docs.tilt.dev/tutorial/5-live-update.html</a></li><li>k9s — Kubernetes terminal UI (GitHub): <a href="https://github.com/derailed/k9s">https://github.com/derailed/k9s</a></li><li><a href="https://dorokhovich.com/blog/local-k8s-workstation-setup?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-workstation-setup">A full field-tested workstation write-up someone put together</a>, with every OS variant and the complete gotcha list</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b23ddaa5ff6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Local Kubernetes Tools Comparison That Finally Unfroze Me: Stop Comparing Them, Sort Them Onto…]]></title>
            <link>https://medium.com/@menshikovvasiliy65/a-local-kubernetes-tools-comparison-that-finally-unfroze-me-stop-comparing-them-sort-them-onto-bb71da5985df?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb71da5985df</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Tue, 28 Jul 2026 20:38:08 GMT</pubDate>
            <atom:updated>2026-07-28T20:38:08.719Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Local Kubernetes Tools Comparison That Finally Unfroze Me: Stop Comparing Them, Sort Them Onto Shelves</h3><p>Here is the confession I don’t love making: I once lost an entire week to a decision that should have taken an afternoon. My team wanted local Kubernetes, I volunteered to pick our stack, I opened a “getting started” guide, and got hit with an incantation — k3d, kind, minikube, Helm, Kustomize, Tilt, Skaffold, DevSpace, Telepresence, mirrord, k9s. I froze. Every local Kubernetes tools comparison I read stacked a dozen names side by side as if they were rival answers to one question, and I couldn’t pick anything. What eventually unfroze me wasn’t a better comparison — it was realizing they don’t belong on the same shelf.</p><h3>Why this bugged me for a whole week</h3><p>I’m a fairly decisive person, which made the paralysis extra humiliating. I figured picking a stack would be a lazy afternoon of reading. Instead I kept hitting the same wall: do I need k3d <em>or</em> Helm? Is Tilt an alternative to minikube? Where on earth does Telepresence fit? Every post read like one giant menu where everything competed with everything, and I genuinely could not tell whether I was choosing one tool or ten.</p><p>The reframing that saved me came from an <a href="https://dorokhovich.com/blog/local-k8s-tooling-overview?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-tooling-overview">overview of the local Kubernetes tooling landscape someone wrote up</a>: each tool handles its own little piece, and once you sort them onto shelves, the whole picture goes quiet. Let me hand you the shelves, because they cost me a week and they might save you one.</p><h3>The first fork nobody told me about: local cluster vs remote connection</h3><p>Before you compare any specific tool, there’s a bigger split I didn’t even know existed. There are two fundamentally different ways to get a near-production loop. The first is to run all of Kubernetes on your own machine — spin up a small but real cluster locally with k3d, kind, minikube, Docker Desktop, or Rancher Desktop, and deploy with the same manifests you’ll use in prod. Fully local, no network dependency. That’s the path we took. The second is to keep your code local but plug it into a <em>remote</em> cluster, so your local process behaves as if it were a Pod living on staging. That’s the world of Telepresence (which builds a VPN-style tunnel, needs root, and modifies the cluster), mirrord (which injects into your process via LD_PRELOAD or DYLD_INSERT_LIBRARIES, needs no root, and mirrors by default so it&#39;s safe for shared staging), and Gefyra (VPN-based, no root, Docker-only).</p><p>The remote approach is genuinely great, but it needs a live remote cluster to maintain and network access — an extra layer of magic I didn’t want to impose on a team still finding its feet. So: everything local. That one decision alone eliminated three tools from my “must choose now” list, and I felt the paralysis loosen its grip a little.</p><h3>The foundation shelf: Docker and kubectl</h3><p>These sit under everything else. Docker is the container engine, and here’s the fact that surprised half my team: local clusters run their Kubernetes <em>nodes</em> as ordinary Docker containers. A node is a container with Kubernetes inside it, and inside <em>that</em> run your Pods. No Docker, no cluster. kubectl, meanwhile, is the official CLI and your main channel to the cluster — apply manifests, read logs, forward ports, shell in. Every accelerator like Tilt or Skaffold and every visual tool like k9s runs <em>on top of</em> kubectl, calling the same Kubernetes API underneath, so it’s worth actually knowing even if you end up living inside Tilt all day. A small bonus that trips people up: Kustomize is built right into kubectl via kubectl apply -k.</p><h3>The cluster shelf: k3d, kind, minikube, Docker/Rancher Desktop</h3><p>This shelf holds the “box” your app goes into, and all of these give you a real Kubernetes API — they just differ in startup speed, resource appetite, and features. <a href="https://k3d.io/">k3d</a> is a wrapper that runs k3s, a minimal certified Kubernetes, inside Docker; it has the fastest startup, the lowest memory footprint, and a handy built-in registry, which makes it my pick for everyday dev (with the honest caveat that it’s a community project, not an official Rancher/SUSE product). <a href="https://kind.sigs.k8s.io/">kind</a>, Kubernetes IN Docker, runs upstream Kubernetes via kubeadm — CNCF-certified, multi-node and HA capable, and built to test Kubernetes itself and CI conformance. minikube runs Kubernetes in a VM or via a docker driver with a big addon ecosystem and remains the classic learning tool. Docker Desktop offers single-node Kubernetes behind a checkbox, convenient if you already run it but limited in configuration. And Rancher Desktop is a GUI app on k3s for native local dev and testing. The 2025–2026 consensus lands on kind or k3d for the best balance of speed and capability, and k3d in particular starts fast and stays light, which is exactly why it’s so pleasant to recreate constantly while you’re still learning and breaking things.</p><h3>The manifest shelf: Helm and Kustomize</h3><p>Production manifests usually live as Helm charts or Kustomize overlays, and this is the whole reason a local cluster beats docker-compose — it accepts these <em>same</em> formats. <a href="https://helm.sh/docs/">Helm</a> is the Kubernetes package manager: your app becomes a <em>chart</em> with a Chart.yaml, a values.yaml, and a templates/ directory of Go templates, and in return you get versioning, releases, rollbacks, dependencies, and repos. It&#39;s been a <a href="https://www.cncf.io/projects/helm/">CNCF graduated project since 2020</a>. Kustomize takes the opposite bet - no templates at all; you write base manifests and apply <em>overlays</em>, which are patches, per environment. It&#39;s <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/">built into kubectl</a> since 1.14, though on its own it has no packaging, versioning, or rollback, so people bolt on Argo CD or Flux for that. In practice the two complement each other: Helm to package and distribute, Kustomize to tidily patch per environment.</p><h3>The accelerator shelf: Tilt, Skaffold, DevSpace</h3><p>The bare loop — edit, build, push, deploy, look — is excruciatingly slow in Kubernetes, and this shelf exists to automate the building, updating, and watching. Tilt (Apache-2.0) automates watch-build-update, and its signature move is Live Update, syncing changed files straight into the running container without a full rebuild; you configure it in a Tiltfile written in Starlark, a Python-like language, and it ships a genuinely clear web UI that&#39;s a big plus for beginners. Skaffold, from Google, is a build/push/deploy pipeline with file sync, a dedicated skaffold debug command, and profiles, deploying via kubectl, Helm, or Kustomize. DevSpace is a CLI that leans into bidirectional sync, hot reload, and in-cluster dev containers. Two adjacent names worth not confusing with these: Okteto is about cloud dev environments, which is closer to the remote approach, and Garden is graph-based multi-service automation, which is overkill for a single service.</p><h3>The convenience shelf: k9s and friends</h3><p>Once you have more than one Pod, typing kubectl get, logs, and describe all day gets old fast. <a href="https://k9scli.io/">k9s</a> is a terminal UI - a &quot;visual kubectl&quot; - with vim-style navigation, live Pod, node, and deployment views, and hotkeys (l for logs, s for shell, d for describe). My favorite touch: it color-codes contexts, so you can paint prod an alarming red and never wreck it by muscle memory again. Also worth installing when the day comes are kubectx and kubens for fast context and namespace switching, stern for multi-pod log streaming, and krew, the kubectl plugin manager.</p><h3>Why we landed on k3d + Tilt</h3><p>Once the tools were on shelves, the choice basically made itself, because local Kubernetes dev really only has two core pains: you need a realistic cluster that accepts real production manifests, and you need a fast edit-to-result loop. k3d covers the first — a real Kubernetes API via k3s, fast startup, modest memory, so we get genuine parity with our Helm and Kustomize manifests instead of a docker-compose surrogate, and without turning laptops into space heaters. It’s cheap to recreate, which matters enormously while a team is learning. Tilt covers the second — Live Update compresses the loop from minutes to seconds, codifies the whole setup in a Tiltfile, deploys through real manifests, and shows a web UI where builds, logs, and state all live in one place. Together they&#39;re fully local, open source, and free.</p><p>The alternatives are all worthy, and I want to be fair to them: Skaffold and DevSpace solve the same loop and are worth trying if their style fits your team, Telepresence and mirrord are the remote approach if you’d rather lean on a shared cluster, and Okteto and Garden solve adjacent problems entirely. For a single service headed toward its first deploy, k3d + Tilt was simply the shortest, clearest path.</p><h3>How it feels now</h3><p>The before-and-after is almost embarrassing in how much of it was in my head. Before the map, my mental model was “ten rival tools, one agonizing choice,” the decision took a paralyzed week, and the stack stayed stubbornly undecided the whole time. After the map, the tools sat on distinct shelves, the decision collapsed into an afternoon, and I had a stack — k3d + Tilt — that I could actually explain the reasons for.</p><p>What stays with me is <em>why</em> I was stuck, because it wasn’t complexity. I was overwhelmed because I kept comparing a cluster to a package manager to a file-syncer as though they answered the same question, and they simply don’t. The moment I stopped ranking them and started sorting them — foundation, cluster, manifest, accelerator, remote, convenience — the choice made itself. If you’re standing at the same frozen starting line, don’t reach for one more comparison table. Reach for shelves. That reframing is the thing I’d hand back to the paralyzed version of me who lost a week he didn’t need to.</p><h3>Sources &amp; further reading</h3><ul><li><a href="https://k3d.io/">k3d — k3s in Docker</a></li><li><a href="https://kind.sigs.k8s.io/">kind — Kubernetes IN Docker</a></li><li><a href="https://helm.sh/docs/">Helm docs — the Kubernetes package manager</a></li><li><a href="https://www.cncf.io/projects/helm/">CNCF — Helm (graduated project)</a></li><li><a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/">Kubernetes docs — Managing objects with Kustomize (built into kubectl)</a></li><li><a href="https://k9scli.io/">k9s — a terminal UI for Kubernetes</a></li><li><a href="https://dorokhovich.com/blog/local-k8s-tooling-overview?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-tooling-overview">A full local-k8s tooling overview someone put together</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb71da5985df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Kubernetes Inner Dev Loop That Was Quietly Eating My Sprint — and How I Got Back to Seconds]]></title>
            <link>https://medium.com/@menshikovvasiliy65/the-kubernetes-inner-dev-loop-that-was-quietly-eating-my-sprint-and-how-i-got-back-to-seconds-061b1732fcb9?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/061b1732fcb9</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Sun, 26 Jul 2026 20:10:17 GMT</pubDate>
            <atom:updated>2026-07-26T20:10:17.691Z</atom:updated>
            <content:encoded><![CDATA[<p>For about six months, my Kubernetes inner dev loop was a productivity black hole, and I mean that almost literally: time went in and nothing came out. I was the backend person on a small payments squad, and I got to the point where I quietly dreaded touching the cluster at all. This is the story of what was actually wrong, why it bugged me for so long, and the setup that finally gave me back a dev loop measured in seconds instead of minutes.</p><h3>Why this bugged me for so long</h3><p>Our service — I’ll just call it myapp, a FastAPI HTTP API on port 8080 backed by PostgreSQL - ran beautifully on a laptop. uvicorn --reload picked up every change in a fraction of a second, the way good local dev should feel. Then we &quot;just&quot; shipped it to Kubernetes, and the instant loop turned into this:</p><pre># 1. build the image<br>docker build -t registry.internal/myapp:dev .<br># 2. push to the registry<br>docker push registry.internal/myapp:dev<br># 3. apply the manifests<br>kubectl apply -f k8s/<br># 4. wait for the new Pod and check it&#39;s alive<br>kubectl rollout status deployment/myapp<br>kubectl logs -f deployment/myapp</pre><p>Four steps that simply did not exist when we ran things locally. Every single pass was two to five minutes of build, push, wait, check. Multiply that by dozens of iterations a day across the team and you get whole afternoons of people staring at kubectl rollout status. And here&#39;s the part that really got under my skin: the wait was juuust long enough that I&#39;d flip to Slack every time. So the true cost was never the four minutes. It was the train of thought that derailed on every deploy, and never quite got back on the rails.</p><p>A slow loop is only half the misery, though. The other half is the bugs you genuinely cannot see on a laptop. We shipped a change that passed every local test and then watched the Pod get <strong>OOMKilled</strong> in staging, because we’d never set a memory limit locally — memory is effectively infinite on a dev box. Another release sat there “running but not responding” because a <strong>readiness probe</strong> was failing and Kubernetes had quietly yanked the Pod out of the Service endpoints. Nothing in my local world had prepared me for either.</p><h3>The idea that reframed everything: shift-left, but with fidelity</h3><p>I got tired of band-aids and went looking for a systematic answer. Someone had written up <a href="https://dorokhovich.com/blog/local-k8s-inner-dev-loop?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-inner-dev-loop">exactly why the Kubernetes inner loop gets slow and how to close the local-versus-cluster gap</a>, and it put a name to the thing I’d been feeling in my gut: the more your test environment differs from prod, the more bugs leak downstream, where each one costs an order of magnitude more to fix.</p><p>The line that really stuck with me was this — testing earlier in a CI container that doesn’t match your cluster <em>isn’t</em> shift-left. It’s just failing faster in the wrong environment. Real shift-left for Kubernetes means validating against real cluster conditions: real resource limits, real probes, real services in the namespace, early, on your own machine. That reframed the whole problem for me, and it pointed at two concrete tools instead of a vague “do better.”</p><p>The first is <strong>k3d</strong>, <a href="https://github.com/k3d-io/k3d">a lightweight wrapper that runs CNCF’s k3s inside Docker</a>. Not an emulation of a cluster — an actual one, small enough to live on a laptop. The second is <strong>Tilt</strong>, whose <a href="https://docs.tilt.dev/tutorial/5-live-update.html">live-update performs an in-place update of the containers in your cluster</a>, syncing your code straight into a running Pod so iteration drops back to seconds.</p><h3>What I actually rolled out</h3><p>I named the cluster dev, put everything in a myapp namespace, and used k3d&#39;s built-in registry at k3d-registry.localhost:5000. My first lesson landed the hard way: <strong>the local cluster cannot see images from your local Docker daemon.</strong> I built myapp:dev, expected the cluster to pick it up, and got a Pod wedged in ImagePullBackOff instead. k3d nodes run their own containerd, isolated from your Docker. You either push to a registry the cluster can reach or import the image explicitly - the <a href="https://k3d.io/stable/usage/registries/">k3d registries guide</a> walks through wiring up a local registry the cluster can actually pull from.</p><p>The second lesson was the :latest tag trap. If your manifest references myapp:latest, Kubernetes defaults imagePullPolicy to Always and the kubelet re-pulls on every launch even when the image is sitting right there. <a href="https://kubernetes.io/docs/concepts/containers/images/">The Kubernetes image docs spell it out</a>: omit imagePullPolicy with a :latest tag and it becomes Always, while a fixed tag defaults to IfNotPresent. I switched to specific tags - myapp:dev, myapp:&lt;gitsha&gt; - and imagePullPolicy: IfNotPresent, and a whole category of mysterious slowness just evaporated.</p><p>Then Tilt took over the loop, and this is the part I still find a little magical. Instead of build then push then apply then wait, saving a file synced the change straight into the running Pod. The numbers matched exactly what the tool promised — Tilt’s own writeup frames live-update as <a href="https://blog.tilt.dev/2019/04/02/fast-kubernetes-development-with-live-update.html">deploying code to running containers in seconds, not minutes</a>, and syncing files into a running Pod with hot reload brought my iteration back down to roughly one to five seconds, better than a 95% cut. One detail I’m glad I got right: in the cluster image I run fastapi run, <em>not</em> uvicorn --reload. Reload is dev-only overhead and a leak risk; the speed comes from Tilt&#39;s live-update, not from reload inside the container.</p><h3>How it feels now</h3><p>The headline is easy to quote — two-to-five-minute iterations became one-to-five-second ones, and “build, push, apply, wait, check” collapsed into “save the file.” But honestly the second-order effects were the ones that changed how I work. Because a change now took seconds to see, I started testing <em>smaller</em> increments, one hypothesis at a time, instead of batching five changes into a single painful deploy and then bisecting which one broke. Pull requests got smaller. Review comments got sharper, because a reviewer could pull the branch and watch it run in a real cluster in under a minute.</p><p>And the OOMKilled and readiness-probe bugs that used to ambush us in staging now surfaced on the author’s laptop, where the person with all the context was sitting right there to fix them. That’s the whole economic argument for shift-left in one sentence: a bug caught in the inner loop costs a coffee’s worth of attention, while the same bug caught after git push costs a CI run, a reviewer&#39;s time, and sometimes a rollback. I didn&#39;t measure it to the decimal, but the number of &quot;why is staging broken?&quot; Slack threads dropped to nearly zero within a sprint, and I stopped bracing every time I opened the cluster.</p><p>A few things bit hard enough to cost a day each, and I’ll pass them on so they don’t cost you one. ImagePullBackOff on day one had nothing to do with a bad image - the cluster just couldn&#39;t see it, and understanding image delivery into k3d up front would have saved me an afternoon. Running --reload inside the container &quot;because it was fast locally&quot; fought Tilt and masked the real loop, so kill it. Don&#39;t confuse the inner and outer loops: this whole exercise is about the <em>inner</em> loop, the single-developer edit-build-run cycle before git push, and the outer loop of CI, GitOps, and integration tests is a genuinely separate beast. And don&#39;t skip resource limits locally - the entire point of a production-like local setup is that limits and probes <em>exist</em> on your laptop, so leaving them out just reopens the gap you were trying to close.</p><p>I had to actively resist the itch to also “fix” that outer loop in the same push. It’s real work, but it’s a different problem with different tools, and bundling it would have stalled everything. I fixed the inner loop first, shipped it, and let the win speak before touching anything downstream. Once the loop was fast, I layered the rest of a production-like setup on piece by piece — real Deployment and Service manifests, PostgreSQL inside the cluster, ConfigMaps and Secrets instead of hardcoded values, health probes — one production-like layer at a time (there’s a full end-to-end assembly linked in Sources below).</p><p>What I keep coming back to isn’t the speed number, satisfying as it is. It’s that I started <em>using</em> the cluster again instead of avoiding it. A dev loop you dread is a dev loop you route around, and every workaround quietly costs you the fidelity you were supposed to be buying. Getting seconds back didn’t just make me faster — it made me willing, and that turned out to be the whole point.</p><h3>Sources &amp; further reading</h3><ul><li>k3d-io/k3d — <a href="https://github.com/k3d-io/k3d">Little helper to run CNCF’s k3s in Docker</a></li><li>k3d docs — <a href="https://k3d.io/stable/usage/registries/">Using image registries with k3d</a></li><li>Tilt docs — <a href="https://docs.tilt.dev/tutorial/5-live-update.html">Smart Rebuilds with Live Update</a></li><li>Tilt blog — <a href="https://blog.tilt.dev/2019/04/02/fast-kubernetes-development-with-live-update.html">Fast Kubernetes Development with Live Update</a></li><li>Kubernetes docs — <a href="https://kubernetes.io/docs/concepts/containers/images/">Container Images &amp; imagePullPolicy</a></li><li><a href="https://dorokhovich.com/blog/local-k8s-inner-dev-loop?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-inner-dev-loop">A full local-Kubernetes inner-loop write-up someone put together</a>, covering the end-to-end k3d-to-production-like assembly</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=061b1732fcb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Cut Python Docker Image Size From 1.2 GB to a Lean, Secure Container]]></title>
            <link>https://medium.com/@menshikovvasiliy65/how-i-cut-python-docker-image-size-from-1-2-gb-to-a-lean-secure-container-dbef6a11555b?source=rss-921c3b4ad024------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbef6a11555b</guid>
            <dc:creator><![CDATA[Vasiliy Menshikov]]></dc:creator>
            <pubDate>Sun, 26 Jul 2026 20:09:46 GMT</pubDate>
            <atom:updated>2026-07-26T20:09:46.284Z</atom:updated>
            <content:encoded><![CDATA[<p>When we moved our tracking API to Kubernetes, the container turned out to be the weakest link in the whole thing. It was a 1.2 GB image that took two full minutes to rebuild on every code change and then, adding insult to injury, flat-out refused to run in our local k3d cluster. If you’ve ever wanted to reduce a Python Docker image size and wondered why your “working” image won’t load into a cluster, this is the afternoon where I fixed all three problems at once — and stopped being quietly embarrassed by my own Dockerfile.</p><h3>Why this bugged me for weeks</h3><p>Our service, myapp, is a Python 3.12 and FastAPI HTTP API on port 8080 that talks to PostgreSQL. The first Dockerfile I ever wrote for it is the first Dockerfile anyone writes, and it technically works:</p><pre>FROM python:3.12<br>WORKDIR /code<br>COPY . .<br>RUN pip install -r requirements.txt<br>CMD python -m uvicorn app.main:app --host 0.0.0.0 --port 8080</pre><p>Here’s the uncomfortable truth: every single line is a small mistake. The full-fat python:3.12 base is enormous. COPY . . before pip install means a one-character code edit invalidates the dependency layer and reinstalls the world. The shell-form CMD quietly breaks signal handling. And it runs as root. I lived with all of this for longer than I&#39;d like to admit, treating the slow rebuilds as just the cost of doing business, until I got fed up and went hunting for a canonical, production-minded reference. Someone had written up <a href="https://dorokhovich.com/blog/local-k8s-containerizing-your-service?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-containerizing-your-service">a walkthrough on writing a small, fast, secure Dockerfile for a FastAPI service and loading it into k3d</a>, and honestly it restructured how I think about every instruction in the file.</p><h3>The cheapest 90% win: fix your layer order</h3><p>Each Dockerfile instruction is a layer, Docker caches them, and — this is the part that matters — <a href="https://docs.docker.com/build/cache/">if a layer changes, every layer after it is invalidated too</a>. I was editing application code dozens of times a day and almost never touching dependencies, yet my ordering forced a full pip install on every build. The fix is embarrassingly simple: install what rarely changes <em>before</em> copying what changes constantly.</p><pre>COPY requirements.txt .<br>RUN pip install --no-cache-dir -r requirements.txt   # heavy, rarely changes<br>COPY ./app ./app                                      # light, changes often</pre><p>That one reorder dropped my rebuild from around two minutes to a few seconds on a code-only change, because the dependency layer now comes straight from cache. It’s the single most common Dockerfile anti-pattern in existence, and I’d been cheerfully living inside it for months.</p><h3>The multi-stage build</h3><p>The naive image ships everything into the final result — compilers, dev headers, pip caches — all of it dead weight at runtime. <a href="https://docs.docker.com/build/building/multi-stage/">A multi-stage build</a> installs dependencies in a build stage and copies only the finished virtualenv into a clean runtime image:</p><pre># --- Stage 1: build ---<br>FROM python:3.12-slim AS build<br>ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1<br>WORKDIR /code<br>RUN python -m venv /opt/venv<br>ENV PATH=&quot;/opt/venv/bin:$PATH&quot;<br>COPY requirements.txt .<br>RUN pip install --no-cache-dir -r requirements.txt</pre><pre># --- Stage 2: runtime ---<br>FROM python:3.12-slim<br>ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PATH=&quot;/opt/venv/bin:$PATH&quot;<br>WORKDIR /code<br>COPY --from=build /opt/venv /opt/venv<br>COPY ./app ./app<br>EXPOSE 8080<br>CMD [&quot;fastapi&quot;, &quot;run&quot;, &quot;app/main.py&quot;, &quot;--port&quot;, &quot;8080&quot;]</pre><p>How much you save depends entirely on your dependencies — with pure wheels the gain is modest, but we had a couple of packages that compiled from source, and dropping the build toolchain shrank the image substantially. Switching from python:3.12 to python:3.12-slim did the rest.</p><h3>The small details that make it production-grade</h3><p>The write-up drilled a handful of these in, and every one of them has bitten someone I know. Use fastapi run, not a bare uvicorn --reload - the reload flag is dev-only overhead in a cluster image, and <a href="https://fastapi.tiangolo.com/deployment/docker/">FastAPI&#39;s own container guide</a> uses fastapi run, which starts Uvicorn with sane production settings. Write CMD in exec form, as an array, so the app becomes PID 1 and receives SIGTERM from Kubernetes directly and shuts down gracefully; shell form wraps it in /bin/sh, the signal never arrives, and the Pod gets hard-killed on timeout. Set PYTHONUNBUFFERED=1, or your logs get stuck in a buffer and never surface in kubectl logs - I lost an hour to &quot;why is my container silent&quot; before I understood that one. Add an unprivileged user with adduser --disabled-password --uid 10001 appuser and then USER appuser, because root-by-default violates least privilege and it pairs later with securityContext.runAsNonRoot: true in the manifest. And add a .dockerignore, because without one I was shipping .git, a local .venv, and nearly a .env straight into the build context.</p><h3>The bug that stole a full day: ImagePullBackOff</h3><p>With a beautiful new image built, I ran docker build, applied the manifest, and the Pod sat in ImagePullBackOff forever. It <em>seems</em> completely obvious that a freshly built local image would be visible to the cluster. It is not, and this cost me a full day of my life. <strong>k3d nodes run their own containerd, isolated from your Docker daemon</strong> - an image sitting in Docker is invisible to the cluster, and the kubelet just keeps failing to pull it from a remote registry that doesn&#39;t have it.</p><p>The fastest fix for a one-off test is a direct import:</p><pre>docker build -t myapp:dev .<br>k3d image import myapp:dev -c dev</pre><p>Pair that with imagePullPolicy: IfNotPresent in the manifest so Kubernetes doesn&#39;t reach for the network anyway. For ongoing work we moved to k3d&#39;s built-in registry, where the same name k3d-registry.localhost:5000/myapp:dev works for both push from the host and pull from inside the cluster. The full delivery model - both paths, plus why *.localhost resolves - is covered in the companion write-up linked in Sources below.</p><h3>Two more touches that paid off</h3><p>First, a HEALTHCHECK that doesn&#39;t need curl. I wanted Docker to know whether the service was alive during local runs, but python:3.12-slim has no curl, and neither does distroless. So I did the check with Python, which is guaranteed to be in the image:</p><pre>HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \<br>  CMD [&quot;python&quot;, &quot;-c&quot;, &quot;import urllib.request,sys; sys.exit(0 if urllib.request.urlopen(&#39;http://localhost:8080/healthz&#39;).getcode()==200 else 1)&quot;]</pre><p>Second, actually understanding what EXPOSE does and doesn&#39;t do. For an embarrassingly long time I thought EXPOSE 8080 published the port. It doesn&#39;t - <a href="https://docs.docker.com/reference/dockerfile/">the Dockerfile reference is explicit that </a><a href="https://docs.docker.com/reference/dockerfile/">EXPOSE doesn&#39;t actually publish anything</a>; it&#39;s pure metadata, documentation for whoever reads the file. Real publishing happens with -p in docker run, or with Service and Ingress objects in Kubernetes. Internalizing that killed a whole afternoon of &quot;why can&#39;t I reach the port&quot; confusion, purely because I stopped expecting EXPOSE to do a job it was never designed for.</p><p>I also standardized on running a single worker per Pod and scaling with replicas, rather than cramming Gunicorn plus multiple Uvicorn workers into one container. In Kubernetes the cluster <em>is</em> the process manager, and letting it own concurrency kept my image simpler and my resource limits meaningful. For local development it’s not even a question — one process is plenty.</p><h3>How it feels now</h3><p>The difference is night and day, and it’s satisfying in a way that’s hard to overstate. The base went from the full python:3.12 to a multi-stage python:3.12-slim. A rebuild on a code change went from roughly two minutes of full pip install to a few seconds served from cache. The container runs as uid 10001 appuser instead of root. Signal handling went from broken - the shell-form CMD swallowing SIGTERM - to correct, with the app as PID 1 receiving signals directly. And the image, which used to greet me with ImagePullBackOff every time, now imports and pushes into k3d cleanly.</p><p>For local dev I deliberately stayed on slim, because it&#39;s genuinely easy to debug. When I hardened the image for production later, I moved the runtime to <a href="https://github.com/GoogleContainerTools/distroless">distroless</a> (gcr.io/distroless/python3-debian12) - no shell, no package manager, far fewer CVEs - building the deps on slim and copying them across. The trade-off is real: docker exec ... sh no longer works, so you debug with kubectl debug and ephemeral containers instead. That&#39;s a fair price for the reduced attack surface, but it&#39;s a choice worth making consciously rather than by accident.</p><p>What stuck with me most is how tangled up all of this had felt when it was really one thing. I’d been treating “make it smaller,” “make it faster,” “make it secure,” and “make it actually run in the cluster” as four separate chores I’d get to someday. They were never four projects. They were one Dockerfile, done with a little more care than the copy-paste version I’d been shrugging past for months — and the version of me who kept restarting slow builds would not believe how good a well-ordered Dockerfile feels to live with.</p><h3>Sources &amp; further reading</h3><ul><li>Docker docs — <a href="https://docs.docker.com/build/building/multi-stage/">Multi-stage builds</a></li><li>Docker docs — <a href="https://docs.docker.com/build/cache/">Optimizing builds with cache (layer invalidation)</a></li><li>Docker docs — <a href="https://docs.docker.com/reference/dockerfile/">Dockerfile reference: EXPOSE and CMD exec form</a></li><li>GoogleContainerTools/distroless — <a href="https://github.com/GoogleContainerTools/distroless">Minimal images with no shell or package manager</a></li><li>FastAPI docs — <a href="https://fastapi.tiangolo.com/deployment/docker/">FastAPI in Containers — Docker</a></li><li><a href="https://dorokhovich.com/blog/local-k8s-containerizing-your-service?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=success-story&amp;utm_content=local-k8s-containerizing-your-service">A local-Kubernetes containerization write-up someone put together</a>, with the complete annotated Dockerfile and the slim-vs-alpine-vs-distroless decision</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbef6a11555b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>