-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevOps_Notes.html
More file actions
2531 lines (2234 loc) · 83.8 KB
/
DevOps_Notes.html
File metadata and controls
2531 lines (2234 loc) · 83.8 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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DevOps Complete Learning Guide</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #667eea;
--secondary: #764ba2;
--dark: #2d3748;
--light: #f7fafc;
--code-bg: #1e1e1e;
--border: #e2e8f0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
line-height: 1.6;
color: var(--dark);
background: var(--light);
}
.header {
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
color: white;
padding: 3rem 2rem;
text-align: center;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 0.5rem;
}
.header p {
font-size: 1.1rem;
opacity: 0.95;
}
.container {
display: flex;
max-width: 1400px;
margin: 0 auto;
gap: 2rem;
padding: 2rem;
}
.sidebar {
width: 280px;
position: sticky;
top: 140px;
height: fit-content;
background: white;
border-radius: 10px;
padding: 1.5rem;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.sidebar h3 {
color: var(--primary);
margin-bottom: 1rem;
font-size: 1.2rem;
}
.toc {
list-style: none;
}
.toc li {
margin-bottom: 0.5rem;
}
.toc a {
color: var(--dark);
text-decoration: none;
display: block;
padding: 0.5rem;
border-radius: 5px;
transition: all 0.3s ease;
}
.toc a:hover {
background: var(--light);
color: var(--primary);
transform: translateX(5px);
}
.toc a.active {
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
color: white;
}
.content {
flex: 1;
background: white;
border-radius: 10px;
padding: 2rem;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.section {
margin-bottom: 3rem;
scroll-margin-top: 160px;
}
.section h2 {
color: var(--primary);
font-size: 2rem;
margin-bottom: 1rem;
padding-bottom: 0.5rem;
border-bottom: 3px solid var(--primary);
}
.section h3 {
color: var(--dark);
font-size: 1.5rem;
margin: 2rem 0 1rem;
}
.section h4 {
color: var(--dark);
font-size: 1.2rem;
margin: 1.5rem 0 0.5rem;
}
.command-box {
background: var(--code-bg);
color: #f8f8f2;
padding: 1rem;
border-radius: 8px;
margin: 1rem 0;
font-family: 'Courier New', monospace;
overflow-x: auto;
position: relative;
}
.command-box::before {
content: 'BASH';
position: absolute;
top: 5px;
right: 10px;
font-size: 0.7rem;
color: #666;
background: #333;
padding: 2px 8px;
border-radius: 3px;
}
.yaml-box {
background: var(--code-bg);
color: #f8f8f2;
padding: 1rem;
border-radius: 8px;
margin: 1rem 0;
font-family: 'Courier New', monospace;
overflow-x: auto;
position: relative;
}
.yaml-box::before {
content: 'YAML';
position: absolute;
top: 5px;
right: 10px;
font-size: 0.7rem;
color: #666;
background: #333;
padding: 2px 8px;
border-radius: 3px;
}
code {
background: #f4f4f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
color: var(--primary);
}
.tip {
background: #e6f7ff;
border-left: 4px solid #1890ff;
padding: 1rem;
margin: 1rem 0;
border-radius: 5px;
}
.tip::before {
content: '💡 TIP: ';
font-weight: bold;
color: #1890ff;
}
.warning {
background: #fff7e6;
border-left: 4px solid #fa8c16;
padding: 1rem;
margin: 1rem 0;
border-radius: 5px;
}
.warning::before {
content: '⚠️ WARNING: ';
font-weight: bold;
color: #fa8c16;
}
.best-practice {
background: #f0f9ff;
border: 2px solid var(--primary);
padding: 1rem;
margin: 1rem 0;
border-radius: 8px;
}
.best-practice::before {
content: '✅ BEST PRACTICE';
display: block;
font-weight: bold;
color: var(--primary);
margin-bottom: 0.5rem;
}
table {
width: 100%;
border-collapse: collapse;
margin: 1rem 0;
}
th {
background: var(--primary);
color: white;
padding: 0.75rem;
text-align: left;
}
td {
padding: 0.75rem;
border-bottom: 1px solid var(--border);
}
tr:hover {
background: var(--light);
}
.command-table {
margin: 1rem 0;
}
.button-group {
position: fixed;
bottom: 20px;
right: 20px;
display: flex;
gap: 10px;
z-index: 1000;
}
.fab {
width: 50px;
height: 50px;
border-radius: 50%;
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
color: white;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
transition: transform 0.3s ease;
}
.fab:hover {
transform: scale(1.1);
}
.search-box {
position: fixed;
top: 20px;
right: 20px;
z-index: 1001;
display: none;
}
.search-box.active {
display: block;
}
.search-box input {
padding: 10px 15px;
border: 2px solid var(--primary);
border-radius: 25px;
width: 300px;
font-size: 1rem;
}
@media print {
.sidebar, .button-group, .header {
display: none;
}
.container {
display: block;
}
.content {
box-shadow: none;
padding: 0;
}
}
@media (max-width: 768px) {
.container {
flex-direction: column;
}
.sidebar {
width: 100%;
position: static;
}
.header h1 {
font-size: 1.8rem;
}
}
</style>
</head>
<body>
<div class="header">
<h1>🚀 DevOps Complete Learning Guide</h1>
<p>Advanced Topics with Practical Examples</p>
</div>
<div class="container">
<nav class="sidebar">
<h3>📚 Table of Contents</h3>
<ul class="toc">
<li><a href="#git-advanced">Git & GitHub Advanced</a></li>
<li><a href="#github-actions">GitHub Actions</a></li>
<li><a href="#linux">Linux for DevOps</a></li>
<li><a href="#cicd">CI/CD Pipelines</a></li>
<li><a href="#docker">Docker Deep Dive</a></li>
<li><a href="#kubernetes">Kubernetes</a></li>
<li><a href="#ingress">Ingress & Cert Manager</a></li>
<li><a href="#observability">Observability</a></li>
<li><a href="#terraform">Terraform</a></li>
</ul>
</nav>
<main class="content">
<!-- Git Advanced Section -->
<section id="git-advanced" class="section">
<h2>1. Git & GitHub Advanced</h2>
<h3>Git Internals & Advanced Commands</h3>
<div class="command-box">
# Understanding Git Objects
git cat-file -p HEAD # Print object content
git ls-tree HEAD # List tree object
git rev-parse HEAD # Get SHA of HEAD
git reflog # Reference log of all changes
</div>
<h4>Interactive Rebase</h4>
<div class="tip">
Interactive rebase is powerful for cleaning up commit history before pushing to remote.
</div>
<div class="command-box">
# Squash last 3 commits
git rebase -i HEAD~3
# In the editor, you'll see:
# pick abc1234 First commit
# pick def5678 Second commit
# pick ghi9012 Third commit
# Change to:
# pick abc1234 First commit
# squash def5678 Second commit
# squash ghi9012 Third commit
</div>
<h4>Git Stash Advanced</h4>
<table class="command-table">
<tr>
<th>Command</th>
<th>Description</th>
</tr>
<tr>
<td><code>git stash save "message"</code></td>
<td>Stash with descriptive message</td>
</tr>
<tr>
<td><code>git stash list</code></td>
<td>List all stashes</td>
</tr>
<tr>
<td><code>git stash apply stash@{2}</code></td>
<td>Apply specific stash</td>
</tr>
<tr>
<td><code>git stash branch new-branch</code></td>
<td>Create branch from stash</td>
</tr>
<tr>
<td><code>git stash show -p stash@{0}</code></td>
<td>Show stash content</td>
</tr>
</table>
<h4>Git Hooks Example</h4>
<div class="best-practice">
Use Git hooks to enforce code quality and standards before commits.
</div>
<div class="command-box">
#!/bin/sh
# .git/hooks/pre-commit
# Make it executable: chmod +x .git/hooks/pre-commit
# Run tests before commit
npm test || exit 1
# Check for console.log statements
if grep -r "console.log" --include="*.js" .; then
echo "Remove console.log statements before committing"
exit 1
fi
# Run linter
npm run lint || exit 1
echo "Pre-commit checks passed!"
</div>
</section>
<!-- GitHub Actions Section -->
<section id="github-actions" class="section">
<h2>2. GitHub Actions</h2>
<h3>Complete CI/CD Workflow</h3>
<div class="yaml-box">
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
env:
NODE_VERSION: '16'
DOCKER_REGISTRY: ghcr.io
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Upload coverage
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage/
</div>
<h3>Matrix Strategy</h3>
<div class="tip">
Use matrix strategies to test across multiple versions and platforms simultaneously.
</div>
<div class="yaml-box">
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [14, 16, 18]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm test
</div>
</section>
<!-- Linux Section -->
<section id="linux" class="section">
<h2>3. Linux for DevOps</h2>
<h3>Essential System Commands</h3>
<table class="command-table">
<tr>
<th>Category</th>
<th>Command</th>
<th>Description</th>
</tr>
<tr>
<td rowspan="4">System Info</td>
<td><code>uname -a</code></td>
<td>All system information</td>
</tr>
<tr>
<td><code>df -h</code></td>
<td>Disk usage human readable</td>
</tr>
<tr>
<td><code>free -h</code></td>
<td>Memory usage</td>
</tr>
<tr>
<td><code>top / htop</code></td>
<td>Process monitoring</td>
</tr>
<tr>
<td rowspan="4">Network</td>
<td><code>ss -tulpn</code></td>
<td>Show listening ports</td>
</tr>
<tr>
<td><code>ip addr show</code></td>
<td>Show IP addresses</td>
</tr>
<tr>
<td><code>curl -I URL</code></td>
<td>Get HTTP headers</td>
</tr>
<tr>
<td><code>dig domain.com</code></td>
<td>DNS lookup</td>
</tr>
</table>
<h3>Service Management (systemd)</h3>
<div class="command-box">
# Service control
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx
systemctl enable nginx # Enable at boot
systemctl disable nginx # Disable at boot
systemctl status nginx
# View logs
journalctl -u nginx -f # Follow logs
journalctl -u nginx --since "1 hour ago"
journalctl -p err # Error logs only
</div>
<h3>Creating a Custom Service</h3>
<div class="best-practice">
Always create custom systemd services for production applications to ensure proper lifecycle management.
</div>
<div class="command-box">
# /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=appuser
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node app.js
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=myapp
[Install]
WantedBy=multi-user.target
# Reload and start
systemctl daemon-reload
systemctl start myapp
systemctl enable myapp
</div>
<!-- Added on 2026-01-05 16:42 -->
<h3>Changing File Permissions</h3>
<p>The <code>chmod</code> command enables you to change the permissions on a file. You must be superuser or the owner of a file or directory to change its permissions.</p>
<p>You can use the <code>chmod</code> command to set permissions in either of two modes:</p>
<ul>
<li><strong>Absolute Mode</strong> - Use numbers to represent file permissions (the method most commonly used to set permissions). When you change permissions by using the absolute mode, represent permissions for each triplet by an octal mode number.</li>
<li><strong>Symbolic Mode</strong> - Use combinations of letters and symbols to add or remove permissions.</li>
</ul>
<h3>Setting File Permissions in Absolute Mode</h3>
<table class="command-table">
<tr><th>Octal Value</th><th>File Permissions Set</th><th>Permissions Description</th></tr>
<tr><td>0</td><td>---</td><td>No permissions</td></tr>
<tr><td>1</td><td>--x</td><td>Execute permission only</td></tr>
<tr><td>2</td><td>-w-</td><td>Write permission only</td></tr>
<tr><td>3</td><td>-wx</td><td>Write and execute permissions</td></tr>
<tr><td>4</td><td>r--</td><td>Read permission only</td></tr>
<tr><td>5</td><td>r-x</td><td>Read and execute permissions</td></tr>
<tr><td>6</td><td>rw-</td><td>Read and write permissions</td></tr>
<tr><td>7</td><td>rwx</td><td>Read, write, and execute permissions</td></tr>
</table>
<h3>Setting File Permissions in Symbolic Mode</h3>
<table class="command-table">
<tr><th>Symbol</th><th>Function</th><th>Description</th></tr>
<tr><td>u</td><td>Who</td><td>User (owner)</td></tr>
<tr><td>g</td><td>Who</td><td>Group</td></tr>
<tr><td>o</td><td>Who</td><td>Others</td></tr>
<tr><td>a</td><td>Who</td><td>All</td></tr>
<tr><td>=</td><td>Operation</td><td>Assign</td></tr>
<tr><td>+</td><td>Operation</td><td>Add</td></tr>
<tr><td>-</td><td>Operation</td><td>Remove</td></tr>
<tr><td>r</td><td>Permission</td><td>Read</td></tr>
<tr><td>w</td><td>Permission</td><td>Write</td></tr>
<tr><td>x</td><td>Permission</td><td>Execute</td></tr>
<tr><td>l</td><td>Permission</td><td>Mandatory locking, setgid bit is on, group execution bit is off</td></tr>
<tr><td>s</td><td>Permission</td><td>setuid or setgid bit is on</td></tr>
<tr><td>S</td><td>Permission</td><td>suid bit is on, user execution bit is off</td></tr>
<tr><td>t</td><td>Permission</td><td>Sticky bit is on, execution bit for others is on</td></tr>
<tr><td>T</td><td>Permission</td><td>Sticky bit is on, execution bit for others is off</td></tr>
</table>
<h3>How to Change Permissions in Absolute Mode</h3>
<p>If you are not the owner of the file or directory, become superuser.</p>
<p>Only the current owner or superuser can use the <code>chmod</code> command to change file permissions on a file or directory.</p>
<p>Change permissions in absolute mode by using the <code>chmod</code> command:</p>
<div class="command-box">
# Change file permissions using absolute mode
chmod nnn filename
</div>
<p><code>nnn</code> specifies the octal values that change permissions on the file or directory. See the table above for the list of valid octal values.</p>
<p><code>filename</code> is the file or directory.</p>
<p>Verify the permissions of the file have changed:</p>
<div class="command-box">
# Verify file permissions
ls -l filename
</div>
<h3>Example--Changing Permissions in Absolute Mode</h3>
<div class="command-box">
# Set rwxr-xr-x permissions on myfile
chmod 755 myfile
ls -l myfile
</div>
<h3>How to Change Permissions in Symbolic Mode</h3>
<p>If you are not the owner of the file or directory, become superuser.</p>
<p>Only the current owner or superuser can use the <code>chmod</code> command to change file permissions on a file or directory.</p>
<p>Change permissions in symbolic mode by using the <code>chmod</code> command:</p>
<div class="command-box">
# Change file permissions using symbolic mode
chmod who operator permission filename
</div>
<p><code>who</code> specifies whose permissions are changed, <code>operator</code> specifies the operation to perform, and <code>permission</code> specifies what permissions are changed. See the table above for the list of valid symbols.</p>
<p><code>filename</code> is the file or directory.</p>
<p>Verify the permissions of the file have changed:</p>
<div class="command-box">
# Verify file permissions
ls -l filename
</div>
<h3>Examples--Changing Permissions in Symbolic Mode</h3>
<div class="command-box">
# Take away read permission from others
chmod o-r filea
# Add read and execute permissions for user, group, and others
chmod a+rx fileb
# Assign read, write, and execute permissions to group
chmod g=rwx filec
</div>
</section>
<!-- Docker Section -->
<section id="docker" class="section">
<h2>4. Docker Deep Dive</h2>
<h3>Multi-Stage Dockerfile</h3>
<div class="best-practice">
Multi-stage builds reduce image size by separating build dependencies from runtime.
</div>
<div class="yaml-box">
# Build stage
FROM node:16-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
# Development dependencies
FROM node:16-alpine AS dev-deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
# Build application
FROM dev-deps AS build
COPY . .
RUN npm run build
# Production stage
FROM node:16-alpine AS runtime
RUN apk add --no-cache tini
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=build --chown=nodejs:nodejs /app/dist ./dist
USER nodejs
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "dist/index.js"]
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node healthcheck.js || exit 1
</div>
<h3>Docker Commands Reference</h3>
<div class="command-box">
# Container management
docker run -d \
--name myapp \
--restart unless-stopped \
--memory="512m" \
--cpus="0.5" \
-p 8080:80 \
-v $(pwd)/data:/data:ro \
--env-file .env \
myimage:latest
# Inspection and debugging
docker inspect container_id
docker stats
docker logs -f --tail 50 container_name
docker exec -it container_name sh
# Cleanup
docker system prune -a --volumes
docker image prune -a
docker container prune
docker volume prune
</div>
</section>
<!-- Kubernetes Section -->
<section id="kubernetes" class="section">
<h2>5. Kubernetes Complete Guide</h2>
<h3>Deployment with All Features</h3>
<div class="yaml-box">
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: app
image: myapp:v1
ports:
- containerPort: 8080
env:
- name: NODE_ENV
value: "production"
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "200m"
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
volumeMounts:
- name: config
mountPath: /etc/config
volumes:
- name: config
configMap:
name: app-config
</div>
<h3>Essential Kubectl Commands</h3>
<table class="command-table">
<tr>
<th>Category</th>
<th>Command</th>
</tr>
<tr>
<td>Cluster Info</td>
<td><code>kubectl cluster-info</code></td>
</tr>
<tr>
<td>Get Resources</td>
<td><code>kubectl get pods -o wide --all-namespaces</code></td>
</tr>
<tr>
<td>Describe</td>
<td><code>kubectl describe pod pod-name</code></td>
</tr>
<tr>
<td>Logs</td>
<td><code>kubectl logs -f pod-name --tail=50</code></td>
</tr>
<tr>
<td>Execute</td>
<td><code>kubectl exec -it pod-name -- /bin/bash</code></td>
</tr>
<tr>
<td>Port Forward</td>
<td><code>kubectl port-forward pod-name 8080:80</code></td>
</tr>
<tr>
<td>Scale</td>
<td><code>kubectl scale deployment app --replicas=5</code></td>
</tr>
<tr>
<td>Rollout</td>
<td><code>kubectl rollout status deployment/app</code></td>
</tr>
</table>
<!-- Added on 2025-12-03 14:54 -->
<h3>What is Ingress in Kubernetes?</h3>
<p>Ingress is a Kubernetes API object used to manage external access to services inside the cluster.</p>
<h3>Ingress is used to:</h3>
<ul>
<li>expose HTTP/HTTPS applications</li>
<li>route incoming traffic to different services</li>
<li>define host-based or path-based routing</li>
<li>handle SSL/TLS termination</li>
</ul>
<p>Ingress acts like a set of rules that tells Kubernetes:</p>
<div class="tip">👉 “When traffic comes from outside, where should it go?”</div>
<h3>What is an Ingress Controller?</h3>
<p>An Ingress Controller is the actual implementation that executes the rules defined in the Ingress object.</p>
<p>Ingress is only a configuration. It does nothing by itself. The Ingress Controller is responsible for processing those rules and routing the traffic.</p>
<h3>Examples of Ingress Controllers:</h3>
<ul>
<li>NGINX Ingress Controller</li>
<li>AWS ALB Ingress Controller</li>
<li>GKE Ingress</li>
<li>Traefik Ingress Controller</li>
<li>HAProxy Ingress</li>
</ul>
<h3>Simple Analogy</h3>
<p><strong>Ingress:</strong> Think of Ingress as a “traffic rulebook” written on paper.</p>
<p><strong>Ingress Controller:</strong> Think of the Ingress Controller as the “traffic police” who reads the rulebook and actually controls the traffic.</p>
<h3>Visual Diagram Explanation</h3>
<p>Internet</p>
<p>LoadBalancer</p>
<p>Ingress Controller</p>
<p>--------------------------------</p>
<p>/app1 → Service1</p>
<p>/app2 → Service2</p>
<p>/admin → Service3</p>
<p>The Ingress Controller reads these rules and handles routing.</p>
<h3>Summary</h3>
<table class="command-table">
<tr><th>Component</th><th>Meaning</th><th>Responsibility</th></tr>
<tr><td>Ingress</td><td>A set of routing rules</td><td>Defines how traffic should flow</td></tr>
<tr><td>Ingress Controller</td><td>The engine that applies the rules</td><td>Routes traffic to correct services</td></tr>
</table>
<!-- Added on 2025-12-03 16:05 -->
<div class="source-link" style="background: #e3f2fd; padding: 10px; border-radius: 5px; margin-bottom: 15px;">
📎 <strong>Source:</strong> <a href="https://drive.google.com/file/d/1Th3s1C9D85lwmkPcXXg6AfdngI3SWnx6/view?usp=drivesdk" target="_blank" style="color: #1976d2;">Kubernetes-Cheatsheet.pdf.pdf</a>
</div>
<h3>Basic Cluster Commands</h3>
<table class="command-table">
<tr><th>Command</th><th>Description</th></tr>
<tr><td><div class="command-box">kubectl version</div></td><td>Show client + server K8s version.</td></tr>
<tr><td><div class="command-box">kubectl cluster-info</div></td><td>See cluster master & DNS info.</td></tr>
<tr><td><div class="command-box">kubectl get all</div></td><td>List all resources (pods, svc, deployments, etc.) in default namespace.</td></tr>
</table>
<h3>Working With Contexts</h3>
<table class="command-table">
<tr><th>Command</th><th>Description</th></tr>
<tr><td><div class="command-box">kubectl config get-contexts</div></td><td>List all contexts (clusters).</td></tr>
<tr><td><div class="command-box">kubectl config use-context dev</div></td><td>Switch to another cluster.</td></tr>
<tr><td><div class="command-box">kubectl config current-context</div></td><td>Show which cluster you are using.</td></tr>
</table>
<h3>Namespaces</h3>
<table class="command-table">
<tr><th>Command</th><th>Description</th></tr>
<tr><td><div class="command-box">kubectl get namespaces</div></td><td>List namespaces.</td></tr>
<tr><td><div class="command-box">kubectl create namespace dev</div></td><td>Create namespace.</td></tr>
<tr><td><div class="command-box">kubectl delete namespace dev</div></td><td>Delete namespace.</td></tr>
<tr><td><div class="command-box">kubectl config set-context --current --namespace=dev</div></td><td>Set default namespace.</td></tr>
</table>
<h3>Pods</h3>
<table class="command-table">
<tr><th>Command</th><th>Description</th></tr>
<tr><td><div class="command-box">kubectl get pods</div></td><td>List pods.</td></tr>
<tr><td><div class="command-box">kubectl get pods -o wide</div></td><td>Show pod IP, node, etc.</td></tr>
<tr><td><div class="command-box">kubectl describe pod pod-name</div></td><td>Detailed pod info & events.</td></tr>
<tr><td><div class="command-box">kubectl logs pod-name</div></td><td>View logs.</td></tr>
<tr><td><div class="command-box">kubectl logs -f pod-name</div></td><td>Follow live logs.</td></tr>
<tr><td><div class="command-box">kubectl exec -it pod-name -- bash</div></td><td>Enter pod terminal.</td></tr>
<tr><td><div class="command-box">kubectl delete pod pod-name</div></td><td>Delete a pod.</td></tr>
</table>
<h3>Deployments</h3>
<table class="command-table">
<tr><th>Command</th><th>Description</th></tr>
<tr><td><div class="command-box">kubectl get deployments</div></td><td>List deployments.</td></tr>
<tr><td><div class="command-box">kubectl create deployment web --image=nginx</div></td><td>Create deployment.</td></tr>
<tr><td><div class="command-box">kubectl scale deployment web --replicas=5</div></td><td>Scale number of pods.</td></tr>
<tr><td><div class="command-box">kubectl rollout status deployment/web</div></td><td>Check deployment rollout status.</td></tr>
<tr><td><div class="command-box">kubectl rollout undo deployment/web</div></td><td>Rollback to previous version.</td></tr>
<tr><td><div class="command-box">kubectl delete deployment web</div></td><td>Delete deployment.</td></tr>
</table>
<h3>ReplicaSets</h3>
<table class="command-table">
<tr><th>Command</th><th>Description</th></tr>
<tr><td><div class="command-box">kubectl get rs</div></td><td>List ReplicaSets.</td></tr>
<tr><td><div class="command-box">kubectl describe rs rs-name</div></td><td>ReplicaSet details.</td></tr>
</table>