diff --git a/k8s/HELM.md b/k8s/HELM.md new file mode 100644 index 0000000000..726e0ca50a --- /dev/null +++ b/k8s/HELM.md @@ -0,0 +1,428 @@ +# Chart Overview +### Chart structure explanation +Here is the file tree structure: + +``` +dinfochart/ +├── charts +├── Chart.yaml +├── templates +│   ├── deployment.yaml +│   ├── _helpers.tpl +│   ├── hooks +│   │   ├── post-install-job.yaml +│   │   └── pre-install-job.yaml +│   ├── NOTES.txt +│   └── service.yaml +├── values-dev.yaml +├── values-prod.yaml +└── values.yaml +``` + +### Key template files and their purpose +- `_helpers.tpl`: defines helpful values for templates +- `deployment.yaml`: defines the structure for the k8s deployment +- `service.yaml`: defines the structure for the k8s service + +### Values organization strategy +We extract the values or blocks that we would like to be configurable from the `.yaml` files into `values.yaml`, +preserving the original names for clarity. + +# Configuration Guide +### Important values and their purpose + +- `replicaCount`: number of pods that will be run. +- `image`: the information about which image to pull (name, tag) +- `service`: configuration for the reverse proxy +- `resources`: limits and reservations for memory and CPU time +- `livenessProbe`: command for checking the responsiveness of a container +- `readinessProbe`: command for checking the health of a container + +### How to customize for different environments +We define another value file with overrides and later supply it in the command: + +```bash +helm install myapp-dev k8s/mychart -f k8s/mychart/values-dev.yaml +``` + +Or specify overrides right in the command line: +```bash +helm install myapp k8s/mychart --set replicaCount=10 +``` + +### Example installations with different configurations +As shown in the lab material: +```bash +# Development +helm install myapp-dev k8s/mychart -f k8s/mychart/values-dev.yaml + +# Production +helm install myapp-prod k8s/mychart -f k8s/mychart/values-prod.yaml + +# Override specific value +helm install myapp k8s/mychart --set replicaCount=10 +``` + +# Hook Implementation +### What hooks you implemented and why +I implemented the pre-install hook and the post-install one. I did that because it was prescribed by the lab. + +### Hook execution order and weights +Hook | Order | Weight +------------------------------ +Pre-install | Before | -5 +Post-install | After | 5 + +### Deletion policies explanation +It allows to set a rule that dictates when the executed hook jobs will be deleted. `before-hook-creation` means right +before the hook is run, its previous invokation will be deleted. `hook-succeeded` and `hook-failed` delete the hook +immediately after it succeeds or fails (respectively). + +# Installation Evidence +### `helm list` output +```text +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +myrelease default 1 2026-04-02 18:01:48.36966193 +0300 MSK deployed dinfochart-0.1.0 1.1.1 +``` + +### `kubectl get all` showing deployed resources +```text +NAME READY STATUS RESTARTS AGE +pod/myrelease-dinfochart-5b67fb98d9-2jk9d 1/1 Running 0 22m +pod/myrelease-dinfochart-5b67fb98d9-8c448 1/1 Running 0 22m +pod/myrelease-dinfochart-5b67fb98d9-fq5mz 1/1 Running 0 22m +pod/myrelease-dinfochart-5b67fb98d9-v5zjk 1/1 Running 0 22m +pod/myrelease-dinfochart-5b67fb98d9-wtx52 1/1 Running 0 22m + +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +service/kubernetes ClusterIP 10.96.0.1 443/TCP 9d +service/myrelease-dinfochart NodePort 10.102.118.72 80:30952/TCP 22m + +NAME READY UP-TO-DATE AVAILABLE AGE +deployment.apps/myrelease-dinfochart 5/5 5 5 22m + +NAME DESIRED CURRENT READY AGE +replicaset.apps/myrelease-dinfochart-5b67fb98d9 5 5 5 22m +``` +### Hook execution output (`kubectl get jobs`, `kubectl describe job`) +As per the deletion policy, the hook jobs get deleted after they run and succeed, which is my case. These commands +report errors because there are no jobs to inspect. + +### Different environment deployments (dev vs prod) +`dev` is for testing the latest changes (with the `latest` tag, plenty of resources). + +`prod` is for deployment on a real cluster (with a fixed version and limited resources). + +# Operations +### Installation commands used +```text +helm install [-f ] +``` + +### How to upgrade a release +```bash +helm upgrade myrelease ./mychart +``` + +### How to rollback +```bash +helm rollback myrelease 1 +``` + +### How to uninstall +```bash +helm uninstall myrelease +``` + +# Testing & Validation +### `helm lint` output +```text +==> Linting dinfochart/ +[INFO] Chart.yaml: icon is recommended + +1 chart(s) linted, 0 chart(s) failed +``` + +### `helm template` verification +```yaml +--- +# Source: dinfochart/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: release-name-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + type: NodePort + selector: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + ports: + - protocol: TCP + port: 80 + targetPort: 5000 +--- +# Source: dinfochart/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: release-name-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 5 + selector: + matchLabels: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 # Extra pods during update + maxUnavailable: 0 # Ensure availability + template: + metadata: + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + spec: + containers: + - name: dinfochart + image: "timurusmanov/devops-infoservice:1.1.1" + ports: + - containerPort: 80 + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 3 +--- +# Source: dinfochart/templates/hooks/post-install-job.yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: 'release-name-dinfochart-post-install' + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": post-install + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: 'release-name-dinfochart-post-install' + spec: + restartPolicy: Never + containers: + - name: post-install-job + image: busybox + command: ['sh', '-c', 'echo Post-install validation && sleep 1 && echo Validation passed'] +--- +# Source: dinfochart/templates/hooks/pre-install-job.yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: 'release-name-dinfochart-pre-install' + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: release-name + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: 'release-name-dinfochart-pre-install' + spec: + restartPolicy: Never + containers: + - name: pre-install-job + image: busybox + command: ['sh', '-c', 'echo Pre-install task running && sleep 1 && echo Pre-install completed'] +``` + +### Dry-run output +```yaml +NAME: test-release +LAST DEPLOYED: Thu Apr 2 18:29:57 2026 +NAMESPACE: default +STATUS: pending-install +REVISION: 1 +DESCRIPTION: Dry run complete +TEST SUITE: None +HOOKS: +--- +# Source: dinfochart/templates/hooks/post-install-job.yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: 'test-release-dinfochart-post-install' + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": post-install + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: 'test-release-dinfochart-post-install' + spec: + restartPolicy: Never + containers: + - name: post-install-job + image: busybox + command: ['sh', '-c', 'echo Post-install validation && sleep 1 && echo Validation passed'] +--- +# Source: dinfochart/templates/hooks/pre-install-job.yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: 'test-release-dinfochart-pre-install' + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: 'test-release-dinfochart-pre-install' + spec: + restartPolicy: Never + containers: + - name: pre-install-job + image: busybox + command: ['sh', '-c', 'echo Pre-install task running && sleep 1 && echo Pre-install completed'] +MANIFEST: +--- +# Source: dinfochart/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: test-release-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + type: NodePort + selector: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + ports: + - protocol: TCP + port: 80 + targetPort: 5000 +--- +# Source: dinfochart/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-release-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 5 + selector: + matchLabels: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 # Extra pods during update + maxUnavailable: 0 # Ensure availability + template: + metadata: + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + spec: + containers: + - name: dinfochart + image: "timurusmanov/devops-infoservice:1.1.1" + ports: + - containerPort: 80 + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 3 +``` + +### Application accessibility verification +```bash +kubectl port-forward service/myrelease-dinfochart 8080:80 & +curl localhost:8080/health +``` +```json +{"status":"healthy","timestamp":"2026-04-02T15:35:47.354190+00:00","uptime_seconds":2010} +``` diff --git a/k8s/LAB10.md b/k8s/LAB10.md new file mode 100644 index 0000000000..02f6061fef --- /dev/null +++ b/k8s/LAB10.md @@ -0,0 +1,447 @@ +# Task 1 + +### Installation +```sh +sudo pacman -S --needed helm +``` +```text +warning: helm-4.1.3-1 is up to date -- skipping + there is nothing to do +``` + +### Version +```sh +helm version +``` +```text +version.BuildInfo{Version:"v4.1.3", GitCommit:"c94d381b03be117e7e57908edbf642104e00eb8f", GitTreeState:"", GoVersion:"go1.26.1-X:nodwarf5", KubeClientVersion:"v1.35"} +``` + +### Output of exploring a public chart + +```sh +helm show chart prometheus-community/prometheus +``` +```yaml +annotations: + artifacthub.io/license: Apache-2.0 + artifacthub.io/links: | + - name: Chart Source + url: https://github.com/prometheus-community/helm-charts + - name: Upstream Project + url: https://github.com/prometheus/prometheus +apiVersion: v2 +appVersion: v3.10.0 +dependencies: +- condition: alertmanager.enabled + name: alertmanager + repository: https://prometheus-community.github.io/helm-charts + version: 1.34.* +- condition: kube-state-metrics.enabled + name: kube-state-metrics + repository: https://prometheus-community.github.io/helm-charts + version: 7.2.* +- condition: prometheus-node-exporter.enabled + name: prometheus-node-exporter + repository: https://prometheus-community.github.io/helm-charts + version: 4.52.* +- condition: prometheus-pushgateway.enabled + name: prometheus-pushgateway + repository: https://prometheus-community.github.io/helm-charts + version: 3.6.* +description: Prometheus is a monitoring system and time series database. +home: https://prometheus.io/ +icon: https://raw.githubusercontent.com/prometheus/prometheus.github.io/master/assets/prometheus_logo-cb55bb5c346.png +keywords: +- monitoring +- prometheus +kubeVersion: '>=1.19.0-0' +maintainers: +- email: gianrubio@gmail.com + name: gianrubio + url: https://github.com/gianrubio +- email: zanhsieh@gmail.com + name: zanhsieh + url: https://github.com/zanhsieh +- email: miroslav.hadzhiev@gmail.com + name: Xtigyro + url: https://github.com/Xtigyro +- email: naseem@transit.app + name: naseemkullah + url: https://github.com/naseemkullah +- email: rootsandtrees@posteo.de + name: zeritti + url: https://github.com/zeritti +name: prometheus +sources: +- https://github.com/prometheus/alertmanager +- https://github.com/prometheus/prometheus +- https://github.com/prometheus/pushgateway +- https://github.com/prometheus/node_exporter +- https://github.com/kubernetes/kube-state-metrics +type: application +version: 28.14.1 +``` + +# Task 2 + +```sh +helm lint dinfochart +``` +```text +==> Linting dinfochart +[INFO] Chart.yaml: icon is recommended + +1 chart(s) linted, 0 chart(s) failed +``` + +```sh +helm template dinfochart dinfochart/ +``` +```yaml +--- +# Source: dinfochart/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: dinfochart + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + type: NodePort + selector: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: dinfochart + ports: + - protocol: TCP + port: 80 + targetPort: 5000 +--- +# Source: dinfochart/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: dinfochart + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 5 + selector: + matchLabels: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: dinfochart + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 # Extra pods during update + maxUnavailable: 0 # Ensure availability + template: + metadata: + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: dinfochart + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + spec: + containers: + - name: dinfochart + image: "timurusmanov/devops-infoservice:1.1.1" + ports: + - containerPort: 80 + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 3 +``` + +```sh +helm install --dry-run --debug test-release dinfochart/ +``` +```text +level=WARN msg="--dry-run is deprecated and should be replaced with '--dry-run=client'" +level=DEBUG msg="Original chart version" version="" +level=DEBUG msg="Chart path" path=/home/timur/proj/DevOps-Core-Course/k8s/dinfochart +level=DEBUG msg="number of dependencies in the chart" chart=dinfochart dependencies=0 +NAME: test-release +LAST DEPLOYED: Thu Apr 2 17:17:49 2026 +NAMESPACE: default +STATUS: pending-install +REVISION: 1 +DESCRIPTION: Dry run complete +TEST SUITE: None +USER-SUPPLIED VALUES: +{} + +COMPUTED VALUES: +image: + pullPolicy: IfNotPresent + repository: timurusmanov/devops-infoservice + tag: 1.1.1 +livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 +readinessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 3 +replicaCount: 5 +resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi +service: + port: 80 + targetPort: 5000 + type: NodePort + +HOOKS: +MANIFEST: +--- +# Source: dinfochart/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: test-release-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + type: NodePort + selector: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + ports: + - protocol: TCP + port: 80 + targetPort: 5000 +--- +# Source: dinfochart/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-release-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 5 + selector: + matchLabels: + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 # Extra pods during update + maxUnavailable: 0 # Ensure availability + template: + metadata: + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + spec: + containers: + - name: dinfochart + image: "timurusmanov/devops-infoservice:1.1.1" + ports: + - containerPort: 80 + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + livenessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 3 + +``` + +```sh +helm install myrelease dinfochart/ +``` +```text +NAME: myrelease +LAST DEPLOYED: Thu Apr 2 17:18:20 2026 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +DESCRIPTION: Install complete +TEST SUITE: None +``` + +# Task 4 + +```sh +# Lint chart +helm lint k8s/dinfochart +``` +```text +==> Linting k8s/dinfochart +[INFO] Chart.yaml: icon is recommended + +1 chart(s) linted, 0 chart(s) failed +``` + +```sh +# Dry run to see hooks +helm install --dry-run=client --debug test-release k8s/dinfochart | grep -A 20 "HOOK\|hook" +``` +```text +level=DEBUG msg="Original chart version" version="" +level=DEBUG msg="Chart path" path=/home/timur/proj/DevOps-Core-Course/k8s/dinfochart +level=DEBUG msg="number of dependencies in the chart" chart=dinfochart dependencies=0 +HOOKS: +--- +# Source: dinfochart/templates/hooks/post-install-job.yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: 'test-release-dinfochart-post-install' + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": post-install + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: 'test-release-dinfochart-post-install' + spec: + restartPolicy: Never + containers: + - name: post-install-job + image: busybox + command: ['sh', '-c', 'echo Post-install validation && sleep 1 && echo Validation passed'] +--- +# Source: dinfochart/templates/hooks/pre-install-job.yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: 'test-release-dinfochart-pre-install' + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart + app.kubernetes.io/instance: test-release + app.kubernetes.io/version: "1.1.1" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: 'test-release-dinfochart-pre-install' + spec: + restartPolicy: Never + containers: + - name: pre-install-job + image: busybox + command: ['sh', '-c', 'echo Pre-install task running && sleep 1 && echo Pre-install completed'] +MANIFEST: +--- +# Source: dinfochart/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: test-release-dinfochart + labels: + helm.sh/chart: dinfochart-0.1.0 + app.kubernetes.io/name: dinfochart +``` + +```sh +# Install and watch hooks +helm install myrelease k8s/dinfochart +kubectl get jobs -w +kubectl get pods -w +``` +```text +NAME: myrelease +LAST DEPLOYED: Thu Apr 2 18:01:48 2026 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +DESCRIPTION: Install complete +TEST SUITE: None +``` +```text +No resources found in default namespace. +``` +```text +NAME READY STATUS RESTARTS AGE +myrelease-dinfochart-5b67fb98d9-2jk9d 1/1 Running 0 39s +myrelease-dinfochart-5b67fb98d9-8c448 1/1 Running 0 39s +myrelease-dinfochart-5b67fb98d9-fq5mz 1/1 Running 0 39s +myrelease-dinfochart-5b67fb98d9-v5zjk 1/1 Running 0 39s +myrelease-dinfochart-5b67fb98d9-wtx52 1/1 Running 0 39s +``` + +```sh +# Verify deletion policy worked +kubectl get jobs +``` +```text +No resources found in default namespace. +``` + +# Task 5 + +Refer to `k8s/HELM.md`. diff --git a/k8s/SECRETS.md b/k8s/SECRETS.md new file mode 100644 index 0000000000..79a74ca774 --- /dev/null +++ b/k8s/SECRETS.md @@ -0,0 +1,155 @@ +# Kubernetes Secrets +### Output of creating and viewing your secret +```sh +kubectl get secret app-credentials -o yaml +``` +```text +apiVersion: v1 +data: + password: YWRtaW4xMjM= + username: dGltdXI= +kind: Secret +metadata: + creationTimestamp: "2026-04-08T14:10:34Z" + name: app-credentials + namespace: default + resourceVersion: "7121" + uid: cde19220-e95a-4b61-9386-b6b8f4b37f45 +type: Opaque +``` + +### Decoded secret values demonstration +```sh +base64 -d <<<"dGltdXI=" +``` +```text +timur +``` +```sh +base64 -d <<<"YWRtaW4xMjM=" +``` +```text +admin123 +``` + +### Explanation of base64 encoding vs encryption +`base64`-encoding is is still plaintext: it obfuscates the information to a human reader, but the data is decodeable +with one command. + +Real encryption requires the attacker to guess a key, which should be difficult to do. + +# Helm Secret Integration +### Chart structure showing secrets.yaml +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: app-credentials +type: Opaque +stringData: + username: {{ .Values.secret.username | quote }} + password: {{ .Values.secret.password | quote }} +``` + +### How secrets are consumed in deployment +Secrets are consumed through environment variables. + +### Verification output (env vars in pod, excluding actual values) +```sh +kubectl exec dinfoserv-dinfochart-575476d846-4424h -- env +``` +```text +PATH=/venv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +HOSTNAME=dinfoserv-dinfochart-575476d846-4424h +username=placeholder +password=placeholder +DINFOSERV_DINFOCHART_PORT_80_TCP=tcp://10.100.233.185:80 +DINFOSERV_DINFOCHART_PORT_80_TCP_PROTO=tcp +KUBERNETES_PORT=tcp://10.96.0.1:443 +KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443 +DINFOSERV_DINFOCHART_PORT_80_TCP_PORT=80 +KUBERNETES_SERVICE_HOST=10.96.0.1 +KUBERNETES_SERVICE_PORT_HTTPS=443 +KUBERNETES_PORT_443_TCP_PORT=443 +KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1 +DINFOSERV_DINFOCHART_SERVICE_HOST=10.100.233.185 +DINFOSERV_DINFOCHART_SERVICE_PORT=80 +DINFOSERV_DINFOCHART_PORT=tcp://10.100.233.185:80 +DINFOSERV_DINFOCHART_PORT_80_TCP_ADDR=10.100.233.185 +KUBERNETES_SERVICE_PORT=443 +KUBERNETES_PORT_443_TCP_PROTO=tcp +GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305 +PYTHON_VERSION=3.13.12 +PYTHON_SHA256=2a84cd31dd8d8ea8aaff75de66fc1b4b0127dd5799aa50a64ae9a313885b4593 +VIRTUAL_ENV=/venv +HOME=/home/infoservice +``` + +Note the "username" and "password" env variables. + +# Resource Management +### Resource limits configuration +Resource limits are configured with the `values` files. + +### Explanation of requests vs limits +Requests = how much is guaranteed. +Limits = how much is the hard maximum. + +### How to choose appropriate values +In the development environment, give more resources to debug and test. +In production, look at the cluster and see how much is available. Then assign that much as the limit. Requests are the +minimal requirements for the containers to function at all. + +# Vault Integration +### Vault installation verification (`kubectl get pods`) +```text +NAME READY STATUS RESTARTS AGE +dinfoserv-dinfochart-b9cc59fdf-2dv4n 2/2 Running 0 4m4s +dinfoserv-dinfochart-b9cc59fdf-6chxr 2/2 Running 0 4m4s +dinfoserv-dinfochart-b9cc59fdf-b6cqg 2/2 Running 0 4m4s +dinfoserv-dinfochart-b9cc59fdf-fkfwn 2/2 Running 0 4m4s +dinfoserv-dinfochart-b9cc59fdf-nh9r2 2/2 Running 0 4m4s +vault-0 1/1 Running 0 15h +vault-agent-injector-848dd747d7-b2pt4 1/1 Running 0 15h +``` + +### Policy and role configuration (sanitized) +Policy: +```sh +cat >dinfoservice-secret-access.hcl <