任何人都可以帮助我理解这个命令 - 这个键值对的输出是什么:
JAVA_OPTS_APPEND: {{ printf "-Djgroups.dns.query=%s-headless.%s.svc.%s" (include "common.names.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain | quote }}
哪里
common.names.fullname: ""
common.names.namespace: ""
clusterDomain: cluster.local
这段代码来自这里: https://github.com/bitnami/charts/blob/main/bitnami/keycloak/templates/configmap-env-vars.yaml
我对 Kubernetes 相当陌生,我正在尝试了解 JAVA_OPTS_APPEND 的价值。
提前致谢。 纳菲
helm template
命令在本地渲染 helm 模板,这将渲染您的值,以便您看到此命令的输出。
如果您的 Kubernetes 集群没有足够的权限,您可以旋转本地
mininkube
或 kind
实例,然后渲染模板:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm template bitnami/keycloak --namespace mhajeb
在渲染的清单中,您将找到以下 ConfigMap:
# Source: keycloak/templates/configmap-env-vars.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: release-name-keycloak-env-vars
namespace: "mhajeb"
labels:
app.kubernetes.io/name: keycloak
helm.sh/chart: keycloak-13.0.4
app.kubernetes.io/instance: release-name
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: keycloak
data:
KEYCLOAK_ADMIN: "user"
KEYCLOAK_HTTP_PORT: "8080"
KEYCLOAK_PROXY: "passthrough"
KEYCLOAK_ENABLE_STATISTICS: "false"
KEYCLOAK_DATABASE_HOST: "release-name-postgresql"
KEYCLOAK_DATABASE_PORT: "5432"
KEYCLOAK_DATABASE_NAME: "bitnami_keycloak"
KEYCLOAK_DATABASE_USER: "bn_keycloak"
KEYCLOAK_PRODUCTION: "false"
KEYCLOAK_ENABLE_HTTPS: "false"
KEYCLOAK_CACHE_TYPE: "ispn"
KEYCLOAK_CACHE_STACK: "kubernetes"
JAVA_OPTS_APPEND: "-Djgroups.dns.query=release-name-keycloak-headless.mhajeb.svc.cluster.local"
KEYCLOAK_LOG_OUTPUT: "default"
KC_LOG_LEVEL: "INFO"
现在请注意
JAVA_OPTS_APPEND: {{ printf "-Djgroups.dns.query=%s-headless.%s.svc.%s" (include "common.names.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain | quote }}
呈现:
JAVA_OPTS_APPEND: "-Djgroups.dns.query=release-name-keycloak-headless.mhajeb.svc.cluster.local"
printf
函数完成的,该函数从模板助手中渲染 common.names.fullname
和 common.names.namespacce
,这些模板助手在“父”图表中定义:
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "common.names.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
和
{{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts.
*/}}
{{- define "common.names.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
默认使用图表、版本名称。如果您想覆盖它们,请查看文档:
https://github.com/bitnami/charts/tree/main/bitnami/keycloak#common-parameters,或模板:),然后设置:
fullnameOverride
完全覆盖 common.names.fullname 的字符串
namespaceOverride
完全覆盖 common.names.namespace 的字符串
helm template my-food-release bitnami/keycloak --namespace mhajeb
结果:
# Source: keycloak/templates/configmap-env-vars.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: my-food-release-keycloak-env-vars
namespace: "mhajeb"
labels:
app.kubernetes.io/name: keycloak
helm.sh/chart: keycloak-13.0.4
app.kubernetes.io/instance: my-food-release
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: keycloak
data:
KEYCLOAK_DATABASE_HOST: "my-food-release-postgresql"
...
JAVA_OPTS_APPEND: "-Djgroups.dns.query=my-food-release-keycloak-headless.mhajeb.svc.cluster.local"
...
helm template my-food-release bitnami/keycloak --namespace mhajeb --set fullnameOverride=daNewName --set namespaceOverride=daNewNamespaceOverride
结果:
# Source: keycloak/templates/configmap-env-vars.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: daNewName-env-vars
namespace: "daNewNamespaceOverride"
labels:
app.kubernetes.io/name: keycloak
helm.sh/chart: keycloak-13.0.4
app.kubernetes.io/instance: my-food-release
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: keycloak
data:
...
JAVA_OPTS_APPEND: "-Djgroups.dns.query=daNewName-headless.daNewNamespaceOverride.svc.cluster.local"
...