La instalación y administración de Helm Charts puede generar algunas complicaciones que quizás no haya encontrado antes.
Helm Charts empaqueta aplicaciones para su instalaciĂłn en clĂşsteres de Kubernetes. La instalaciĂłn de Helm Chart es un poco como el lanzamiento
, por lo que los desarrolladores de Helm Chart enfrentan algunos de los mismos problemas que enfrentan los desarrolladores que crean instaladores:
- ¿Qué suposiciones puede hacer sobre el entorno en el que está instalando?
- ÂżPuede la aplicaciĂłn interactuar con otras aplicaciones?
- ÂżQuĂ© configuraciones deberĂan estar disponibles para el usuario y cĂłmo deberĂan ofrecerse?
Pero estas preguntas están relacionadas con los detalles de Helm. Para entender por qué, comencemos con una imagen de lo que sucede cuando el usuario inicia helm install
. Luego, podemos pasar a ver cómo algunos de los gráficos oficiales de Kubernetes abordan estos problemas.
Imagen de lanzamientohelm install
Quiero instalar MySQL en mi clĂşster. Pero no necesito la versiĂłn de MySQL que se stable/MySQL
instala en el archivo values.yaml en el repositorio oficial de gráficos . Entonces, creo mi propio archivo values.yaml
llamado mysql-values.yaml
con solo una lĂnea:
imageTag: “5.7.10”
Luego corro helm install stable/mysql --values=mysqlvalues.yaml
.
Helm (ignorant-camel
), MySQL . kubectl describe pod ignorant-camel-mysql-5dc6b947b-lf6p8
, imageTag
.
, , imageTag . helm install stabe/mysql --values=mysqlvalues.yaml --dry-run --debug
, Helm Kubernetes, .
Kubernetes , Helm Chart:
├── Chart.yaml ├── README.md ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── secrets.yaml │ └── ...more yaml... └── values.yaml
helm install stable/mysql
, values.yaml
Helm (, ) yaml , Kubernetes. helm install stable/mysql
, . , .
, values.yaml
— , , . , values.yaml
, , .
values.yaml
. , , . requirements.yaml
, , . , values.yaml
. , c Helm.
, ,
. , , — Helm Charts.
Helm
, Kubernetes . Helm Chart , , :
• , values.yaml
? , , , ?
• , , , ?
• , , (, )?
• , ?
, Helm Charts. , , , .
, , . Helm, . Helm , . .
, . , , , Helm 3 Lua. .
1.
, env, values.yaml
:
- name: ENV_VAR1 value: {{ .Values.var1 }} - name: ENV_VAR2 value: {{ .Values.var2 }}
values.yaml
--set var1=foo
. , ? , , (, ENV_VAR1
var1
)? , . , , ?
Helm Charts, configmap
. / . configmap, unbound.conf. , . configmap
, :
{{- range .Values.localRecords }} local-data: "{{ .name }} A {{ .ip }}" local-data-ptr: "{{ .ip }} {{ .name }}" {{- end }}
values.yaml localRecords
, :
localRecords: - name: "fake3.host.net" ip: "10.12.10.10" - name: "fake4.host.net" ip: "10.13.10.10"
Sonarqube chart , extraEnv
:
{{- range $key, $value := .Values.extraEnv }} — name: {{ $key }} value: {{ $value }} {{- end }}
values.yaml
, :
extraEnv: - ENV_VAR1: var1 - ENV_VAR2: var2
extraEnv
, . Buildkite , . values.yaml
:
{{- if .Values.extraEnv }} {{ toYaml .Values.extraEnv | indent 12 }} {{- end }}
, , , extraEnv
values.yaml
, (
) (
) , :
extraEnv: — name: ENV_VAR1 value: "var1" — name: ENV_VAR2 value: "var2"
Keycloak :
{{- with .Values.keycloak.extraEnv }} {{ tpl . $ | indent 12 }} {{- end }}
, extraEnv
, tpl
, , . , , :
extraEnv: | — name: KEYCLOAK_LOGLEVEL value: DEBUG — name: HOSTNAME value: {{ .Release.Name }}-keycloak
{{ .Release.Name }}
values.yaml
, , tpl
. , , , ( ). , values.yaml
, .
2.
, Helm, , ( ) . , , .
, , — . , Xray Postgres. , Postgres ( , , ):
{{- if .Values.postgresql.enabled }} — name: POSTGRES_USER value: {{ .Values.postgresql.postgresUser }} — name: POSTGRESS_PASSWORD valueFrom: secretKeyRef: name: {{ .Release.Name }}-postgresql key: postgres-password — name: POSTGRESS_DB value: {{ .Values.postgresql.postgresDatabase }} {{- else }} ...
Xray
, , Postgres. , , ? . ?
extraEnv
, Keycloak. extraEnv
, Postgres, . values.yaml
:
extraEnv: | — name: POSTGRES_USER value: {{ .Values.postgresql.postgresUser }} — name: POSTGRESS_PASSWORD valueFrom: secretKeyRef: name: {{ .Release.Name }}-postgresql key: postgres-password — name: POSTGRESS_DB value: {{ .Values.postgresql.postgresDatabase }}
|
, , tpl
.
, , configmap. — .Files.Get
. , values.yaml, , . , .Files.Get tpl. configmap , :
conf_file1: {{ tpl (.Files.Get "files/conf_file1") . | quote }}
Secret base64:
conf_file1: {{ tpl (.Files.Get "files/conf_file1") . | b64enc | quote }}
{{ (tpl (.Files.Glob "files/*").AsConfig . ) | indent 2 }}
AsSecret
, tpl
. , Glob Get :
{{ range $path, $bytes := .Files.Glob "files/*" }} {{ base $path }}: '{{ tpl ($root.Files.Get $path) . | b64enc }}' {{ end }}
3. -
extraEnv
Keycloak
, , , . , Keycloak Keycloak
, JSON
, Keycloak
. , extraVolumes
:
{{- with .Values.keycloak.extraVolumes }} {{ tpl . $ | indent 8 }} {{- end }}
extraVolumeMounts
:
volumeMounts: - name: scripts mountPath: /scripts {{- with .Values.keycloak.extraVolumeMounts }} {{ tpl . $ | indent 12 }} {{- end }}
extraVolumes: | — name: custom-secret secret: secretName: custom-secret extraVolumeMounts: | - name: custom-secret mountPath: "/realm/" readOnly: true
(volumes) volumeMounts
values.yaml
. , , initContainers
( sidecars
). , , .
Keycloak , preStartScript, :
{{- with .Values.keycloak.preStartScript }} echo 'Running custom pre-start script...' {{ . | indent 4 }} {{- end }}
, , .Values.keycloak.preStartScript
values.yaml
. , , .
4.
Helm, helm create
, (Service), Ingress. Ingress. , . , RabbitMQ, , Ingress :
{{- if .Values.ingress.enabled }} ... {{-end}
, RabbitMQ , (host-based):
rules: {{- if .Values.ingress.hostName }} - host: {{ .Values.ingress.hostName }} http: {{- else }} - http: {{- end }}
RabbitMQ ( else ). , (, RabbitMQ , ):
- path: {{ default "/" .path }} backend: serviceName: {{ template "rabbitmq.fullname" . }} servicePort: {{ .Values.rabbitmq.managerPort }}
, , .
{{- with .Values.ingress.annotations }} annotations: {{ toYaml . | indent 4 }} {{- end }}
values.yaml
, :
annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: /
, .yaml , , . , , , . , NGINX :
annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: / nginx.ingress.kubernetes.io/configuration-snippet: | more_set_headers 'Access-Control-Allow-Origin: $http_origin';
Art of the Helm Chart
Helm Chart , . , , . . , , , .
Hay otras cuestiones que no hemos cubierto, como las pruebas y la seguridad. Fue solo un vistazo a una pieza especĂfica de las listas oficiales. IntentĂ© concentrarme en patrones que encuentro particularmente Ăştiles para lograr que los usuarios hagan lo que quieran con sus gráficos. Los gráficos oficiales de Kubernetes han sido de gran ayuda para mĂ mientras trabajaba en los gráficos de Helm para el proyecto Activity . Con suerte, la explicaciĂłn en esta publicaciĂłn ayudará a alentar a otros a sumergirse en el repositorio oficial e inspirarse en sus gráficos.