Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10分でだいたい分かるHelm ~v2~

C174e1ef0c746f53d989b1902b4e674e?s=47 go_vargo
April 15, 2019

10分でだいたい分かるHelm ~v2~

C174e1ef0c746f53d989b1902b4e674e?s=128

go_vargo

April 15, 2019
Tweet

Transcript

  1. 10෼Ͱ͍͍ͩͨ෼͔ΔHelm ~ Version2 ~ 1

  2. ໨࣍ • ࣗݾ঺հ • Helmίϯηϓτ • Helm༻ޠ • HelmΞʔΩςΫνϟ •

    HelmΠϯετʔϧ • HelmίϚϯυ • Chart • Template • SubChart • Hooks • Lint / Test • Chart Repository 2
  3. ࣗݾ঺հ ໊લ: όϧΰ(@go_vargo) ৬ۀ: SE @SIer ܦྺ: ΞϓϦ3೥, Πϯϑϥ1೥ झຯ:

    Ϋϥ΢υωΠςΟϒ ɹɹ Ϋϥ΢υωΠςΟϒܥͷMeetup΁ͷࢀՃ ٕज़ॻయ6Ͱ൦෍͠·ͨ͠ Helm(v2)͕͍͍ͩͨཧղͰ͖·͢ Booth: https://go-vargo.booth.pm/items/1313526 3
  4. Helmίϯηϓτ Helm https://helm.sh/ GitHub https://github.com/helm/helm 4

  5. Helm༻ޠ 5 ཁૉ ֓ཁ Chart HelmͰ࢖͏ύοέʔδͷςϯϓϨʔτ Helm Client HelmΛૢ࡞͢ΔίϚϯυϥΠϯπʔϧ Tiller

    KubernetesΫϥελ্ͰՔಇ͢Δαʔόʔ Release ChartΛσϓϩΠͨ͠୯Ґ ϦϙδτϦ ChartΛอ؅͍ͯ͠ΔϦϙδτϦαʔό
  6. HelmΞʔΩςΫνϟ 6

  7. HelmΠϯετʔϧ 7 લఏ ɾKubernetesΫϥελ͕Քಇ͍ͯ͠Δ͜ͱ ɾTiller༻ͷServiceAccountʹద੾ͳݖݶΛ༩͓͑ͯ͘ Πϯετʔϧํ๏ ɹTiller͕Namespaceʮkube-systemʯʹ഑ஔ͞ΕΔ ɹϩʔΧϧͷʮ$HELM_HOMEʯ͕ઃఆ͞ΕΔ IFMNJOJUŠTFSWJDFBDDPVOUUJMMFS

  8. HelmίϚϯυ 8 ίϚϯυ ֓ཁ helm create ChartΛ࡞੒͢Δ helm install ChartΛKubernetesΫϥελʹΠϯετʔϧ͢Δ

    helm upgrade ReleaseΛߋ৽͢Δ helm delete ReleaseΛ࡟আ͢Δ helm rollback ReleaseΛࢦఆͨ͠ϦϏδϣϯʹϩʔϧόοΫ͢Δ helm list ReleaseΛҰཡදࣔ͢Δ helm status ReleaseͷεςʔλεΛ֬ೝ͢Δ helm fetch ChartΛϦϙδτϦ͔Βμ΢ϯϩʔυ͢Δ helm template ඳըͨ͠YAMLϑΝΠϧΛදࣔ͢Δ helm dependency Chartͷґଘؔ܎Λ؅ཧ͢Δ ࢀߟ: https://helm.sh/docs/helm/#helm
  9. Chart 9 Helm Hub: https://hub.helm.sh/ GitHub: https://github.com/helm/charts

  10. ChartΠϯετʔϧ 10 IFMNJOTUBMMŠOBNFNZTRMa ŠOBNFTQBDFEBUBCBTFa ŠTFUJNBHF5BHTUBCMFNZTRM ίϚϯυϥΠϯࢦఆ ϑΝΠϧࢦఆ ※ ϑΝΠϧ͸ෳ਺ࢦఆՄೳ IFMNJOTUBMMGWBMVFTZBNMTUBCMFNZTRM

  11. Values.yaml 11 image: "mysql" imageTag: "5.7.14" busybox: image: "busybox" tag:

    "1.29.3" testFramework: image: "dduportal/bats" tag: “0.4.0" persistence: enabled: true # storageClass: "-" accessMode: ReadWriteOnce size: 8Gi annotations: {} stable/mysql: https://github.com/helm/charts/blob/master/stable/mysql/values.yaml
  12. ChartσΟϨΫτϦߏ੒ 12 wordpress/ ᵓᴷ .helmignore ᵓᴷ Chart.yaml ᵓᴷ LICENSE ᵓᴷ

    README.md ᵓᴷ requirements.yaml ᵓᴷ values.yaml ᵓᴷ charts/ ᴹ ᵋᴷ mariadb/ ᵋᴷ templates/ ᵓᴷ NOTES.txt ᵓᴷ _helpers.tpl ᵓᴷ deployment.yaml ᵋᴷ ...... tgzϑΝΠϧʹݻΊΔࡍʹআ֎͢ΔϑΝΠϧͷҰཡ Chartʹؔ͢Δ৘ใ Φϓγϣϯ: ChartͷϥΠηϯε Φϓγϣϯ: Chartͷઆ໌ Φϓγϣϯ: νϟʔτͷґଘؔ܎Ұཡ ChartͰઃఆ͢ΔσϑΥϧτͷઃఆ஋ Chart͕ґଘ͢ΔଞͷChart KubernetesͷϚχϑΣετϑΝΠϧ܈ ιϑτ΢ΣΞͷར༻ํ๏ template಺Ͱ࢖༻͢ΔϔϧύʔϑΝΠϧ
  13. Template 13 apiVersion: extensions/v1beta1 kind: Deployment metadata: name: {{ template

    "mysql.fullname" . }} … containers: - name: {{ template "mysql.fullname" . }} image: "{{ .Values.image }}:{{ .Values.imageTag }}" imagePullPolicy: {{ .Values.imagePullPolicy | quote }} resources: {{ toYaml .Values.resources | indent 10 }} env: {{- if .Values.mysqlAllowEmptyPassword }} - name: MYSQL_ALLOW_EMPTY_PASSWORD value: "true" {{- end }} - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: {{ template "mysql.secretName" . }} key: mysql-root-password {{- if .Values.mysqlAllowEmptyPassword }} optional: true {{- end }} stable/mysql: https://github.com/helm/charts/blob/master/stable/mysql/templates/deployment.yaml
  14. Template × values.yaml 14 apiVersion: extensions/v1beta1 kind: Deployment metadata: name:

    {{ template "mysql.fullname" . }} … containers: - name: {{ template "mysql.fullname" . }} image: "{{ .Values.image }}:{{ .Values.imageTag }}" image: "mysql" imageTag: “5.7.14" … apiVersion: extensions/v1beta1 kind: Deployment metadata: name: mysql … containers: - name: mysql image: “mysql:5.7.14” templates/deployment.yaml values.yaml ੜ੒͞ΕΔYAML
  15. ૊ࠐม਺ 15 ม਺ ֓ཁ Release Releaseʹؔ͢Δϝλ৘ใ Values values.yamlʹهࡌͨ͠Ϣʔβʔఆٛ஋ Chart Chartʹؔ͢Δϝλ৘ใ

    File ChartσΟϨΫτϦͷ௥ՃϑΝΠϧͷ಺༰ Capabilities Kubernetes΍Helmͷϝλ৘ใ Template Template directoryͷҐஔ৘ใ
  16. Flow Control 16 ཁૉ ֓ཁ IF / ELSE IFΛ࢖ͬͨ৚݅෼ذ͕Մೳ WITH

    ม਺ͷείʔϓఆٛΛมߋՄೳ RANGE Ϧετͷݸ਺෼ͷϧʔϓॲཧ͕Մೳ DEFINE ม਺Λఆٛ͢ΔɻTEMPLATEͱ૊Έ߹ΘͤΔ TEMPLATE ม਺ΛಡΈࠐΉɻDEFINEͱ૊Έ߹ΘͤΔ INCLUDE ม਺ΛಡΈࠐΉɻYAMLܗࣜʹ੔͑΍͍͢ ϓϩάϥϜݴޠͷΑ͏ͳॲཧ͕Մೳ
  17. NOTES.txt / _helper.tpl 17 NOTES.txt͸ιϑτ΢ΣΞͷ࢖༻ํ๏Λهࡌ _helper.tpl͸Template಺Ͱ࢖͏άϩʔόϧఆ਺ (Chart΍Releaseͷ໊લͳͲ)Λఆٛ IFMNJOTUBMMŠOBNFNZSFMFBTFNZDIBSU /05&4 (FUUIFBQQMJDBUJPO63-CZSVOOJOHUIFTFDPNNBOET

    FYQPSU10%@/".& LVCFDUMHFUQPETOBNFTQBDFEFGBVMUa MBQQLVCFSOFUFTJPOBNFNZSFMFBTF a BQQLVCFSOFUFTJPJOTUBODFNZSFMFBTFa PKTPOQBUI\JUFNT<>NFUBEBUBOBNF^  FDIP7JTJUIUUQUPVTFZPVSBQQMJDBUJPO LVCFDUMQPSUGPSXBSE10%@/".&
  18. SubChart 18 IFMNEFQFOEFODZVQEBUF<$IBSU> Hang tight while we grab the latest

    from your chart repositories... ...Successfully got an update from the "local" chart repository ...Successfully got an update from the "stable" chart repository ...Successfully got an update from the "example" chart repository ...Successfully got an update from the "another" chart repository Update Complete. Happy Helming! Saving 2 charts Downloading apache from repo http://example.com/charts Downloading mysql from repo http://another.example.com/charts dependencies: - name: apache version: 1.2.3 repository: http://example.com/charts - name: mysql version: 3.2.1 repository: http://another.example.com/charts requirements.yaml ґଘؔ܎Λ࣋ͭ͜ͱͰଞͷ ChartΛར༻Մೳ requirements.yamlΛ༻ҙ͠ɺ ʮhelm dependencyʯͰ؅ཧ
  19. Hooks 19 Hooks pre-install post-install pre-delete post-delete pre-update post-upgrade pre-rollback

    post-rollback crd-install apiVersion: batch/v1 kind: Job metadata: name: "{{.Release.Name}}" labels: app.kubernetes.io/managed-by: {{.Release.Service | quote }} app.kubernetes.io/instance: {{.Release.Name | quote }} helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}" annotations: # This is what defines this resource as a hook. # Without this line, the job is considered part of the release. "helm.sh/hook": post-install "helm.sh/hook-weight": "-5" "helm.sh/hook-delete-policy": hook-succeeded ... ReleaseͷLife Cycleʹհೖ͢Δख๏ ChartΠϯετʔϧલޙʹJobΛ࣮ߦ͢Δ͜ͱ΍ ChartΠϯετʔϧલޙʹConfigMapͷઃఆͳͲ͕Մೳ
  20. Plugins 20 Plugin͸༗ࢤ͕։ൃͨ͠΋ͷΛར༻Մೳ helm diff(https://github.com/databus23/helm-diff)

  21. Lint / Test 21 Lint: ੩తղੳ ߏจνΣοΫ΍ਪ঑ߏ੒͔Ͳ͏͔ΛνΣοΫ͢Δ Test: ςετ templates/tests/഑Լͷςετ༻ϑΝΠϧΛ࣮ߦ͢Δ

    IFMNMJOUNZDIBSU -JOUJOHNZDIBSU <*/'0>$IBSUZBNMJDPOJTSFDPNNFOEFE DIBSU T MJOUFE OPGBJMVSFT IFMNUFTUNZDIBSU 36//*/(NZDIBSUUFTUDPOOFDUJPO 1"44&%NZDIBSUUFTUDPOOFDUJPO
  22. Chart Repository 22 ඞཁ৚݅: HTTP(S)௨৴͕Ͱ͖ΔαʔόʔʹtgzܗࣜͷChartΛ഑ஔ બ୒ࢶ: Ϋϥ΢υετϨʔδɺGitHub/GitLabɺʮChartMuseumʯͳͲ IFMNSFQPBEE</".&><3&104*503:63-> [NAME] has

    been added to your repositories HelmͰΠϯετʔϧՄೳ GitHub Pages(https://pages.github.com/) ChartMuseum(https://chartmuseum.com/) helm repoͰϦϙδτϦͷ௥Ճ/࡟আ/ߋ৽/Ұཡද͕ࣔՄೳ
  23. ·ͱΊ 23 ɾHelm͸KubernetesͷύοέʔδϚωʔδϟʔ ɾChart͕͋Δ΋ͷͳΒ͙͢ʹΠϯετʔϧ͕ࢼͤΔ ɾςϯϓϨʔτΤϯδϯͱͯ͠࢖͏ͷ΋༗Γ ɾChart͸ΧελϚΠζ΍ࣗ࡞΋Մೳ (΍Γํ͸ʮࣗ࡞ΞϓϦΛHelmԽͯ͠؆୯σϓϩΠʯΛࢀর͍ͩ͘͞ʂ) ɾ·ͱΊͯΞϓϦͱϛυϧ΢ΣΞΛ࡟আͰ͖ΔͷͰ؅ཧָ͕ʹͳΔ ɾKubernetes͸એݴతʹ࢖͏΋ͷ͕ͩɺHelm͸ͲͪΒ͔ͱ͍͏ͱखଓܕ ɹˠ

    ݸਓతʹ͸Ұ௕Ұ୹ͩͱࢥ͍ͬͯ·͢ ɾHelm v3͕ग़Δͱ݁ߏมԽ͕͋Δ(ΞʔΩςΫνϟ΍ίϚϯυͳͲ) Happy Helming ૉఢͳΫϥ΢υωΠςΟϒϥΠϑΛ