This commit is contained in:
Santiago Lo Coco 2023-11-17 20:21:23 -03:00
parent 4004c87e40
commit 492e06f2af
6 changed files with 80 additions and 38 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.venv
old-helm
old
old
consignas.txt

49
README.md Normal file
View File

@ -0,0 +1,49 @@
Todas las variables que se repiten y que, en un principio, no tendría sentido cambiarlas para este chart se marcaron con default.
Por ejemplo, busque los default de service.yaml. Verá que `type` es por defecto "ClusterIP" y que `targetPort` es por defecto `$port`.
Esto tiene dos beneficios:
1) Elimina redundancia en values.yaml
2) Da libertad para que en un futuro se pueda simplemente modificarlo en `values.yaml`. Por ejemplo, supongamos que queremos cambiar el `type` a "NodePort" en el servicio de `api`, basta con hacer el siguiente cambio:
```yaml
services:
- api:
name: "api"
tier: "backend"
port: 5000
type: "NodePort"
```
----------
En `ingress` se repite el `host` por dos razones:
1) Si quisieran que la api esté en otro dominio se pueda hacer fácilmente mediante:
```yaml
ingress:
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
hosts:
- host: kube.slc.ar
paths:
- path: /
name: "client"
port: 8080
pathType: "Prefix"
- host: api.kube.slc.ar
- path: /
name: "api"
port: 5000
pathType: "Prefix"
tls:
- secretName: exam-crt
hosts:
- kube.slc.ar
- api.kube.slc.ar
```
2) No se pueden reutilizar variables en YAML. Existe la posibilidad de usar YAML anchors pero en la [documentación](https://helm.sh/docs/chart_template_guide/yaml_techniques/#yaml-anchors) no lo recomiendan: "Because Helm and Kubernetes often read, modify, and then rewrite YAML files, the anchors will be lost."
TODO: probar igual los anchors

View File

@ -8,7 +8,7 @@ metadata:
app: {{ .name }}
{{- include "exam.labels" $ | nindent 4 }}
spec:
replicas: {{ .replicas }}
replicas: {{ default "1" .replicas }}
selector:
matchLabels:
app: {{ .name }}
@ -32,19 +32,22 @@ spec:
{{- if .env }}
env:
{{- with .env }}
{{- range $key, $val := .nonsecrets }}
{{- $envKey := $key | upper | replace "-" "_" }}
- name: {{ $envKey }}
value: {{ quote $val }}
{{- range $key, $val := . }}
{{- if ne "secrets" $key }}
{{- $envKey := $key | upper | replace "-" "_" }}
- name: {{ $envKey }}
value: {{ quote $val }}
{{- else }}
{{- range $key, $val := $val }}
{{- $envKey := $key | upper | replace "-" "_" }}
- name: {{ $envKey }}
valueFrom:
secretKeyRef:
# TODO
name: {{ include "exam.fullname" $ }}-secrets
key: {{ $val }}
{{- end }}
{{- end }}
{{- range $key, $val := .secrets }}
{{- $envKey := $key | upper | replace "-" "_" }}
- name: {{ $envKey }}
valueFrom:
secretKeyRef:
# TODO
name: {{ include "exam.fullname" $ }}-secrets
key: {{ $val }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -41,8 +41,8 @@ spec:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- if semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion }}
pathType: {{ default "ImplementationSpecific" .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}

View File

@ -8,10 +8,10 @@ metadata:
app: {{ $service.name }}
{{- include "exam.labels" $ | nindent 4 }}
spec:
type: {{ $service.type }}
type: {{ default "ClusterIP" $service.type }}
ports:
- port: {{ $service.port }}
targetPort: {{ $service.target }}
targetPort: {{ default $service.port $service.target }}
selector:
app: {{ $service.name }}
tier: {{ $service.tier }}

View File

@ -3,7 +3,6 @@ tls:
host: kube.slc.ar
ingress:
className: ""
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/ssl-redirect: "true"
@ -12,11 +11,9 @@ ingress:
- host: kube.slc.ar
paths:
- path: /()(.*)
pathType: ImplementationSpecific
name: "client"
port: 8080
- path: /api(/|$)(.*)
pathType: ImplementationSpecific
name: "api"
port: 5000
tls:
@ -29,21 +26,17 @@ services:
name: "api"
tier: "backend"
port: 5000
target: 0
type: ClusterIP
- postgres:
name: "db"
tier: "backend"
port: 5432
target: 0
type: ClusterIP
- client:
name: "client"
tier: "frontend"
port: 8080
target: 80
type: ClusterIP
- postgres:
name: "db"
tier: "backend"
port: 5432
# secrets.yaml
secrets:
username: "username"
password: "password1234"
@ -58,16 +51,14 @@ deployments:
name: "api"
tier: "backend"
env:
nonsecrets:
app-settings: src.config.ProductionConfig
port: "5000"
app-settings: src.config.ProductionConfig
port: "5000"
secrets:
database-url: database-url
image:
repository: api
tag: prod
port: 5000
replicas: 1
- client:
tier: "frontend"
name: "client"
@ -75,13 +66,12 @@ deployments:
repository: client
tag: prod
port: 8080
replicas: 1
replicas: 3
- db:
tier: "backend"
name: "db"
env:
nonsecrets:
pgdata: /var/lib/postgresql/data/pgdata
pgdata: /var/lib/postgresql/data/pgdata
secrets:
postgres-password: password
postgres-user: username
@ -89,6 +79,5 @@ deployments:
repository: db
tag: 13.3
port: 5432
replicas: 1
mountPath: /var/lib/postgresql/data
storage: postgres-pv-storage