|
1 | 1 | # Chapter 4: Working with Pods |
2 | 2 |
|
| 3 | +import { ProcessFlow, StackDiagram, CardGrid, colors } from '@site/src/components/diagrams'; |
| 4 | + |
3 | 5 | **Previous:** [Chapter 3: Getting Kubernetes](03-getting-kubernetes.md) | **Next:** [Chapter 5: Virtual Clusters and Namespaces](05-virtual-clusters-namespaces.md) |
4 | 6 |
|
5 | 7 | --- |
@@ -74,20 +76,21 @@ Pods enable resource sharing by providing a shared execution environment for one |
74 | 76 |
|
75 | 77 | **Multi-Container Pod Architecture:** |
76 | 78 |
|
77 | | -``` |
78 | | -Pod: web-application (IP: 10.244.1.5) |
79 | | -┌─────────────────────────────────────────┐ |
80 | | -│ │ |
81 | | -│ ┌─────────────┐ ┌─────────────────┐ │ |
82 | | -│ │ Web Server │ │ Log Collector │ │ |
83 | | -│ │ Port: 8080 │ │ Port: 5005 │ │ |
84 | | -│ │ │ │ │ │ |
85 | | -│ └─────────────┘ └─────────────────┘ │ |
86 | | -│ │ │ │ |
87 | | -│ └── Shared Volume ───┘ │ |
88 | | -│ │ |
89 | | -└─────────────────────────────────────────┘ |
90 | | -``` |
| 79 | +<StackDiagram |
| 80 | + title="Pod: web-application (IP: 10.244.1.5)" |
| 81 | + layers={[ |
| 82 | + { |
| 83 | + label: 'Containers', |
| 84 | + color: colors.blue, |
| 85 | + items: ['Web Server (Port: 8080)', 'Log Collector (Port: 5005)'] |
| 86 | + }, |
| 87 | + { |
| 88 | + label: 'Shared Resources', |
| 89 | + color: colors.slate, |
| 90 | + items: ['Shared Volume'] |
| 91 | + } |
| 92 | + ]} |
| 93 | +/> |
91 | 94 |
|
92 | 95 | **Container Communication Patterns:** |
93 | 96 | - **External Access**: `10.244.1.5:8080` (web) and `10.244.1.5:5005` (logs) |
@@ -181,9 +184,9 @@ spec: |
181 | 184 | - **Pending**: No suitable node found (check resources/constraints) |
182 | 185 | - **Failed**: Scheduling impossible (insufficient cluster capacity) |
183 | 186 |
|
184 | | -`★ Insight ─────────────────────────────────────` |
| 187 | +:::info[Insight] |
185 | 188 | Resource requests and limits are critical for scheduling efficiency. Without them, the scheduler cannot make optimal decisions and may place workloads on inadequate nodes, leading to performance issues. |
186 | | -`─────────────────────────────────────────────────` |
| 189 | +::: |
187 | 190 |
|
188 | 191 | ### 1.4. Pod Lifecycle |
189 | 192 |
|
@@ -255,19 +258,30 @@ Every Kubernetes cluster implements a pod network that automatically connects al |
255 | 258 |
|
256 | 259 | **Network Architecture:** |
257 | 260 |
|
258 | | -``` |
259 | | -Kubernetes Cluster Network |
260 | | -┌──────────────────────────────────────────────────┐ |
261 | | -│ │ |
262 | | -│ Node 1 Node 2 Node 3 │ |
263 | | -│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ |
264 | | -│ │ Pod A │ │ Pod B │ │ Pod C │ │ |
265 | | -│ │ 10.1.1.2 │◄──►│ 10.1.2.5 │◄──►│ 10.1.3.8 │ │ |
266 | | -│ └──────────┘ └──────────┘ └──────────┘ │ |
267 | | -│ │ |
268 | | -│ Pod Network: Direct communication across nodes │ |
269 | | -└──────────────────────────────────────────────────┘ |
270 | | -``` |
| 261 | +<CardGrid |
| 262 | + cards={[ |
| 263 | + { |
| 264 | + title: 'Node 1', |
| 265 | + description: 'Pod A', |
| 266 | + items: ['IP: 10.1.1.2'], |
| 267 | + color: colors.blue |
| 268 | + }, |
| 269 | + { |
| 270 | + title: 'Node 2', |
| 271 | + description: 'Pod B', |
| 272 | + items: ['IP: 10.1.2.5'], |
| 273 | + color: colors.green |
| 274 | + }, |
| 275 | + { |
| 276 | + title: 'Node 3', |
| 277 | + description: 'Pod C', |
| 278 | + items: ['IP: 10.1.3.8'], |
| 279 | + color: colors.purple |
| 280 | + } |
| 281 | + ]} |
| 282 | +/> |
| 283 | + |
| 284 | +**Pod Network: Direct communication across nodes** |
271 | 285 |
|
272 | 286 | **CNI Plugin Options:** |
273 | 287 |
|
@@ -308,9 +322,9 @@ spec: |
308 | 322 | - **Application Segmentation**: Multi-tier applications with controlled access |
309 | 323 | - **Service Mesh**: Advanced traffic management and security |
310 | 324 |
|
311 | | -`★ Insight ─────────────────────────────────────` |
| 325 | +:::info[Insight] |
312 | 326 | The pod network starts completely open for ease of use and learning. In production environments, implement network policies to control traffic flow, just like security checkpoints in logistics networks. |
313 | | -`─────────────────────────────────────────────────` |
| 327 | +::: |
314 | 328 |
|
315 | 329 | --- |
316 | 330 |
|
@@ -340,14 +354,25 @@ Init containers run before application containers and must complete successfully |
340 | 354 |
|
341 | 355 | **Execution Flow:** |
342 | 356 |
|
343 | | -``` |
344 | | -Init Container Sequence: |
345 | | -┌─────────────┐ ┌─────────────┐ ┌─────────────┐ |
346 | | -│ Init 1 │→ │ Init 2 │→ │ Application │ |
347 | | -│ Setup DB │ │ Check API │ │ Server │ |
348 | | -│ (must pass) │ │ (must pass) │ │ (starts) │ |
349 | | -└─────────────┘ └─────────────┘ └─────────────┘ |
350 | | -``` |
| 357 | +<ProcessFlow |
| 358 | + steps={[ |
| 359 | + { |
| 360 | + title: 'Init 1', |
| 361 | + description: 'Setup DB (must pass)', |
| 362 | + color: colors.orange |
| 363 | + }, |
| 364 | + { |
| 365 | + title: 'Init 2', |
| 366 | + description: 'Check API (must pass)', |
| 367 | + color: colors.orange |
| 368 | + }, |
| 369 | + { |
| 370 | + title: 'Application', |
| 371 | + description: 'Server (starts)', |
| 372 | + color: colors.green |
| 373 | + } |
| 374 | + ]} |
| 375 | +/> |
351 | 376 |
|
352 | 377 | **Init Container Example:** |
353 | 378 |
|
@@ -414,16 +439,35 @@ Sidecars are defined as init containers with `restartPolicy: Always`, which make |
414 | 439 |
|
415 | 440 | **Sidecar Lifecycle:** |
416 | 441 |
|
417 | | -``` |
418 | | -Sidecar Container Lifecycle: |
419 | | -┌─────────────────────────────────────────────┐ |
420 | | -│ 1. Sidecar starts first │ |
421 | | -│ 2. Main application starts after sidecar │ |
422 | | -│ 3. Both containers run together │ |
423 | | -│ 4. Main application shuts down │ |
424 | | -│ 5. Sidecar shuts down after main app │ |
425 | | -└─────────────────────────────────────────────┘ |
426 | | -``` |
| 442 | +<ProcessFlow |
| 443 | + steps={[ |
| 444 | + { |
| 445 | + title: 'Sidecar Starts', |
| 446 | + description: 'Sidecar container starts first', |
| 447 | + color: colors.purple |
| 448 | + }, |
| 449 | + { |
| 450 | + title: 'Main App Starts', |
| 451 | + description: 'Main application starts after sidecar', |
| 452 | + color: colors.blue |
| 453 | + }, |
| 454 | + { |
| 455 | + title: 'Running Together', |
| 456 | + description: 'Both containers run together', |
| 457 | + color: colors.green |
| 458 | + }, |
| 459 | + { |
| 460 | + title: 'Main App Shutdown', |
| 461 | + description: 'Main application shuts down', |
| 462 | + color: colors.orange |
| 463 | + }, |
| 464 | + { |
| 465 | + title: 'Sidecar Shutdown', |
| 466 | + description: 'Sidecar shuts down after main app', |
| 467 | + color: colors.red |
| 468 | + } |
| 469 | + ]} |
| 470 | +/> |
427 | 471 |
|
428 | 472 | **Content Synchronization Example:** |
429 | 473 |
|
@@ -475,9 +519,9 @@ As of Kubernetes v1.29+, native sidecar support is in beta, providing: |
475 | 519 | - **Lifecycle Management**: Proper shutdown sequencing |
476 | 520 | - **Status Tracking**: Clear sidecar vs main container status |
477 | 521 |
|
478 | | -`★ Insight ─────────────────────────────────────` |
| 522 | +:::info[Insight] |
479 | 523 | Sidecar containers implement the single responsibility principle - each container has one focused job. This separation makes components simpler, more reusable, and easier to troubleshoot than monolithic applications. |
480 | | -`─────────────────────────────────────────────────` |
| 524 | +::: |
481 | 525 |
|
482 | 526 | --- |
483 | 527 |
|
@@ -764,9 +808,9 @@ HOSTNAME=hello-pod |
764 | 808 | | `kubectl logs` | Container output | Application debugging | |
765 | 809 | | `kubectl exec` | Container access | Interactive debugging | |
766 | 810 |
|
767 | | -`★ Insight ─────────────────────────────────────` |
| 811 | +:::info[Insight] |
768 | 812 | The Pod name becomes the hostname for all containers inside it, making networking and debugging intuitive. A Pod named "web-server" has hostname "web-server" for all its containers. |
769 | | -`─────────────────────────────────────────────────` |
| 813 | +::: |
770 | 814 |
|
771 | 815 | ### 4.4. Multi-Container Examples |
772 | 816 |
|
@@ -1012,9 +1056,9 @@ Pods are the fundamental building blocks of Kubernetes, providing a standardized |
1012 | 1056 | **Looking Forward:** |
1013 | 1057 | While Pods are fundamental, production deployments typically use higher-level controllers like Deployments, StatefulSets, and DaemonSets that provide additional capabilities like self-healing, scaling, and rolling updates. |
1014 | 1058 |
|
1015 | | -`★ Insight ─────────────────────────────────────` |
| 1059 | +:::info[Insight] |
1016 | 1060 | Pods embody the separation of concerns principle - they handle application packaging and resource sharing while letting Kubernetes manage scheduling and orchestration. This separation enables the flexibility and power of the Kubernetes platform. |
1017 | | -`─────────────────────────────────────────────────` |
| 1061 | +::: |
1018 | 1062 |
|
1019 | 1063 | --- |
1020 | 1064 |
|
|
0 commit comments