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

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

go_vargo
April 15, 2019

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

go_vargo

April 15, 2019
Tweet

More Decks by go_vargo

Other Decks in Technology

Transcript

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

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

    Ϋϥ΢υωΠςΟϒ ɹɹ Ϋϥ΢υωΠςΟϒܥͷMeetup΁ͷࢀՃ ٕज़ॻయ6Ͱ൦෍͠·ͨ͠ Helm(v2)͕͍͍ͩͨཧղͰ͖·͢ Booth: https://go-vargo.booth.pm/items/1313526 3
  3. Helm༻ޠ 5 ཁૉ ֓ཁ Chart HelmͰ࢖͏ύοέʔδͷςϯϓϨʔτ Helm Client HelmΛૢ࡞͢ΔίϚϯυϥΠϯπʔϧ Tiller

    KubernetesΫϥελ্ͰՔಇ͢Δαʔόʔ Release ChartΛσϓϩΠͨ͠୯Ґ ϦϙδτϦ ChartΛอ؅͍ͯ͠ΔϦϙδτϦαʔό
  4. 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
  5. 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
  6. 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಺Ͱ࢖༻͢ΔϔϧύʔϑΝΠϧ
  7. 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
  8. 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
  9. ૊ࠐม਺ 15 ม਺ ֓ཁ Release Releaseʹؔ͢Δϝλ৘ใ Values values.yamlʹهࡌͨ͠Ϣʔβʔఆٛ஋ Chart Chartʹؔ͢Δϝλ৘ใ

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

    ม਺ͷείʔϓఆٛΛมߋՄೳ RANGE Ϧετͷݸ਺෼ͷϧʔϓॲཧ͕Մೳ DEFINE ม਺Λఆٛ͢ΔɻTEMPLATEͱ૊Έ߹ΘͤΔ TEMPLATE ม਺ΛಡΈࠐΉɻDEFINEͱ૊Έ߹ΘͤΔ INCLUDE ม਺ΛಡΈࠐΉɻYAMLܗࣜʹ੔͑΍͍͢ ϓϩάϥϜݴޠͷΑ͏ͳॲཧ͕Մೳ
  11. 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%@/".&
  12. 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ʯͰ؅ཧ
  13. 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ͷઃఆͳͲ͕Մೳ
  14. Lint / Test 21 Lint: ੩తղੳ ߏจνΣοΫ΍ਪ঑ߏ੒͔Ͳ͏͔ΛνΣοΫ͢Δ Test: ςετ templates/tests/഑Լͷςετ༻ϑΝΠϧΛ࣮ߦ͢Δ

    IFMNMJOUNZDIBSU -JOUJOHNZDIBSU <*/'0>$IBSUZBNMJDPOJTSFDPNNFOEFE DIBSU T MJOUFE OPGBJMVSFT IFMNUFTUNZDIBSU 36//*/(NZDIBSUUFTUDPOOFDUJPO 1"44&%NZDIBSUUFTUDPOOFDUJPO
  15. 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ͰϦϙδτϦͷ௥Ճ/࡟আ/ߋ৽/Ұཡද͕ࣔՄೳ