En este tutorial, analizaremos brevemente cómo Helm puede ayudar a simplificar la administración de aplicaciones de Kubernetes y aprenderemos a usar Helm para crear un gráfico básico.
La gestión de aplicaciones es un aspecto complejo de Kubernetes. Helm lo hace mucho más fácil al proporcionar un método de empaquetado de software unificado que admite el control de versiones. Helm instala y administra paquetes (llamados Gráficos en Helm) para Kubernetes, al igual que yum y apt.
En este tutorial, dejaremos que Helm cree un gráfico básico para nosotros. Este tutorial asume que tiene al menos un conocimiento básico de lo que es Helm. Si no está familiarizado con él, le sugiero que lea este tutorial antes de comenzar el artículo: https://www.alibabacloud.com/help/doc-detail/86511.htm
Luego, lo ajustaremos de forma incremental para ver cómo funcionan juntos el archivo de valores y las partes de la plantilla.
Con una tabla de trabajo tan básica, es más fácil trabajar con él que empezar desde cero.
Chart es un paquete de Helm. Contiene todas las definiciones de recursos necesarias para ejecutar una aplicación, herramienta o servicio dentro de un clúster de Kubernetes.
Piense en ello como el equivalente de Kubernetes de una fórmula Homebrew, un Apt dpkg o un archivo Yum RPM.
Crear una estructura completa de directorios de organigramas
helm create myhelm1 Creating myhelm1
Esto crea un cuadro de trabajo completo con todos los archivos necesarios en el directorio myhelm.
myhelm1/ | |- .helmignore # Contains patterns for files to ignore when packaging Helm charts. | |- Chart.yaml # Meta Information about your chart | |- values.yaml # The default values for your templates | |- charts/ # Charts that this chart depends on: dependencies | |- templates/ # The template files
Se le presentarán algunos de estos archivos a lo largo de este tutorial, solo cuando necesitemos conocer esos archivos específicos.
El objetivo es utilizar el gráfico lo antes posible para crear una instancia de trabajo. Luego investigamos qué creó el gráfico y cómo lo hizo.
El archivo es lo primero values.yaml
. Contiene nuestros valores predeterminados para los objetos de Kubernetes que queremos crear.
, nginx
. 55 . busybox
— 650 .
values.yaml
nano ./myhelm1/values.yaml # Default values for myhelm1. # This is a YAML-formatted file. # Declare variables to be passed into your templates. replicaCount: 1 image: repository: nginx tag: stable pullPolicy: IfNotPresent
values.yaml
, busybox, . .
nano ./myhelm1/values.yaml # Default values for myhelm1. # This is a YAML-formatted file. # Declare variables to be passed into your templates. replicaCount: 1 image: repository: radial/busyboxplus tag: base pullPolicy: IfNotPresent
deployment.yaml
.
(deployment), , Kubernetes. , .
deployment.yaml
27 — . busybox. , , . busybox
60 .
( , values.yaml
. — .)
nano ./myhelm1/templates/deployment.yaml spec: containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} command: ['sh', '-c', 'sleep 60']
Helm .
helm install ./myhelm1/
.
helm install ./myhelm1/ NAME: loopy-otter LAST DEPLOYED: Thu Feb 14 08:48:42 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE loopy-otter-myhelm1 ClusterIP 10.109.163.87 <none> 80/TCP 0s ==> v1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE loopy-otter-myhelm1 1 0 0 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE loopy-otter-myhelm1-67b67bf4c8-tsdcq 0/1 Pending 0 0s NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myhelm1,app.kubernetes.io/instance=loopy-otter" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:80
Helm : NAME: loopy-otter
. . .
, .
, Helm .yaml
, , values.yaml
.
nginx. busybox
.
NOTES.txt, .
, Pod .
kubectl get pods NAME READY STATUS RESTARTS AGE loopy-otter-myhelm1-67b67bf4c8-tsdcq 0/1 Running 0 13s
. helm delete
, .
helm delete loopy-otter release "loopy-otter" deleted
helmignore NOTES.txt
.helmignore
NOTES.txt
.
.helmignore
, Helm .
nano ./myhelm1/.helmignore NOTES.txt
, , .
helm install .\myhelm1\ --name test1 NAME: test1 LAST DEPLOYED: Thu Feb 14 08:56:10 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE test1-myhelm1 ClusterIP 10.96.102.116 <none> 80/TCP 0s ==> v1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE test1-myhelm1 1 0 0 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE test1-myhelm1-6f77bf4459-9nxpz 0/1 ContainerCreating 0 0s
( , .)
test1.
helm delete test1 release "test1" deleted
--dry-run --debug
--dry-run
--debug
, , Helm YAML .
Kubernetes .
.
helm install .\myhelm1\ --name test1 --dry-run --debug [debug] Created tunnel using local port: '49958' [debug] SERVER: "127.0.0.1:49958" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 Error: a release named test1 already exists. Run: helm ls --all test1; to check the status of the release Or run: helm del --purge test1; to delete it
, .
release
helm ls --all test1 NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE test1 1 Thu Feb 14 08:56:10 2019 DELETED myhelm1-0.1.0 1.0 default
.
(debug
) : test2:
helm install .\myhelm1\ --name test2 --dry-run --debug [debug] Created tunnel using local port: '49970' [debug] SERVER: "127.0.0.1:49970" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test2 REVISION: 1 RELEASED: Thu Feb 14 08:59:22 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: {} COMPUTED VALUES: affinity: {} fullnameOverride: "" image: pullPolicy: IfNotPresent repository: radial/busyboxplus tag: base ingress: annotations: {} enabled: false hosts: - chart-example.local paths: [] tls: [] nameOverride: "" nodeSelector: {} replicaCount: 1 resources: {} service: port: 80 type: ClusterIP tolerations: [] HOOKS: --- # test2-myhelm1-test-connection apiVersion: v1 kind: Pod metadata: name: "test2-myhelm1-test-connection" labels: app.kubernetes.io/name: myhelm1 helm.sh/chart: myhelm1-0.1.0 app.kubernetes.io/instance: test2 app.kubernetes.io/managed-by: Tiller annotations: "helm.sh/hook": test-success spec: containers: - name: wget image: busybox command: ['wget'] args: ['test2-myhelm1:80'] restartPolicy: Never MANIFEST: --- # Source: myhelm1/templates/service.yaml apiVersion: v1 kind: Service metadata: name: test2-myhelm1 labels: app.kubernetes.io/name: myhelm1 helm.sh/chart: myhelm1-0.1.0 app.kubernetes.io/instance: test2 app.kubernetes.io/managed-by: Tiller spec: type: ClusterIP ports: - port: 80 targetPort: http protocol: TCP name: http selector: app.kubernetes.io/name: myhelm1 app.kubernetes.io/instance: test2 --- # Source: myhelm1/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: test2-myhelm1 labels: app.kubernetes.io/name: myhelm1 helm.sh/chart: myhelm1-0.1.0 app.kubernetes.io/instance: test2 app.kubernetes.io/managed-by: Tiller spec: replicas: 1 selector: matchLabels: app.kubernetes.io/name: myhelm1 app.kubernetes.io/instance: test2 template: metadata: labels: app.kubernetes.io/name: myhelm1 app.kubernetes.io/instance: test2 spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: IfNotPresent command: ['sh', '-c', 'sleep 60'] ports: - name: http containerPort: 80 protocol: TCP livenessProbe: httpGet: path: / port: http readinessProbe: httpGet: path: / port: http resources: {}
, , .
, .
. nginx. .
20 # Source: myhelm1/templates/service.yaml ... kind: Service
— — Pod.
, .helmignore .
nano ./myhelm1/.helmignore test-connection.yaml service.yaml
busybox livenessProbes.
29 42 deployment.yaml
nano ./myhelm1/templates/deployment.yaml ports: - name: http containerPort: 80 protocol: TCP livenessProbe: httpGet: path: / port: http readinessProbe: httpGet: path: / port: http resources: {}
, helm install
.
labels: app.kubernetes.io/name: myhelm1 helm.sh/chart: myhelm1-0.1.0 app.kubernetes.io/instance: test4 app.kubernetes.io/managed-by: Tiller selector: matchLabels: app.kubernetes.io/name: myhelm1 app.kubernetes.io/instance: test4 metadata: labels: app.kubernetes.io/name: myhelm1 app.kubernetes.io/instance: test4
.
helm install .\myhelm1\ --name test2 --dry-run --debug [debug] Created tunnel using local port: '49976' [debug] SERVER: "127.0.0.1:49976" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test2 REVISION: 1 RELEASED: Thu Feb 14 09:09:55 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: {} COMPUTED VALUES: affinity: {} fullnameOverride: "" image: pullPolicy: IfNotPresent repository: radial/busyboxplus tag: base ingress: annotations: {} enabled: false hosts: - chart-example.local paths: [] tls: [] nameOverride: "" nodeSelector: {} replicaCount: 1 resources: {} service: port: 80 type: ClusterIP tolerations: [] HOOKS: MANIFEST: --- # Source: myhelm1/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: test2-myhelm1 spec: replicas: 1 template: spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: IfNotPresent command: ['sh', '-c', 'sleep 60']
:
- USER-SUPPLIED VALUES: , . .
- COMPUTED VALUES:
values.yaml
. , . - HOOKS: .
-
deployment.yaml
. ,values.yaml
.
--dry-run --debug
. , , . : Helm , .
, .
helm install .\myhelm1\ --name test2 NAME: test2 LAST DEPLOYED: Thu Feb 14 09:12:01 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE test2-myhelm1 1 0 0 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE test2-myhelm1-5bd9bb65c7-6pr4q 0/1 ContainerCreating 0 0s
— Pod. Pod .
kubectl get pods NAME READY STATUS RESTARTS AGE test2-myhelm1-5bd9bb65c7-6pr4q 1/1 Running 0 10s
helm delete test2 release "test2" deleted
imagePullPolicy = Never
values.yaml
(placeholders) .
. , , --set
.
imagePullPolicy .
, .
values.yaml.
nano ./myhelm1/values.yaml # Default values for myhelm1. # This is a YAML-formatted file. # Declare variables to be passed into your templates. replicaCount: 1 image: repository: radial/busyboxplus tag: base pullPolicy: IfNotPresent
, . ( 22-25)
nano ./myhelm1/templates/deployment.yaml containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }}
.Values.image.pullPolicy
-
values.yaml
-
.image.pullPolicy
image: pullPolicy: IfNotPresent
pullPolicy: IfNotPresent
. (, , .)
, , . (imagePullPolicy: Never
)
Kubernetes:
imagePullPolicy: Never: , . .
, --set
.
helm install .\myhelm1\ --set imagePullPolicy=Never --name test3 --dry-run --debug [debug] Created tunnel using local port: '50101' [debug] SERVER: "127.0.0.1:50101" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test3 REVISION: 1 RELEASED: Thu Feb 14 10:10:37 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: imagePullPolicy: Never COMPUTED VALUES: affinity: {} fullnameOverride: "" image: pullPolicy: IfNotPresent repository: radial/busyboxplus tag: base imagePullPolicy: Never ingress: annotations: {} enabled: false hosts: - chart-example.local paths: [] tls: [] nameOverride: "" nodeSelector: {} replicaCount: 1 resources: {} service: port: 80 type: ClusterIP tolerations: [] HOOKS: MANIFEST: --- # Source: myhelm1/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: test3-myhelm1 spec: replicas: 1 template: spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: IfNotPresent command: ['sh', '-c', 'sleep 60']
USER-SUPPLIED VALUES : imagePullPolicy: Never
COMPUTED VALUES: :
image: pullPolicy: IfNotPresent tag: base imagePullPolicy: Never
--set
.
yaml.
: imagePullPolicy: IfNotPresent
: .
: :
helm install .\myhelm1\ --set image.PullPolicy=Never --name test3 --dry-run --debug [debug] Created tunnel using local port: '50107' [debug] SERVER: "127.0.0.1:50107" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test3 REVISION: 1 RELEASED: Thu Feb 14 10:14:11 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: image: PullPolicy: Never < - - - - - - COMPUTED VALUES: affinity: {} fullnameOverride: "" image: PullPolicy: Never < - - - - - - pullPolicy: IfNotPresent < - - - - - - repository: radial/busyboxplus
, . , -. ( — , ).
, , . values.yaml . .
, .
helm install .\myhelm1\ --set image.pullPolicy=Never --name test3 --dry-run --debug [debug] Created tunnel using local port: '50113' [debug] SERVER: "127.0.0.1:50113" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test3 REVISION: 1 RELEASED: Thu Feb 14 10:15:10 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: image: pullPolicy: Never < - - - - - - - - - - - - - COMPUTED VALUES: affinity: {} fullnameOverride: "" image: pullPolicy: Never repository: radial/busyboxplus tag: base ingress: annotations: {} enabled: false hosts: - chart-example.local paths: [] tls: [] nameOverride: "" nodeSelector: {} replicaCount: 1 resources: {} service: port: 80 type: ClusterIP tolerations: [] HOOKS: MANIFEST: --- # Source: myhelm1/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: test3-myhelm1 spec: replicas: 1 template: spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: Never < - - - - - - - - - - - command: ['sh', '-c', 'sleep 60']
, imagePullPolicy: Never
… .
COMPUTED VALUES , .
COMPUTED VALUES: image: pullPolicy: Never
. .
, . , 5 .
nano ./myhelm1/values.yaml # Default values for myhelm1. # This is a YAML-formatted file. # Declare variables to be passed into your templates. replicaCount: 1 image: repository: radial/busyboxplus tag: base pullPolicy: IfNotPresent #nameOverride: "" #fullnameOverride: "" #service: # type: ClusterIP # port: 80 #ingress: # enabled: false # annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" # paths: [] # hosts: # - chart-example.local # tls: [] # - secretName: chart-example-tls # hosts: # - chart-example.local #resources: {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little # resources, such as Minikube. If you do want to specify resources, uncomment the following # lines, adjust them as necessary, and remove the curly braces after 'resources:'. # limits: # cpu: 100m # memory: 128Mi # requests: # cpu: 100m # memory: 128Mi #nodeSelector: {} #tolerations: [] #affinity: {}
helm install .\myhelm1\ --set image.pullPolicy=Never --name test3 --dry-run --debug [debug] Created tunnel using local port: '50125' [debug] SERVER: "127.0.0.1:50125" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 Error: render error in "myhelm1/templates/ingress.yaml": template: myhelm1/templates/ingress.yaml:1:14: executing "myhelm1/templates/ingress.yaml" at <.Values.ingress.enab...>: can't evaluate field enabled in type interface {}
Values.ingress.enabled
myhelm1/templates/ingress.yaml
ingress — nginx, .
ingress.yaml
.
nano ./myhelm1/.helmignore ingress.yaml
: myhelm1 image.pullPolicy = Never
--set replicaCount=3
helm install .\myhelm1\ --set image.pullPolicy=Never --set replicaCount=3 --name test3 --dry-run --debug [debug] Created tunnel using local port: '50140' [debug] SERVER: "127.0.0.1:50140" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test3 REVISION: 1 RELEASED: Thu Feb 14 10:23:43 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: image: pullPolicy: Never < * * * = = = = = = = = = = = = = replicaCount: 3 < - - - - - - - - - - - - - - - - COMPUTED VALUES: image: pullPolicy: Never < * * * = = = = = = = = = = = = = repository: radial/busyboxplus tag: base replicaCount: 3 < - - - - - - - - - - - - - - - - HOOKS: MANIFEST: --- # Source: myhelm1/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: test3-myhelm1 spec: replicas: 3 < - - - - - - - - - - - - - - - - - - template: spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: Never < * * * = = = = = = = = = = = = = command: ['sh', '-c', 'sleep 60']
--set replicaCount
deployment.yaml
.
helm install .\myhelm1\ --set image.pullPolicy=Never --set replicaCount=3 --name test3 NAME: test3 LAST DEPLOYED: Thu Feb 14 10:34:45 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE test3-myhelm1 3 0 0 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE test3-myhelm1-878d8d7c-7xshs 0/1 Pending 0 0s test3-myhelm1-878d8d7c-fnjqn 0/1 ContainerCreating 0 0s test3-myhelm1-878d8d7c-gjw4m 0/1 Pending 0 0s
. — 3, , 3 .
3 . helm status
.
helm status test3 LAST DEPLOYED: Thu Feb 14 10:34:45 2019 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE test3-myhelm1 3 3 3 3 20s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE test3-myhelm1-878d8d7c-7xshs 1/1 Running 0 20s test3-myhelm1-878d8d7c-fnjqn 1/1 Running 0 20s test3-myhelm1-878d8d7c-gjw4m 1/1 Running 0 20s
. test3.
helm delete test3 release "test3" deleted
value
values.yaml
.
.
: terminationGracePeriodSeconds
terminationGracePeriodSeconds — , . grace period — , , , , , . , . 30 .
terminationGracePeriodSeconds: 30
values.yaml
, 5–12 , :
nano ./myhelm1/values.yaml replicaCount: 1 terminationGracePeriodSeconds: 30 image: repository: radial/busyboxplus tag: base pullPolicy: IfNotPresent
, ( 22 29 , )
nano ./myhelm1/templates/deployment.yaml containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} command: ['sh', '-c', 'sleep 60']
.
helm install .\myhelm1\ --name test4 --dry-run --debug [debug] Created tunnel using local port: '50239' [debug] SERVER: "127.0.0.1:50239" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test4 REVISION: 1 RELEASED: Thu Feb 14 10:54:58 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: name: test4-myhelm1 spec: replicas: 1 template: spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: IfNotPresent terminationGracePeriodSeconds: 30 < - - - - - - command: ['sh', '-c', 'sleep 60']
. COMPUTED VALUES: .
: , terminationGracePeriodSeconds
10.
helm install .\myhelm1\ --set terminationGracePeriodSeconds=10 --name test4 --dry-run --debug [debug] Created tunnel using local port: '50245' [debug] SERVER: "127.0.0.1:50245" [debug] Original chart version: "" [debug] CHART PATH: C:\k8\myhelm1 NAME: test4 REVISION: 1 RELEASED: Thu Feb 14 10:56:33 2019 CHART: myhelm1-0.1.0 USER-SUPPLIED VALUES: terminationGracePeriodSeconds: 10 < - - - - - - COMPUTED VALUES: image: pullPolicy: IfNotPresent repository: radial/busyboxplus tag: base replicaCount: 1 terminationGracePeriodSeconds: 10 < - - - - - - HOOKS: MANIFEST: --- # Source: myhelm1/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: test4-myhelm1 spec: replicas: 1 template: spec: containers: - name: myhelm1 image: "radial/busyboxplus:base" imagePullPolicy: IfNotPresent terminationGracePeriodSeconds: 10 < - - - - - - command: ['sh', '-c', 'sleep 60']
. COMPUTED VALUES: 10
10.
_helpers.tpl
. ( . .)
, .
. (.helmignore
)
En el trabajo, creará sus propios gráficos base esqueléticos de los que copiará.
Aprendimos los conceptos básicos de Helm el primer día, modificando el gráfico nginx
para adaptarlo a nuestros requisitos. --dry-run --debug
- la mejor función de Helm: prueba y depuración antes de la instalación.