Skip to content

Commit c62920f

Browse files
authored
Merge pull request #10 from kolayne-IU-assignments/lab10
Lab10
2 parents f074d3d + 0867d55 commit c62920f

31 files changed

+1103
-0
lines changed

k8s/HELM.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Helm
2+
3+
## Helm chart
4+
5+
```
6+
$ kubectl get pods,svc
7+
NAME READY STATUS RESTARTS AGE
8+
pod/app-py-774b8c9bc-4zqvs 1/1 Running 0 20s
9+
pod/app-py-774b8c9bc-6tg64 1/1 Running 0 4m57s
10+
pod/app-py-774b8c9bc-mhm8j 1/1 Running 0 4m57s
11+
pod/app-py-774b8c9bc-zsb2b 1/1 Running 0 4m57s
12+
13+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
14+
service/app-py LoadBalancer 10.106.188.219 <pending> 5000:30928/TCP 4m57s
15+
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21m
16+
$
17+
```
18+
19+
## Helm hooks
20+
21+
```
22+
$ kubectl get po
23+
NAME READY STATUS RESTARTS AGE
24+
app-py-774b8c9bc-2rfbf 1/1 Running 0 86s
25+
app-py-774b8c9bc-6dz7d 1/1 Running 0 86s
26+
app-py-774b8c9bc-bzpqf 1/1 Running 0 86s
27+
app-py-774b8c9bc-z9l76 1/1 Running 0 86s
28+
post-install-hook 0/1 Completed 0 86s
29+
pre-install-hook 0/1 Completed 0 100s
30+
$ kubectl describe po pre-install-hook
31+
Name: pre-install-hook
32+
Namespace: default
33+
Priority: 0
34+
Service Account: default
35+
Node: minikube/192.168.49.2
36+
Start Time: Sun, 31 Mar 2024 22:15:29 +0300
37+
Labels: <none>
38+
Annotations: helm.sh/hook: pre-install
39+
Status: Succeeded
40+
IP: 10.244.0.25
41+
IPs:
42+
IP: 10.244.0.25
43+
Containers:
44+
sleep-5:
45+
Container ID: docker://dd1fcb8f5e49cb0a4b655c1b50f86980b777448f40b9efb10b188e62b4faf181
46+
Image: busybox
47+
Image ID: docker-pullable://busybox@sha256:c3839dd800b9eb7603340509769c43e146a74c63dca3045a8e7dc8ee07e53966
48+
Port: <none>
49+
Host Port: <none>
50+
Command:
51+
sleep
52+
Args:
53+
5
54+
State: Terminated
55+
Reason: Completed
56+
Exit Code: 0
57+
Started: Sun, 31 Mar 2024 22:15:35 +0300
58+
Finished: Sun, 31 Mar 2024 22:15:40 +0300
59+
Ready: False
60+
Restart Count: 0
61+
Environment: <none>
62+
Mounts:
63+
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-52w28 (ro)
64+
Conditions:
65+
Type Status
66+
Initialized True
67+
Ready False
68+
ContainersReady False
69+
PodScheduled True
70+
Volumes:
71+
kube-api-access-52w28:
72+
Type: Projected (a volume that contains injected data from multiple sources)
73+
TokenExpirationSeconds: 3607
74+
ConfigMapName: kube-root-ca.crt
75+
ConfigMapOptional: <nil>
76+
DownwardAPI: true
77+
QoS Class: BestEffort
78+
Node-Selectors: <none>
79+
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
80+
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
81+
Events:
82+
Type Reason Age From Message
83+
---- ------ ---- ---- -------
84+
Normal Scheduled 106s default-scheduler Successfully assigned default/pre-install-hook to minikube
85+
Normal Pulling 103s kubelet Pulling image "busybox"
86+
Normal Pulled 101s kubelet Successfully pulled image "busybox" in 2.166s (2.167s including waiting)
87+
Normal Created 100s kubelet Created container sleep-5
88+
Normal Started 100s kubelet Started container sleep-5
89+
$ kubectl describe po post-install-hook
90+
Name: post-install-hook
91+
Namespace: default
92+
Priority: 0
93+
Service Account: default
94+
Node: minikube/192.168.49.2
95+
Start Time: Sun, 31 Mar 2024 22:15:43 +0300
96+
Labels: <none>
97+
Annotations: helm.sh/hook: post-install
98+
Status: Succeeded
99+
IP: 10.244.0.29
100+
IPs:
101+
IP: 10.244.0.29
102+
Containers:
103+
sleep-10:
104+
Container ID: docker://90f8d485d239cb251abb96bed98bb057023e0026bd0f44a519f4020c04e10b8e
105+
Image: busybox
106+
Image ID: docker-pullable://busybox@sha256:c3839dd800b9eb7603340509769c43e146a74c63dca3045a8e7dc8ee07e53966
107+
Port: <none>
108+
Host Port: <none>
109+
Command:
110+
sleep
111+
Args:
112+
10
113+
State: Terminated
114+
Reason: Completed
115+
Exit Code: 0
116+
Started: Sun, 31 Mar 2024 22:15:49 +0300
117+
Finished: Sun, 31 Mar 2024 22:15:59 +0300
118+
Ready: False
119+
Restart Count: 0
120+
Environment: <none>
121+
Mounts:
122+
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-nlrcb (ro)
123+
Conditions:
124+
Type Status
125+
Initialized True
126+
Ready False
127+
ContainersReady False
128+
PodScheduled True
129+
Volumes:
130+
kube-api-access-nlrcb:
131+
Type: Projected (a volume that contains injected data from multiple sources)
132+
TokenExpirationSeconds: 3607
133+
ConfigMapName: kube-root-ca.crt
134+
ConfigMapOptional: <nil>
135+
DownwardAPI: true
136+
QoS Class: BestEffort
137+
Node-Selectors: <none>
138+
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
139+
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
140+
Events:
141+
Type Reason Age From Message
142+
---- ------ ---- ---- -------
143+
Normal Scheduled 99s default-scheduler Successfully assigned default/post-install-hook to minikube
144+
Normal Pulling 97s kubelet Pulling image "busybox"
145+
Normal Pulled 95s kubelet Successfully pulled image "busybox" in 2.015s (2.015s including waiting)
146+
Normal Created 95s kubelet Created container sleep-10
147+
Normal Started 94s kubelet Started container sleep-10
148+
$ kubectl get pods,svc
149+
NAME READY STATUS RESTARTS AGE
150+
pod/app-py-774b8c9bc-hv6tg 1/1 Running 0 67s
151+
pod/app-py-774b8c9bc-p2v9s 1/1 Running 0 67s
152+
pod/app-py-774b8c9bc-r22dh 1/1 Running 0 67s
153+
pod/app-py-774b8c9bc-svlbm 1/1 Running 0 67s
154+
155+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
156+
service/app-py LoadBalancer 10.111.233.19 <pending> 5000:31628/TCP 67s
157+
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 113m
158+
$
159+
```

