Skip to content

Commit ec6da44

Browse files
Introduction to K8s (#598)
2 parents 6321da5 + 6565824 commit ec6da44

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

Topics/Introduction_To_Kubernetes.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Kubernetes
2+
3+
## Table of Contents
4+
1. [Introduction](#Introduction)
5+
- [What is Kubernetes(k8s)?](#What-is-Kubernetes(k8s)?)
6+
- [Kubernetes vs Docker](#k8s-vs-docker)
7+
- [Why k8s?](#why-k8s)
8+
2. [CI/CD](#CI/CD)
9+
3. [Examples](#Examples)
10+
11+
## Introduction
12+
### What is Kubernetes(k8s)?
13+
14+
Kubernetes known as k8s is a cluster manage tool and distrubuted supporting platform to use automate, deploying, and scaling container.
15+
16+
### k8s vs Docker?
17+
Docker provides consistent environments for developing and running applications across different systems, isolating applications within containers, enabling deployment anywhere, optimizing resource utilization, implementing version control for images, and facilitating DevOps practices. This allows multiple processes to run on the same machine without interfering with each other during execution.
18+
19+
In contrast, Docker and Kubernetes (often abbreviated as k8s) are complementary technologies in containerization. Docker focuses on container creation and runtime, while Kubernetes addresses challenges in deploying and managing containers in production environments. Together, they form a powerful combination for modern application development and deployment workflows.
20+
21+
An illustrative analogy is imagining your program running within a box; the box represents Docker, while Kubernetes acts as the delivery person ensuring your box reaches the correct destination with the appropriate wrapping.
22+
23+
### why k8s?
24+
k8s played a significant role in cloud-native computing due to its ability to streamline the deployment and management of containerized applications at scale. K8s help improve resolve complex microservices architectures across distributed environments. It offers automated scaling, self-healing capabilities, and declarative configuration, empowering developers to focus on building robust and scalable applications without being bogged down by the complexities of infrastructure management.
25+
26+
27+
### CI/CD
28+
k8s with CI/CD practices revolutionizes the software development lifecycle, offering agility and efficiency. By integrating K8s with CI/CD pipelines, user can achieve faster release cycles, improved quality assurance, and greater overall productivity. CI/CD pipelines trigger automated tests and builds whenever new code is committed, with K8s enabling the seamless deployment of these changes into production environments. This integration ensures consistency between development, testing, and production environments, reducing the risk of errors and ensuring a smoother deployment process. With K8s and CI/CD, organizations can embrace a DevOps culture, delivering value to customers more quickly and efficiently while maintaining a high standard of readbilty and scalability in their applications.
29+
30+
### Examples
31+
32+
k8s are usually config in yaml format
33+
34+
Deployment: manage and scale applications. It defines the desired state for a set of pods (replica set) and ensures that the specified number of replicas are running at `all times`
35+
36+
`metadata` : is a unique name to identify the k8s resource
37+
38+
`spec`: define the state of this deployment
39+
40+
`replicas`: is the number of instances that will be running
41+
42+
with in `sepc` we can define which docker image we used, what port is the container exposed as well as the env var.
43+
```yaml
44+
apiVersion: apps/v1
45+
kind: Deployment
46+
metadata:
47+
name: example-deployment
48+
spec:
49+
replicas: 3
50+
selector:
51+
matchLabels:
52+
app: example-app
53+
template:
54+
metadata:
55+
labels:
56+
app: example-app
57+
spec:
58+
containers:
59+
- name: example-container
60+
image: nginx:latest
61+
ports:
62+
- containerPort: 80
63+
env:
64+
- name: USERNAME
65+
valueFrom:
66+
secretKeyRef:
67+
name: example-secret
68+
key: username
69+
- name: PASSWORD
70+
valueFrom:
71+
secretKeyRef:
72+
name: example-secret
73+
key: password
74+
volumeMounts:
75+
- name: config-volume
76+
mountPath: /etc/config
77+
volumes:
78+
- name: config-volume
79+
configMap:
80+
name: example-configmap
81+
82+
```
83+
k8s allows for dynamic patching of environment variables into containers using `Secrets` and `ConfigMaps`. `Secrets `typically safeguard vital credentials from unauthorized access, while `ConfigMaps` serve as repositories for local configurations that dictate application behavior. `Secrets` encode sensitive data like passwords and API tokens in a base64 format to maintain confidentiality, while `ConfigMaps` store non-sensitive settings such as environment variables and application configurations.
84+
```yaml
85+
apiVersion: v1
86+
kind: Secret
87+
metadata:
88+
name: example-secret
89+
type: Opaque
90+
data:
91+
username: <base64-encoded-username>
92+
password: <base64-encoded-password>
93+
---
94+
apiVersion: v1
95+
kind: ConfigMap
96+
metadata:
97+
name: example-configmap
98+
data:
99+
app-config.yaml: |
100+
key1: value1
101+
key2: value2
102+
---
103+
104+
```
105+
106+
CronJob: schedule and run tasks at specific times or intervals, similar to the cron utility in Unix-like operating systems. It allows users to define a job template and specify a schedule using the cron format.
107+
```yaml
108+
apiVersion: batch/v1beta1
109+
kind: CronJob
110+
metadata:
111+
name: example-cronjob
112+
spec:
113+
schedule: "*/1 * * * *"
114+
jobTemplate:
115+
spec:
116+
template:
117+
spec:
118+
containers:
119+
- name: example-container
120+
image: busybox
121+
command: ["echo", "Hello from the cron job"]
122+
restartPolicy: OnFailure
123+
```
124+
`schedule` takes an input unix-like, a really useful website would be `https://crontab.guru/`
125+
126+
Here is few examples:
127+
- `*/1 * * * *` : “At every minute.”
128+
- `0 * * * *` : "At the beginning of every hour."
129+
- `0 0 * * *`: "At midnight every day."
130+
- `0 9 * * MON-FRI`: "At 9:00 AM every weekday."
131+

0 commit comments

Comments
 (0)