Die Grundlagen der Arbeit mit Helmdiagrammen und -vorlagen - Teil 2

In diesem Tutorial werden wir kurz erläutern, wie Helm die Verwaltung von Kubernetes-Anwendungen vereinfachen kann, und lernen, wie Sie mit Helm ein grundlegendes Diagramm erstellen.







In diesem Tutorial wird erläutert, wie die Helmvorlage deployment.yaml



von der Vorlage in das YAML-Manifest konvertiert wird.







Der Artikel entspricht nicht dem herkömmlichen Programmierreferenzhandbuch: Bediener und Funktionen sind in alphabetischer Reihenfolge aufgeführt.







Der Artikel erläutert die Syntax der Vorlage nach Bedarf, um sie deployment.yaml



von Anfang bis Ende zu erläutern .







Werte in Vorlagen verwenden



Hier ist die vollständige Datei deploy.yaml als Referenz:







apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "myhelm1.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "myhelm1.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "myhelm1.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}

          terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}

          command: ['sh', '-c', 'sleep 60']

      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      
      





Auszug daraus deployment.yaml



:







    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  replicas: {{ .Values.replicaCount }}
      app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
      
      





.Release.Name



und .Release.Service



sind in Objekte eingebettet - vollständige Liste unter https://docs.helm.sh/chart_template_guide/ Eingebettete Objekte. Leider gibt es keine Links zu bestimmten Teilen ihrer SEHR langen Webseiten - Sie müssen nach unten scrollen und suchen.







Im Folgenden wird angezeigt, wie die endgültige Datei angezeigt wird, deployment.yaml



wenn Sie Folgendes verwenden:







helm install .\myhelm1\ --name test5 --dry-run --debug
      
      





In der ersten Hälfte dieses Tutorials müssen Sie keine Befehle ausführen, sondern nur lesen. (Selbst beim Debuggen wird zu viel ausgegeben, wenn wir nur die Syntax des dreizeiligen Musters überprüfen müssen.)







(Nachdem Sie das vollständige Tutorial gelesen haben, möchten Sie es möglicherweise erneut lesen. Bearbeiten Sie diesmal jedoch die Vorlagen- und Wertedateien und führen Sie die Helminstallation mit Debug aus, um sie zu reproduzieren / zu trainieren.)







    app.kubernetes.io/instance: test5
    app.kubernetes.io/managed-by: Tiller
      app.kubernetes.io/instance: test5
        - name: myhelm1
          image: "radial/busyboxplus:base"
          imagePullPolicy: IfNotPresent
      
      





3 values.yaml:







          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
      
      





values.yaml









image:
  repository: radial/busyboxplus
  tag: base
  pullPolicy: IfNotPresent
      
      





— name: {{ .Chart.Name }} Chart.yaml. .







apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: myhelm1
version: 0.1.0
      
      





, — .







, YAML , {{ and }}



.







{{ }}



.







, , , (.)



.







, . .Chart.name



« , Chart



, name



».







With



**values.yaml** extract: 

nodeSelector:
    disktype: ssd
    gpu: Nvidia
      
      





**deployment.yaml** extract: 

      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      
      





:







      nodeSelector:
        disktype: ssd
        gpu: Nvidia
      
      





: YAML.







8 , deployment.yaml



{{- toYaml. | nindent 8}}









nindent 8



8 .







with



— . .Values.nodeSelector



: Yaml (toYaml



).

toYaml



.Values.nodeSelector



. .

sum(1,34,454)



toYaml(.)



… .







| , Linux.







affinity



: tolerations



: with



.







, , with . MODIFYING SCOPE USING WITH







include



, , deployment.yaml



values.yaml



, Chart.yaml



.







service.yaml



:







.







