-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathstorage-config.html
More file actions
567 lines (521 loc) · 20.2 KB
/
Copy pathstorage-config.html
File metadata and controls
567 lines (521 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Storage Backends - Rūsternetes</title>
<link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="stylesheet" href="../style.css">
</head>
<body>
<nav class="nav">
<div class="nav-inner">
<a href="../index.html" class="nav-logo">
<img src="../favicon-colored.svg" width="22" height="22" alt="" style="vertical-align: middle;"> rūsternetes
</a>
<div class="nav-links">
<a href="index.html" style="color: var(--walle-yellow);">Docs</a>
<a href="https://github.com/calfonso/rusternetes" class="nav-gh">GitHub</a>
</div>
</div>
</nav>
<div class="doc-layout">
<aside class="doc-sidebar">
<div class="doc-search">
<input type="text" class="doc-search-input" placeholder="Search docs... ( / )">
</div>
<div class="doc-search-results"></div>
<div class="sidebar-section">
<div class="sidebar-heading">Getting Started</div>
<ul class="sidebar-links">
<li><a href="quickstart.html">Quick Start</a></li>
<li><a href="installation.html">Installation</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-heading">Deployment</div>
<ul class="sidebar-links">
<li><a href="deployment.html">Overview</a></li>
<li><a href="all-in-one.html">All-in-One Binary</a></li>
<li><a href="docker-cluster.html">Compose + etcd</a></li>
<li><a href="sqlite-cluster.html">Compose + SQLite</a></li>
<li><a href="redis-cluster.html">Compose + Redis</a></li>
<li><a href="high-availability.html">High Availability</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-heading">Cluster Setup</div>
<ul class="sidebar-links">
<li><a href="bootstrap.html">Bootstrap</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-heading">Configuration</div>
<ul class="sidebar-links">
<li><a href="api-server-config.html">API Server</a></li>
<li><a href="kubelet-config.html">Kubelet</a></li>
<li><a href="scheduler-config.html">Scheduler</a></li>
<li><a href="controller-manager-config.html">Controller Manager</a></li>
<li><a href="kube-proxy-config.html">Kube-Proxy</a></li>
<li><a href="storage-config.html" class="active">Storage Backends</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-heading">Features</div>
<ul class="sidebar-links">
<li><a href="workloads.html">Workloads</a></li>
<li><a href="networking.html">Networking</a></li>
<li><a href="storage-volumes.html">Storage & Volumes</a></li>
<li><a href="security.html">Security</a></li>
<li><a href="crds.html">Custom Resources</a></li>
<li><a href="scheduling.html">Scheduling</a></li>
<li><a href="containers.html">Container Runtime</a></li>
<li><a href="kubectl.html">kubectl</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-heading">Operations</div>
<ul class="sidebar-links">
<li><a href="authentication.html">Authentication</a></li>
<li><a href="monitoring.html">Monitoring</a></li>
<li><a href="troubleshooting.html">Troubleshooting</a></li>
<li><a href="cloud-providers.html">Cloud Providers</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-heading">Reference</div>
<ul class="sidebar-links">
<li><a href="api-reference.html">API Reference</a></li>
<li><a href="conformance.html">Conformance</a></li>
</ul>
</div>
</aside>
<div class="doc-overlay"></div>
<main class="doc-content">
<p class="breadcrumb">Configuration › Storage Backends</p>
<h1>Storage Backends</h1>
<p class="lead">
Rūsternetes supports four storage backends: etcd for production clusters, SQLite
and Redis (via rhino) for lightweight deployments, and an in-memory backend for testing.
All backends implement the same <code>Storage</code> trait.
</p>
<h2>Backend Comparison</h2>
<table>
<thead>
<tr>
<th>Feature</th>
<th>etcd</th>
<th>SQLite (rhino)</th>
<th>Redis (rhino)</th>
<th>Memory</th>
</tr>
</thead>
<tbody>
<tr>
<td>Use case</td>
<td>Production clusters</td>
<td>Lightweight / all-in-one</td>
<td>Lightweight / all-in-one</td>
<td>Unit tests only</td>
</tr>
<tr>
<td>Persistence</td>
<td>Distributed, replicated</td>
<td>Single file on disk</td>
<td>Redis server (with optional AOF/RDB)</td>
<td>None (lost on restart)</td>
</tr>
<tr>
<td>Watch support</td>
<td>gRPC watch streams</td>
<td>Broadcast channel (capacity 1000)</td>
<td>Broadcast channel (capacity 1000)</td>
<td>Broadcast channel</td>
</tr>
<tr>
<td>External dependency</td>
<td>etcd cluster required</td>
<td>None (embedded) or rhino gRPC server</td>
<td>Redis server required</td>
<td>None</td>
</tr>
<tr>
<td>HA support</td>
<td>Yes (etcd replication)</td>
<td>No</td>
<td>Yes (Redis Sentinel / Cluster)</td>
<td>No</td>
</tr>
<tr>
<td>Auto-compaction</td>
<td>Yes (etcd built-in)</td>
<td>Yes (every 300s)</td>
<td>Yes (every 300s)</td>
<td>N/A</td>
</tr>
<tr>
<td>Auto-UID generation</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td>Feature flag</td>
<td>Always available</td>
<td><code>sqlite</code></td>
<td><code>redis</code></td>
<td>Always available</td>
</tr>
</tbody>
</table>
<h2>etcd Backend</h2>
<p>
The production-grade backend. Connects to an external etcd cluster via gRPC and
provides full watch support through etcd's native watch API.
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">terminal</span>
</div>
<code><span class="comment"># Start with etcd (default)</span>
rusternetes-api-server \
<span class="flag">--storage-backend</span> <span class="value">etcd</span> \
<span class="flag">--etcd-servers</span> <span class="value">http://etcd:2379</span></code>
</pre>
<h3>etcd Configuration</h3>
<p>
etcd itself is configured separately. Recommended settings for Rūsternetes:
</p>
<table>
<thead>
<tr>
<th>Setting</th>
<th>Recommended</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--auto-compaction-retention</code></td>
<td><code>1</code> (hour)</td>
<td>Automatically compact old revisions to save disk space</td>
</tr>
<tr>
<td><code>--quota-backend-bytes</code></td>
<td><code>8589934592</code> (8 GB)</td>
<td>Maximum database size</td>
</tr>
<tr>
<td><code>--snapshot-count</code></td>
<td><code>10000</code></td>
<td>Number of committed transactions to trigger a snapshot</td>
</tr>
<tr>
<td><code>--listen-client-urls</code></td>
<td><code>http://0.0.0.0:2379</code></td>
<td>Client-facing listen address</td>
</tr>
</tbody>
</table>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">compose.yml</span>
</div>
<code>etcd:
image: quay.io/coreos/etcd:v3.5.17
command:
- etcd
- <span class="flag">--name</span>=<span class="value">etcd0</span>
- <span class="flag">--data-dir</span>=<span class="value">/etcd-data</span>
- <span class="flag">--listen-client-urls</span>=<span class="value">http://0.0.0.0:2379</span>
- <span class="flag">--advertise-client-urls</span>=<span class="value">http://etcd:2379</span>
- <span class="flag">--auto-compaction-retention</span>=<span class="value">1</span>
- <span class="flag">--snapshot-count</span>=<span class="value">10000</span></code>
</pre>
<h2>SQLite Backend (rhino)</h2>
<p>
The lightweight backend uses <a href="https://github.com/calfonso/rhino">rhino</a>,
an embedded SQLite engine that implements the same key-value semantics as etcd.
It can run in two modes:
</p>
<h3>Embedded Mode (All-in-One)</h3>
<p>
The SQLite database runs in-process with no external dependencies. This is the
default for the all-in-one binary.
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">terminal</span>
</div>
<code><span class="comment"># All-in-one with embedded SQLite</span>
rusternetes \
<span class="flag">--storage-backend</span> <span class="value">sqlite</span> \
<span class="flag">--data-dir</span> <span class="value">./data/rusternetes.db</span></code>
</pre>
<table>
<thead>
<tr>
<th>Setting</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>compact_interval</code></td>
<td>300s</td>
<td>How often to compact old revisions</td>
</tr>
<tr>
<td>Watch mechanism</td>
<td>Broadcast channel</td>
<td>In-process tokio broadcast for watch events</td>
</tr>
<tr>
<td>Feature flag</td>
<td><code>sqlite</code></td>
<td>Must be enabled at compile time</td>
</tr>
</tbody>
</table>
<h3>gRPC Mode (Docker Compose)</h3>
<p>
For multi-container deployments without etcd, rhino can run as a separate gRPC
service that multiple components connect to. Use <code>compose.sqlite.yml</code>:
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">terminal</span>
</div>
<code><span class="comment"># Start with SQLite gRPC backend</span>
podman compose -f compose.sqlite.yml up -d</code>
</pre>
<h2>Redis Backend (rhino)</h2>
<p>
The Redis backend uses <a href="https://github.com/calfonso/rhino">rhino</a>'s
RedisBackend to store cluster state in a Redis server. Like the SQLite backend,
it implements the same key-value semantics as etcd. It can run in two modes:
</p>
<h3>Embedded Mode (All-in-One)</h3>
<p>
The Redis backend runs in-process with rhino's RedisBackend, connecting directly
to a Redis server. No gRPC layer is needed.
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">terminal</span>
</div>
<code><span class="comment"># All-in-one with embedded Redis backend</span>
rusternetes \
<span class="flag">--storage-backend</span> <span class="value">redis</span> \
<span class="flag">--redis-url</span> <span class="value">redis://localhost:6379</span></code>
</pre>
<h3>gRPC Mode (Docker Compose)</h3>
<p>
For multi-container deployments, rhino can run as a separate gRPC service backed
by Redis that multiple components connect to. Use <code>compose.redis.yml</code>:
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">terminal</span>
</div>
<code><span class="comment"># Start with Redis gRPC backend</span>
podman compose -f compose.redis.yml up -d</code>
</pre>
<table>
<thead>
<tr>
<th>Setting</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>compact_interval</code></td>
<td>300s</td>
<td>How often to compact old revisions</td>
</tr>
<tr>
<td>Watch mechanism</td>
<td>Broadcast channel</td>
<td>In-process tokio broadcast for watch events</td>
</tr>
<tr>
<td>Feature flag</td>
<td><code>redis</code></td>
<td>Must be enabled at compile time</td>
</tr>
</tbody>
</table>
<h2>Memory Backend</h2>
<p>
An in-memory <code>HashMap</code>-based storage backend used exclusively for unit tests.
It provides all <code>Storage</code> trait operations including watch support via
broadcast channels. Data is lost when the process exits.
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">rust test</span>
</div>
<code><span class="comment">// Unit tests use MemoryStorage</span>
#[tokio::test]
async fn test_create_pod() {
let storage = Arc::new(MemoryStorage::new());
<span class="comment">// MemoryStorage auto-generates UIDs for resources</span>
let pod = storage.create("/registry/pods/default/test", &pod).await?;
}</code>
</pre>
<div class="admonition warning">
<div class="admonition-title">TESTING ONLY</div>
<p>
The memory backend is not suitable for any production or development use.
It has no persistence, no compaction, and auto-generates UIDs which differs
from the production backends.
</p>
</div>
<h2>Storage Trait</h2>
<p>
All backends implement the <code>Storage</code> trait, which provides the complete
API for resource persistence:
</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>create(key, value)</code></td>
<td>Create a new resource. Returns the created resource with resourceVersion set.</td>
</tr>
<tr>
<td><code>get(key)</code></td>
<td>Get a resource by key. Returns 404 if not found.</td>
</tr>
<tr>
<td><code>update(key, value)</code></td>
<td>Update an existing resource. Returns the updated resource.</td>
</tr>
<tr>
<td><code>update_raw(key, value)</code></td>
<td>Update with raw JSON value (used by garbage collector).</td>
</tr>
<tr>
<td><code>delete(key)</code></td>
<td>Delete a resource by key.</td>
</tr>
<tr>
<td><code>list(prefix)</code></td>
<td>List all resources matching a key prefix.</td>
</tr>
<tr>
<td><code>watch(prefix)</code></td>
<td>Watch for changes to resources with a given prefix.</td>
</tr>
<tr>
<td><code>watch_from_revision(prefix, revision)</code></td>
<td>Watch for changes starting from a specific revision.</td>
</tr>
<tr>
<td><code>current_revision()</code></td>
<td>Get the current storage revision number.</td>
</tr>
<tr>
<td><code>is_revision_compacted(revision)</code></td>
<td>Check if a revision has been compacted and is no longer available.</td>
</tr>
</tbody>
</table>
<h2>Key Schema</h2>
<p>
All backends use the same key format, matching Kubernetes conventions:
</p>
<pre>
<div class="code-header">
<span class="code-dot red"></span>
<span class="code-dot yellow"></span>
<span class="code-dot green"></span>
<span class="code-title">key format</span>
</div>
<code><span class="comment"># Namespaced resources</span>
/registry/{resource_type}/{namespace}/{name}
<span class="comment"># Cluster-scoped resources</span>
/registry/{resource_type}/{name}
<span class="comment"># Examples</span>
/registry/pods/default/nginx <span class="comment"># Pod "nginx" in namespace "default"</span>
/registry/services/kube-system/kube-dns <span class="comment"># Service "kube-dns" in kube-system</span>
/registry/nodes/node-1 <span class="comment"># Node "node-1" (cluster-scoped)</span>
/registry/clusterroles/admin <span class="comment"># ClusterRole "admin"</span>
<span class="comment"># List prefixes</span>
/registry/pods/default/ <span class="comment"># All pods in "default" namespace</span>
/registry/pods/ <span class="comment"># All pods in all namespaces</span>
/registry/nodes/ <span class="comment"># All nodes</span></code>
</pre>
<h2>Resource Versions</h2>
<p>
The <code>metadata.resourceVersion</code> field is derived from the storage backend's
modification revision:
</p>
<ul>
<li><strong>etcd</strong>: <code>resourceVersion</code> = etcd <code>mod_revision</code> (monotonically increasing integer)</li>
<li><strong>SQLite</strong>: <code>resourceVersion</code> = rhino <code>mod_revision</code> (same semantics)</li>
<li><strong>Redis</strong>: <code>resourceVersion</code> = rhino <code>mod_revision</code> (same semantics)</li>
<li><strong>Memory</strong>: <code>resourceVersion</code> = internal counter</li>
</ul>
<p>
Resource versions are used for optimistic concurrency control (conflict detection on updates)
and as watch resume tokens (<code>watch_from_revision</code>).
</p>
<div class="admonition tip">
<div class="admonition-title">CHOOSING A BACKEND</div>
<p>
Use <strong>etcd</strong> for production multi-node clusters that need HA and replication.
Use <strong>SQLite</strong> for single-node or development deployments where simplicity
matters. Use <strong>Redis</strong> when you need a lightweight backend with optional
HA via Redis Sentinel or Cluster. Use <strong>memory</strong> only in test code.
</p>
</div>
<div class="doc-pager">
<a href="kube-proxy-config.html" class="prev">
<span class="pager-label">Previous</span>
← Kube-Proxy Config
</a>
<a href="workloads.html" class="next">
<span class="pager-label">Next</span>
Workloads →
</a>
</div>
</main>
</div>
<footer class="doc-footer">
<p><a href="../index.html">Rūsternetes</a> — Kubernetes reimplemented in Rust. Apache-2.0 License.</p>
</footer>
<button class="sidebar-toggle" aria-label="Toggle navigation">☰</button>
<script src="search.js"></script>
</body>
</html>