Skip to content

Commit a85d00d

Browse files
authored
Merge pull request #14 from qobz1e/lab10
Lab10
2 parents dcc620c + 891ceb9 commit a85d00d

14 files changed

Lines changed: 744 additions & 0 deletions

File tree

k8s/HELM.md

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
2+
# Lab 10 — Helm Package Manager
3+
4+
![difficulty](https://img.shields.io/badge/difficulty-intermediate-yellow)
5+
![topic](https://img.shields.io/badge/topic-Helm-blue)
6+
![points](https://img.shields.io/badge/points-12%2B2.5-orange)
7+
![tech](https://img.shields.io/badge/tech-Helm-informational)
8+
9+
> Package your Kubernetes applications with Helm for reusable, configurable deployments across environments.
10+
11+
---
12+
13+
## Chart Overview
14+
15+
This Helm chart (`myapp`) converts Kubernetes manifests from Lab 9 into a reusable, configurable deployment system.
16+
17+
### Structure
18+
19+
```
20+
21+
myapp/
22+
├── Chart.yaml
23+
├── values.yaml
24+
├── values-dev.yaml
25+
├── values-prod.yaml
26+
└── templates/
27+
├── deployment.yaml
28+
├── service.yaml
29+
└── hooks/
30+
├── pre-install-job.yaml
31+
└── post-install-job.yaml
32+
33+
````
34+
35+
### Key Components
36+
37+
- **Deployment template** — runs the Python application with configurable replicas, image, and resources
38+
- **Service template** — exposes the application inside cluster (NodePort / ClusterIP)
39+
- **Values files** — environment-based configuration (dev/prod)
40+
- **Hooks** — lifecycle jobs executed before and after deployment
41+
42+
---
43+
44+
## Configuration Guide
45+
46+
### Main values (`values.yaml`)
47+
48+
- `replicaCount` — number of pods
49+
- `image.repository` — Docker image name
50+
- `image.tag` — image version
51+
- `service.port` — exposed port
52+
- `service.targetPort` — container port (5000)
53+
- `resources` — CPU/memory limits
54+
- `livenessProbe` — health check configuration
55+
- `readinessProbe` — readiness check configuration
56+
57+
### Dev environment (`values-dev.yaml`)
58+
59+
- 1 replica
60+
- lightweight CPU/memory limits
61+
- NodePort service
62+
- relaxed probes
63+
64+
### Prod environment (`values-prod.yaml`)
65+
66+
- 3–5 replicas
67+
- higher resource limits
68+
- LoadBalancer-ready configuration
69+
- stricter probes
70+
71+
### Example usage
72+
73+
```bash
74+
helm install myapp-dev ./myapp -f values-dev.yaml
75+
helm install myapp-prod ./myapp -f values-prod.yaml
76+
````
77+
78+
---
79+
80+
## Hook Implementation
81+
82+
### Pre-install hook
83+
84+
Executes before deployment starts.
85+
86+
* Used for initialization / validation
87+
* Runs a Kubernetes Job
88+
89+
### Post-install hook
90+
91+
Executes after deployment completes.
92+
93+
* Used for smoke tests or verification
94+
* Confirms application readiness
95+
96+
### Hook execution order
97+
98+
```
99+
Pre-install → Deploy resources → Post-install
100+
```
101+
102+
### Hook weights
103+
104+
* `-5` → pre-install (runs first)
105+
* `5` → post-install (runs last)
106+
107+
### Deletion policy
108+
109+
Hooks are configured with:
110+
111+
```
112+
hook-delete-policy: hook-succeeded
113+
```
114+
115+
This ensures:
116+
117+
* cleanup after successful execution
118+
* no leftover Jobs in cluster
119+
120+
---
121+
122+
## Installation Evidence
123+
124+
### Helm release list
125+
126+
```bash
127+
helm list
128+
```
129+
130+
📸 Screenshot: `lab10-set.png`
131+
132+
---
133+
134+
### Kubernetes resources
135+
136+
```bash
137+
kubectl get all
138+
```
139+
140+
📸 Screenshot: `lab10-set.png`
141+
142+
---
143+
144+
### Application running
145+
146+
```bash
147+
kubectl get pods
148+
kubectl get svc
149+
```
150+
151+
📸 Screenshot: `lab10-app.png`
152+
153+
---
154+
155+
### Hooks execution
156+
157+
```bash
158+
kubectl get jobs
159+
kubectl logs job/<pre-install-job>
160+
kubectl logs job/<post-install-job>
161+
```
162+
163+
📸 Screenshot: `lab10-hooks.png`
164+
165+
---
166+
167+
## Operations
168+
169+
### Install
170+
171+
```bash
172+
helm install myapp-release ./myapp
173+
```
174+
175+
### Upgrade
176+
177+
```bash
178+
helm upgrade myapp-release ./myapp
179+
```
180+
181+
### Rollback
182+
183+
```bash
184+
helm rollback myapp-release 1
185+
```
186+
187+
### Uninstall
188+
189+
```bash
190+
helm uninstall myapp-release
191+
```
192+
193+
---
194+
195+
## Testing & Validation
196+
197+
### Chart validation
198+
199+
```bash
200+
helm lint ./myapp
201+
```
202+
203+
### Template rendering
204+
205+
```bash
206+
helm template myapp ./myapp
207+
```
208+
209+
### Dry-run install
210+
211+
```bash
212+
helm install test ./myapp --dry-run --debug
213+
```
214+
215+
### Result
216+
217+
* Deployment successfully created
218+
* Service exposed via NodePort
219+
* Application accessible in browser via `http://localhost:8080`
220+
221+
---
222+
223+
## Summary
224+
225+
This Helm chart demonstrates:
226+
227+
* templating Kubernetes manifests
228+
* environment-based configuration
229+
* lifecycle hooks (pre/post install)
230+
* production-ready structure
231+
* reusable deployment patterns
232+
233+
Helm significantly improves maintainability, scalability, and repeatability of Kubernetes deployments.
234+
235+
---
236+
237+
## Screenshots
238+
239+
### Cluster setup & Helm state
240+
241+
![lab10-set](lab10-set.png)
242+
243+
### Application running
244+
245+
![lab10-app](lab10-app.png)
246+
247+
### Hooks execution
248+
249+
![lab10-hooks](lab10-hooks.png)

k8s/myapp/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

k8s/myapp/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: myapp
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"

k8s/myapp/templates/_helpers.tpl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "myapp.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "myapp.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "myapp.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "myapp.labels" -}}
37+
helm.sh/chart: {{ include "myapp.chart" . }}
38+
{{ include "myapp.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "myapp.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "myapp.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "myapp.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "myapp.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "myapp.fullname" . }}
5+
spec:
6+
replicas: {{ .Values.replicaCount }}
7+
selector:
8+
matchLabels:
9+
app: {{ include "myapp.name" . }}
10+
template:
11+
metadata:
12+
labels:
13+
app: {{ include "myapp.name" . }}
14+
spec:
15+
containers:
16+
- name: app
17+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
18+
ports:
19+
- containerPort: {{ .Values.service.targetPort }}
20+
resources:
21+
{{- toYaml .Values.resources | nindent 12 }}
22+
livenessProbe:
23+
httpGet:
24+
path: {{ .Values.livenessProbe.path }}
25+
port: {{ .Values.service.targetPort }}
26+
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
27+
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
28+
readinessProbe:
29+
httpGet:
30+
path: {{ .Values.readinessProbe.path }}
31+
port: {{ .Values.service.targetPort }}
32+
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
33+
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}

0 commit comments

Comments
 (0)