apiVersion: v1
kind: Service
metadata:
  name: {{ include "myhelm1.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
      
      





range () Helm



3 ingress.yaml









{{- if .Values.ingress.enabled -}}
{{- $fullName := include "myhelm1.fullname" . -}}
{{- $ingressPaths := .Values.ingress.paths -}}
... rest of yaml ....
    {{- end }}
  {{- end }}
{{- end }}
      
      





**values.yaml** extract: 
ingress:
  enabled: false
      
      





ingress.yaml



if



..., 1 . — false, yaml — .







2 3 , Helm.







{{ }}









/ . {{-









-}}



, — — .







values.yaml









ingress:
  enabled: false
  hosts:
    - chart-example.local
  tls:
    - secretName: chart-example-tls
      hosts:
        - chart-example.local-1
        - chart-example.local-2
        - chart-example.local-3
      
      





deployment.yaml :







{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
      
      





:







spec:
  tls:
    - hosts:
        - "chart-example.local-1"
        - "chart-example.local-2"
        - "chart-example.local-3"
      secretName: chart-example-tls
      
      





, (range



) . quote



.







range .Values.ingress.tls



, . 3 , .







Extract of **values.yaml** 

ingress:
  enabled: false
  hosts:
    - chart-example.local
  tls:
    - secretName: chart-example-tls-a
      hosts:
        - chart-example.local-1-a
        - chart-example.local-2-a
        - chart-example.local-3-a

    - secretName: chart-example-tls-b
      hosts:
        - chart-example.local-1-b
        - chart-example.local-2-b

    - secretName: chart-example-tls-c
      hosts:
        - chart-example.local-1-c
        - chart-example.local-2-c
        - chart-example.local-3-c
        - chart-example.local-4-c
      
      





:







  tls:
    - hosts:
        - "chart-example.local-1-a"
        - "chart-example.local-2-a"
        - "chart-example.local-3-a"
      secretName: chart-example-tls-a
    - hosts:
        - "chart-example.local-1-b"
        - "chart-example.local-2-b"
      secretName: chart-example-tls-b
    - hosts:
        - "chart-example.local-1-c"
        - "chart-example.local-2-c"
        - "chart-example.local-3-c"
        - "chart-example.local-4-c"
      secretName: chart-example-tls-c
      
      





importance of -



.







{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
      
      





:







{{ if .Values.ingress.tls }}
  tls:
  {{ range .Values.ingress.tls }}
    - hosts:
      {{ range .hosts }}
        - {{ . | quote }}
      {{ end }}
      secretName: {{ .secretName }}
  {{ end }}
{{ end }}
      
      





:







  tls:
    - hosts:

        - "chart-example.local-1-a"

        - "chart-example.local-2-a"

        - "chart-example.local-3-a"

      secretName: chart-example-tls-a

    - hosts:

        - "chart-example.local-1-b"

        - "chart-example.local-2-b"

      secretName: chart-example-tls-b

    - hosts:

        - "chart-example.local-1-c"

        - "chart-example.local-2-c"

        - "chart-example.local-3-c"

        - "chart-example.local-4-c"

      secretName: chart-example-tls-c

      
      





.







_helpers.tpl



, .







: name: {{include "myhelm1.fullname". }}



— .







include









include YAML-.







_helpers.tpl



— , .







_helpers.tpl:









{{- define "myhelm1.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
      
      





. , .







myhelm1.name : .Chart.Name.







, myhelm1.name .Values.nameOverride



.







trunc 63



63 .







trimSuffix "-"



-



.







trimSuffix "-



" -



.







( , , )







app.kubernetes.io/name: {{ include "myhelm1.name" . }}















app.kubernetes.io/name: myhelm1









:







helm.sh/chart: {{ include "myhelm1.chart" . }}















helm.sh/chart: myhelm1-0.1.0









:







{{- define "myhelm1.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
      
      





printf "%s-%s" .Chart.Name .Chart.Version



.Chart.Name



.Chart.Version



— .







replace "+" "_"



.







, , 10- myhelm1.fullname



.







, , if / else :







if condition
 do something
else
 do something else
end
      
      





{{ }}



.







Helm



Helm .







The Chart Developer's Guide: https://helm.sh/docs/topics/charts/







The Chart Template Developer's Guide: https://docs.helm.sh/chart_template_guide/







– . — .







, Helm .







:











• .







— , , — .







values.yaml



, , :







replicaCount: 1

terminationGracePeriodSeconds: 30

image:
  repository: radial/busyboxplus
  tag: base
  pullPolicy: IfNotPresent
      
      





, ./myhelm1/.helmignore



, :







NOTES.txt
test-connection.yaml
service.yaml
ingress.yaml
      
      





deployment.yaml, :







apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}

          terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
      
      





, , yaml ( ), .







:







helm install .\myhelm1\  --name test5 --dry-run --debug
      
      





, :







PS C:\k8> helm install .\myhelm1\  --name test5 --dry-run --debug
[debug] Created tunnel using local port: '50327'

[debug] SERVER: "127.0.0.1:50327"

[debug] Original chart version: ""
[debug] CHART PATH: C:\k8\myhelm1

NAME:   test5
REVISION: 1
RELEASED: Fri Feb 15 13:47:49 2019
CHART: myhelm1-0.1.0
USER-SUPPLIED VALUES:
{}

COMPUTED VALUES:
image:
  pullPolicy: IfNotPresent
  repository: radial/busyboxplus
  tag: base
replicaCount: 1
terminationGracePeriodSeconds: 30

HOOKS:
MANIFEST:

---
# Source: myhelm1/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: myhelm1
    helm.sh/chart: myhelm1-0.1.0
    app.kubernetes.io/instance: test5
spec:
  replicas: 1
  template:
    spec:
      containers:
        - name: myhelm1
          image: "radial/busyboxplus:base"
          imagePullPolicy: IfNotPresent

          terminationGracePeriodSeconds: 30
      
      





«» grep.







helm install .\myhelm1\  --name test5 --dry-run --debug | grep -vE 'debug]|NAME|REVIS|RELEA|ART:|OKS:|FEST:'
      
      





. , : yaml .







USER-SUPPLIED VALUES:
{}

COMPUTED VALUES:
image:
  pullPolicy: IfNotPresent
  repository: radial/busyboxplus
  tag: base
replicaCount: 1
terminationGracePeriodSeconds: 30

---
# Source: myhelm1/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: myhelm1
    helm.sh/chart: myhelm1-0.1.0
    app.kubernetes.io/instance: test5
spec:
  replicas: 1
  template:
    spec:
      containers:
        - name: myhelm1
          image: "radial/busyboxplus:base"
          imagePullPolicy: IfNotPresent

          terminationGracePeriodSeconds: 30
      
      





:

deployment.yaml









apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
spec: #-------------------->> learn spacing << ------------------------
  replicas1: {{ .Values.replicaCount }}
  replicas2:   {{ .Values.replicaCount }}
  replicas3:    {{ .Values.replicaCount }}
  replicas4: '{{ .Values.replicaCount }}'
  replicas5: "{{ .Values.replicaCount }}"
  replicas6: "{{    .Values.replicaCount }}"
  replicas7: "{{    .Values.replicaCount       }}"
  replicas: "{{    .Values.replicaCount       }}'
  replicas: '{{    .Values.replicaCount       }}"
  replicas: {{    .Values.replicaCount       }}"
  replicas: "{{    .Values.replicaCount       }}

  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image1: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          image2: "{{ .Values.image.repository }} {{ .Values.image.tag }}"
          image3: "{{ .Values.image.repository }}{{ .Values.image.tag }}"
          image4: {{ .Values.image.repository }}{{ .Values.image.tag }}

          imagePullPolicy1: {{ .Values.image.pullPolicy }}
          imagePullPolicy2: {{ .Values.image.pullPolicyzzz }}
          imagePullPolicy3: {{ .Values.image.pullPolicyeeeeeeeeeee }}

          terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
      
      





:







spec: #-------------------->> learn spacing << ------------------------
  replicas1: 1
  replicas2:   1
  replicas3:    1
  replicas4: '1'
  replicas5: "1"
  replicas6: "1"
  replicas7: "1"
  template:
    spec:
      containers:
        - name: myhelm1
          image1: "radial/busyboxplus:base"
          image2: "radial/busyboxplus base"
          image3: "radial/busyboxplusbase"
          image4: radial/busyboxplusbase

          imagePullPolicy1: IfNotPresent
          imagePullPolicy2:
          imagePullPolicy3:

          terminationGracePeriodSeconds: 30
      
      





, .







, , . , , .







deployment.yaml









apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
spec: #
  replicas1: {{ .Values.replicaCount }}

  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image1: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

          imagePullPolicy-correct: {{ .Values.image.pullPolicy }}

          imagePullPolicy1: {{ Values.image.pullPolicy }}
          imagePullPolicy2: {{ .Valu.image.pullPolicyzzz }}
          imagePullPolicy3: {{ ..Values.image.pullPolicyeeeeeeeeeee }}
      
      





:







helm install .\myhelm1\  --name test5 --dry-run --debug | grep -vE 'debug]|NAME|REVIS|RELEA|ART:|OKS:|FEST:'
      
      





Error: parse error in "myhelm1/templates/deployment.yaml": template: myhelm1/templates/deployment.yaml:19: function "Values" not defined
      
      





, , .







Error: parse error in "myhelm1/templates/deployment.yaml": template: myhelm1/templates/deployment.yaml:21: unexpected . after term "."
      
      





, , .







Error: render error in "myhelm1/templates/deployment.yaml": template: myhelm1/templates/deployment.yaml:20:36: executing "myhelm1/templates/deployment.yaml" at 
<.Valu.image.pullPoli...>: can't evaluate field image in type interface {}
      
      





helm install .\myhelm1\  --name test5 --dry-run --debug | grep -vE 'debug]|NAME|REVIS|RELEA|ART:|OKS:|FEST:'
      
      





:







apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
spec: #
  replicas1: {{ .Values.replicaCount }}

  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image1: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

          imagePullPolicy1: {{ quote .Values.image.pullPolicy }}

          imagePullPolicy2: {{ .Values.image.pullPolicy | quote }}

          imagePullPolicy3: "{{ .Values.image.pullPolicy }}"

          imagePullPolicy4: {{ .Values.image.pullPolicy | upper }}

          imagePullPolicy5: {{ .Values.image.pullPolicy | lower }}

{{ $variable := 123 }}

          variable: $variable           
          variable: {{ $variable }}
      
      





. 3 — use those -, . 3 .







Helm , Python, .







:







      containers:
        - name: myhelm1
          image1: "radial/busyboxplus:base"

          imagePullPolicy1: "IfNotPresent"

          imagePullPolicy2: "IfNotPresent"

          imagePullPolicy3: "IfNotPresent"

          imagePullPolicy4: IFNOTPRESENT

          imagePullPolicy5: ifnotpresent

          variable: $variable
          variable: 123     
      
      





. , imagePullPolicy 1 3 . ? :







deployment.yaml









apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: {{ include "myhelm1.name" . }}
    helm.sh/chart: {{ include "myhelm1.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
spec: #
  replicas1: {{ .Values.replicaCount }}

  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image1: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

#          imagePullPolicy1: {{ quote .Values.image.pullPolicy }}
          imagePullPolicy1: {{ quote .Values.image.pullPolicy }}

#          imagePullPolicy2: {{ .Values.image.pullPolicy | quote }}
          imagePullPolicy2: {{ .Values.image.pullPolicy | quote }}

          imagePullPolicy3: " .Values.image.pullPolicy "
          imagePullPolicy3: "{{ .Values.image.pullPolicy }}"

          imagePullPolicy4:  .Values.image.pullPolicy | upper 
          imagePullPolicy4: {{ .Values.image.pullPolicy | upper }}

          imagePullPolicy5:  .Values.image.pullPolicy | lower 
          imagePullPolicy5: {{ .Values.image.pullPolicy | lower }}

{{ $variable := 123 }}

          variable: $variable           
          variable: {{ $variable }}
      
      





helm install .\myhelm1\  --name test5 --dry-run --debug | grep -vE 'debug]|NAME|REVIS|RELEA|ART:|OKS:|FEST:'
      
      





:







        - name: myhelm1
          image1: "radial/busyboxplus:base"

#          imagePullPolicy1: "IfNotPresent"
          imagePullPolicy1: "IfNotPresent"

#          imagePullPolicy2: "IfNotPresent"
          imagePullPolicy2: "IfNotPresent"

          imagePullPolicy3: " .Values.image.pullPolicy "
          imagePullPolicy3: "IfNotPresent"

          imagePullPolicy4:  .Values.image.pullPolicy | upper
          imagePullPolicy4: IFNOTPRESENT

          imagePullPolicy5:  .Values.image.pullPolicy | lower
          imagePullPolicy5: ifnotpresent
      
      





. .







{{ and }}



. .







, , — { { and { }



{{ and }}



… 1 .







{ and }



{{ and }}









          imagePullPolicy1: { { quote .Values.image.pullPolicy } }
          imagePullPolicy1: {{ quote .Values.image.pullPolicy }}

          imagePullPolicy2: { .Values.image.pullPolicy | quote }
          imagePullPolicy2: {{ .Values.image.pullPolicy | quote }}
      
      





:







          imagePullPolicy1: { { quote .Values.image.pullPolicy } }
          imagePullPolicy1: "IfNotPresent"

          imagePullPolicy2: { .Values.image.pullPolicy | quote }
          imagePullPolicy2: "IfNotPresent"
      
      





helm install .\myhelm1\ --set replicaCount={1,2,3}  --name test5 --dry-run --debug | grep -vE 'debug]|NAME|REVIS|RELEA|ART:|OKS:|FEST:'
      
      







Helm https://github.com/helm/charts 300 Helm.







: .







, 80% . ( 2 10 ).







4 :







• Helm

• 2

• 300 Helm

• , 3







Helm .







, Helm.







https://github.com/helm/charts/blob/master/stable/lamp/templates/NOTES.txt







, LAMP .Values.ingress.enabled









{{- if .Values.ingress.enabled }}

INGRESS:
      Please make sure that you have an ingress controller instance {{ if .Values.ingress.ssl }}and a lego instance
      {{- end -}} running
      and that you have configured the A Records of {{ template "lamp.domain" . }} and its
      subdomains to point to your ingress controllers ip address.
{{- else }}
      
      





, : .







NOTES.txt , : https://github.com/helm/charts/blob/master/stable/lamp/templates/NOTES.txt







1. You can now connect to the following services:

      {{- if not .Values.ingress.enabled }}
      export CHARTIP=$(kubectl get svc {{ template "lamp.fullname" . }} --output=jsonpath={.status.loadBalancer.ingress..ip})
      {{- end }}

      Main Site:
        {{- if .Values.ingress.enabled }}
        http{{ if .Values.ingress.ssl }}s{{ end }}://{{ template "lamp.domain" . }}
        {{- else }}
        http://$CHARTIP
        {{- end }}
      {{- if .Values.phpmyadmin.enabled }}

      PHPMyAdmin:
      {{- if .Values.ingress.enabled }}
        http{{ if .Values.ingress.ssl }}s{{ end }}://{{ .Values.phpmyadmin.subdomain }}.{{ template "lamp.domain" . }}
      {{- else }}
        http://$CHARTIP:{{ .Values.phpmyadmin.port }}
      {{- end }}
      {{- end }}
      
      





— , : https://github.com/helm/charts/blob/master/stable/mongodb/templates/NOTES.txt







{{- if contains .Values.service.type "LoadBalancer" }}
{{- if not .Values.mongodbRootPassword }}
-------------------------------------------------------------------------------
 WARNING

    By specifying "service.type=LoadBalancer" and not specifying "mongodbRootPassword"
    you have most  likely exposed the MongoDB service externally without any
    authentication mechanism.

    For security reasons, we strongly suggest that you switch to "ClusterIP" or
    "NodePort". As alternative, you can also specify a valid password on the
    "mongodbRootPassword" parameter.

-------------------------------------------------------------------------------
{{- end }}
{{- end }}
      
      





, .Values.service.type



"NodePort



", "LoadBalancer



" "ClusterIP": https://github.com/helm/charts/blob/master/stable/mongodb/templates/NOTES.txt







To connect to your database from outside the cluster execute the following commands:

{{- if contains "NodePort" .Values.service.type }}

    export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
    export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "mongodb.fullname" . }})
    mongo --host $NODE_IP --port $NODE_PORT {{- if .Values.usePassword }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }}

{{- else if contains "LoadBalancer" .Values.service.type }}

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ template "mongodb.fullname" . }}'

    export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "mongodb.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
    mongo --host $SERVICE_IP --port {{ .Values.service.nodePort }} {{- if .Values.usePassword }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }}

{{- else if contains "ClusterIP" .Values.service.type }}

    kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "mongodb.fullname" . }} 27017:27017 &
    mongo --host 127.0.0.1 {{- if .Values.usePassword }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }}

{{- end }}
      
      





3 . ( … ).







.Files.Get



https://docs.helm.sh/chart_template_guide/… … ( ) , .







Es gibt 80 Anwendungsfälle in den Helm - Repository .Files.Get.





https://github.com/helm/charts/search?utf8=%E2%9C%93&q=.Files.Get&type =

fand ich 5 verschiedene Anwendungsfälle .Files.Get.





zu lernen Weitere Informationen zu Helm finden Sie unter https://github.com/helm/charts/tree/master/stable .








All Articles