k8s/app-go/.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/app-go/Chart.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: label-lib
3+
repository: file://../label-lib
4+
version: 0.1.0
5+
digest: sha256:d33e74eddc07f8914537b87b237d90f30af5d0015d167f8d673ebe25f86c923f
6+
generated: "2024-03-31T22:48:15.070549349+03:00"

k8s/app-go/Chart.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: app-py
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+
dependencies:
21+
- name: label-lib
22+
version: 0.1.0
23+
repository: file://../label-lib

k8s/app-go/templates/NOTES.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "app-py.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "app-py.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "app-py.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "app-py.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
20+
echo "Visit http://127.0.0.1:8080 to use your application"
21+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
22+
{{- end }}

k8s/app-go/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 "app-py.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 "app-py.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 "app-py.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "app-py.labels" -}}
37+
helm.sh/chart: {{ include "app-py.chart" . }}
38+
{{ include "app-py.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 "app-py.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "app-py.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 "app-py.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "app-py.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

k8s/app-go/templates/deployment.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "app-py.fullname" . }}
5+
labels:
6+
{{- include "app-py.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "app-py.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "app-py.labels" . | nindent 8 }}
22+
{{- with .Values.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
30+
serviceAccountName: {{ include "app-py.serviceAccountName" . }}
31+
securityContext:
32+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
33+
containers:
34+
- name: {{ .Chart.Name }}
35+
securityContext:
36+
{{- toYaml .Values.securityContext | nindent 12 }}
37+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
38+
imagePullPolicy: {{ .Values.image.pullPolicy }}
39+
ports:
40+
- name: http
41+
containerPort: {{ .Values.service.port }}
42+
protocol: TCP
43+
livenessProbe:
44+
{{- toYaml .Values.livenessProbe | nindent 12 }}
45+
readinessProbe:
46+
{{- toYaml .Values.readinessProbe | nindent 12 }}
47+
resources:
48+
{{- toYaml .Values.resources | nindent 12 }}
49+
{{- with .Values.volumeMounts }}
50+
volumeMounts:
51+
{{- toYaml . | nindent 12 }}
52+
{{- end }}
53+
{{- with .Values.volumes }}
54+
volumes:
55+
{{- toYaml . | nindent 8 }}
56+
{{- end }}
57+
{{- with .Values.nodeSelector }}
58+
nodeSelector:
59+
{{- toYaml . | nindent 8 }}
60+
{{- end }}
61+
{{- with .Values.affinity }}
62+
affinity:
63+
{{- toYaml . | nindent 8 }}
64+
{{- end }}
65+
{{- with .Values.tolerations }}
66+
tolerations:
67+
{{- toYaml . | nindent 8 }}
68+
{{- end }}

0 commit comments

Comments
 (0)