<?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 Manuel Baena García on Medium]]></title>
        <description><![CDATA[Stories by Manuel Baena García on Medium]]></description>
        <link>https://medium.com/@mbaena_43991?source=rss-fd9c033cb9fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MSApzXM76H5TFcLK</url>
            <title>Stories by Manuel Baena García on Medium</title>
            <link>https://medium.com/@mbaena_43991?source=rss-fd9c033cb9fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:10:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mbaena_43991/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[How I Recovered a Corrupted MicroK8s Cluster by Rebuilding dqlite Snapshots]]></title>
            <link>https://medium.com/@mbaena_43991/how-i-recovered-a-corrupted-microk8s-cluster-by-rebuilding-dqlite-snapshots-941ea11b7925?source=rss-fd9c033cb9fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/941ea11b7925</guid>
            <category><![CDATA[dqlite]]></category>
            <category><![CDATA[microk8s]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[databaserecovery]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Manuel Baena García]]></dc:creator>
            <pubDate>Mon, 07 Jul 2025 17:39:31 GMT</pubDate>
            <atom:updated>2025-07-07T17:39:31.129Z</atom:updated>
            <content:encoded><![CDATA[<p>MicroK8s is a lightweight and convenient way to deploy Kubernetes on single nodes or small clusters. However, its reliance on <strong>dqlite</strong>, a distributed SQLite backend, can become a critical weakness if the database becomes corrupted.</p><p>In this article, I walk you through how I successfully recovered a production MicroK8s cluster after dqlite corruption, including tools, custom scripts, and lessons learned.</p><h3>1. Identifying the Problem</h3><p>After experiencing cluster instability, I manually inspected the dqlite database:</p><pre>/snap/microk8s/current/bin/dqlite -s &lt;ip&gt;:19001 \<br>  -c /var/snap/microk8s/current/var/kubernetes/backend/cluster.crt \<br>  -k /var/snap/microk8s/current/var/kubernetes/backend/cluster.key k8s</pre><p>Within the dqlite prompt:</p><pre>PRAGMA integrity_check;</pre><p>The result:</p><pre>*** in database main ***<br>Tree 2 page 4456451 cell 0: overflow list length is 23 but should be 24<br>Page 4456450: never used</pre><p>A clear indicator of database corruption.</p><h3>2. Forcing a Snapshot from dqlite</h3><p>To attempt recovery, I forced dqlite to generate a fresh snapshot:</p><pre>systemctl stop snap.microk8s.daemon-k8s-dqlite</pre><p>Create or edit tuning.yaml:</p><pre>snapshot:<br>  trailing: 4<br>  threshold: 1</pre><p>Restart dqlite:</p><pre>systemctl start snap.microk8s.daemon-k8s-dqlite</pre><p>A new snapshot appeared in:</p><pre>/var/snap/microk8s/current/var/kubernetes/backend</pre><h3>3. Extracting the Snapshot with a Custom Script</h3><p>To extract the SQLite database from the snapshot, I developed a Python script supporting large files and LZ4 compression:</p><pre>python3 snapshot_to_sqlite_stream.py snapshot-974-1301685652-100717512 ./out/</pre><p>Result:</p><pre>✅ Extracted: out/k8s.db</pre><p>The script detects the dqlite binary format and safely extracts the .db file.</p><h3>4. Repairing the SQLite Database</h3><p>Using a recent version of sqlite3 with .recover support:</p><pre>./sqlite3 k8s.db &quot;.recover --ignore-freelist&quot; &gt; recovered.sql<br>./sqlite3 k8s_repaired.db &lt; recovered.sql</pre><p>Verifying integrity:</p><pre>sqlite3 k8s_repaired.db &quot;PRAGMA integrity_check;&quot;</pre><p>Output:</p><pre>ok</pre><h3>5. Rebuilding the dqlite Snapshot</h3><p>To convert the repaired .db back to a dqlite-compatible snapshot, I created a second Python script:</p><pre>python3 sqlite_to_snapshot.py snapshot-974-1301685652-100717512 out/k8s.db --compress</pre><h3>6. Verifying Cluster Recovery</h3><p>Back in dqlite:</p><pre>PRAGMA integrity_check;</pre><p>Output:</p><pre>ok</pre><p>The cluster resumed normal operation.</p><h3>7. Resources and References</h3><ul><li><a href="https://medium.com/@miroslavbalaz/fixing-microk8s-hanging-b05c9a080184">Fixing MicroK8s Hanging — Miroslav Balaz</a></li><li><a href="https://canonical.com/dqlite/docs">Canonical dqlite Documentation</a></li><li><a href="https://microk8s.io/docs/restore-quorum">MicroK8s Quorum Recovery Guide</a></li></ul><h3>8. Lessons Learned</h3><p>✅ Regular backups of the dqlite backend are essential.</p><p>✅ Custom tools for snapshot extraction and rebuilding can save the day.</p><p>✅ Forced snapshots combined with .recover are powerful recovery mechanisms.</p><h3>Conclusion</h3><p>While dqlite corruption doesn’t always mean total data loss, recovery requires technical knowledge and careful handling. Sharing these experiences helps strengthen the community and improves our collective resilience.</p><p>Have you faced similar challenges? Feel free to share your approach or feedback!</p><p><strong>Note:</strong> The extraction and snapshot rebuilding scripts mentioned are available upon request or will be published soon on GitHub.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=941ea11b7925" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>