ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Helm
    Helm 2022. 10. 23. 18:08
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ’ก Helm์ด๋ž€?

    • helm์€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €์ด๋‹ค. apt, yum, pip ํˆด๊ณผ ๋น„์Šทํ•˜๊ฒŒ ํ”Œ๋žซํผ์˜ ํŒจํ‚ค์ง€๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค.
    • helm์„ ์ด์šฉํ•˜์—ฌ ์›ํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด(ํŒจํ‚ค์ง€)๋ฅผ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์— ์†์‰ฝ๊ฒŒ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • helm ํŒจํ‚ค์ง€ ๋˜ํ•œ YAML ํ˜•์‹์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์œผ๋ฉฐ, ์ด๊ฒƒ์„ Chart๋ผ๊ณ  ํ•œ๋‹ค.
    • Chart ๋””๋ ‰ํ† ๋ฆฌ ์•ˆ์—๋Š” Deployment, Service ๋“ฑ๊ณผ ๊ฐ™์€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฆฌ์†Œ์Šค๊ฐ€ YAML ํŒŒ์ผ ํ˜•ํƒœ๋กœ ๋“ค์–ด๊ฐ€ ์žˆ๋‹ค. ๊ฐ ํŒŒ์ผ๋“ค์˜ ์„ค์ •๊ฐ’์€ ๋น„์›Œ์ ธ ์žˆ๊ณ (placeholder) values.yaml์˜ ์„ค์ •๊ฐ’๋“ค๋กœ ์ฑ„์›Œ์ง„๋‹ค. ํŒจํ‚ค์ง€๊ฐ€ ์„ค์น˜๋  ์‹œ์ ์— values.yaml ํŒŒ์ผ์˜ ์„ค์ •๊ฐ’๋“ค์„ ์ด์šฉํ•˜์—ฌ templates ๋””๋ ‰ํ† ๋ฆฌ์— ๋“ค์–ด์žˆ๋Š” YAML ํŒŒ์ผ์˜ ๊ตฌ๋ฉ๋‚œ ๋ถ€๋ถ„์„ ์ฑ„์šด๋‹ค. values.yaml ํŒŒ์ผ์—๋Š” ์ž์ฃผ ๋ฐ”๋€Œ๊ฑฐ๋‚˜ ์‚ฌ์šฉ์ž๋งˆ๋‹ค ๋‹ฌ๋ผ์ง€๋Š” ์„ค์ •๊ฐ’๋“ค์„ ์ž…๋ ฅํ•˜๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉํ•˜๊ณ  templates ๋””๋ ‰ํ† ๋ฆฌ๋Š” ํŒจํ‚ค์ง€์˜ ๋ผˆ๋Œ€๋ฅผ ์ด๋ฃฌ๋‹ค.

     

    ๐Ÿ“Œ ์ฐจํŠธ ๊ตฌ์กฐ

    ChartStructure/
      Chart.yaml          # ์ฐจํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง„ YAML ํŒŒ์ผ
      LICENSE             # ์˜ต์…˜: ์ฐจํŠธ์˜ ๋ผ์ด์„ผ์Šค ์ •๋ณด๋ฅผ ๊ฐ€์ง„ ํ…์ŠคํŠธ ํŒŒ์ผ
      README.md           # ์˜ต์…˜: README ํŒŒ์ผ
      values.yaml         # ์ฐจํŠธ์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ํ™˜๊ฒฝ์„ค์ • ๊ฐ’๋“ค
      values.schema.json  # ์˜ต์…˜: values.yaml ํŒŒ์ผ์˜ ๊ตฌ์กฐ๋ฅผ ์ œ์•ฝํ•˜๋Š” JSON ํŒŒ์ผ
      charts/             # ์ด ์ฐจํŠธ์— ์ข…์†๋œ ์ฐจํŠธ๋“ค์„ ํฌํ•จํ•˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ
      crds/               # ์ปค์Šคํ…€ ์ž์›์— ๋Œ€ํ•œ ์ •์˜
      templates/          # values์™€ ๊ฒฐํ•ฉ๋  ๋•Œ, ์œ ํšจํ•œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค manifest ํŒŒ์ผ๋“ค์ด ์ƒ์„ฑ๋  ํ…œํ”Œ๋ฆฟ๋“ค์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ
      templates/NOTES.txt # ์˜ต์…˜: ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ๋ฒ•์„ ํฌํ•จํ•˜๋Š” ํ…์ŠคํŠธ ํŒŒ์ผ

     

    ๐ŸŽˆ Chart.yaml Fields

    apiVersion: ์ฐจํŠธ API ๋ฒ„์ „ (ํ•„์ˆ˜)
    name: ์ฐจํŠธ๋ช… (ํ•„์ˆ˜)
    version: SemVer 2 ๋ฒ„์ „ (ํ•„์ˆ˜)
    kubeVersion: ํ˜ธํ™˜๋˜๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฒ„์ „์˜ SemVer ๋ฒ”์œ„ (์„ ํƒ)
    description: ์ด ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ ๊ฐ„๋žตํ•œ ์„ค๋ช… (์„ ํƒ)
    type: ์ฐจํŠธ ํƒ€์ž… (์„ ํƒ)
    keywords:
      - ์ด ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ ํ‚ค์›Œ๋“œ ๋ฆฌ์ŠคํŠธ (์„ ํƒ)
    home: ํ”„๋กœ์ ํŠธ ํ™ˆํŽ˜์ด์ง€์˜ URL (์„ ํƒ)
    sources:
      - ์ด ํ”„๋กœ์ ํŠธ์˜ ์†Œ์Šค์ฝ”๋“œ URL ๋ฆฌ์ŠคํŠธ (์„ ํƒ)
    dependencies: # ์ฐจํŠธ ํ•„์š”์กฐ๊ฑด๋“ค์˜ ๋ฆฌ์ŠคํŠธ (optional)
      - name: ์ฐจํŠธ๋ช… (nginx)
        version: ์ฐจํŠธ์˜ ๋ฒ„์ „ ("1.2.3")
        repository: ์ €์žฅ์†Œ URL ("https://example.com/charts") ๋˜๋Š” ("@repo-name")
        condition: (์„ ํƒ) ์ฐจํŠธ๋“ค์˜ ํ™œ์„ฑ/๋น„ํ™œ์„ฑ์„ ๊ฒฐ์ •ํ•˜๋Š” boolean ๊ฐ’์„ ๋งŒ๋“œ๋Š” yaml ๊ฒฝ๋กœ (์˜ˆ์‹œ: subchart1.enabled)
        tags: # (์„ ํƒ)
          - ํ™œ์„ฑํ™” / ๋น„ํ™œ์„ฑ์„ ํ•จ๊ป˜ํ•˜๊ธฐ ์œ„ํ•ด ์ฐจํŠธ๋“ค์„ ๊ทธ๋ฃนํ™” ํ•  ์ˆ˜ ์žˆ๋Š” ํƒœ๊ทธ๋“ค
        enabled: (์„ ํƒ) ์ฐจํŠธ๊ฐ€ ๋กœ๋“œ๋ ์ˆ˜ ์žˆ๋Š”์ง€ ๊ฒฐ์ •ํ•˜๋Š” boolean
        import-values: # (์„ ํƒ)
          - ImportValues ๋Š” ๊ฐ€์ ธ์˜ฌ ์ƒ์œ„ ํ‚ค์— ๋Œ€ํ•œ ์†Œ์Šค ๊ฐ’์˜ ๋งตํ•‘์„ ๋ณด์œ ํ•œ๋‹ค. ๊ฐ ํ•ญ๋ชฉ์€ ๋ฌธ์ž์—ด์ด๊ฑฐ๋‚˜ ํ•˜์œ„ / ์ƒ์œ„ ํ•˜์œ„ ๋ชฉ๋ก ํ•ญ๋ชฉ ์Œ์ผ ์ˆ˜ ์žˆ๋‹ค.
        alias: (์„ ํƒ) ์ฐจํŠธ์— ๋Œ€ํ•œ ๋ณ„๋ช…์œผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค. ๊ฐ™์€ ์ฐจํŠธ๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ์ถ”๊ฐ€ํ•ด์•ผํ• ๋•Œ ์œ ์šฉํ•˜๋‹ค.
    maintainers: # (์„ ํƒ)
      - name: maintainer๋“ค์˜ ์ด๋ฆ„ (๊ฐ maintainer๋งˆ๋‹ค ํ•„์ˆ˜)
        email: maintainer๋“ค์˜ email (๊ฐ maintainer๋งˆ๋‹ค ์„ ํƒ)
        url: maintainer์— ๋Œ€ํ•œ URL (๊ฐ maintainer๋งˆ๋‹ค ์„ ํƒ)
    icon: ์•„์ด์ฝ˜์œผ๋กœ ์‚ฌ์šฉ๋  SVG๋‚˜ PNG ์ด๋ฏธ์ง€ URL (์„ ํƒ)
    appVersion: ์ด ์•ฑ์˜ ๋ฒ„์ „ (์„ ํƒ). SemVer์ธ ํ•„์š”๋Š” ์—†๋‹ค.
    deprecated: ์ฐจํŠธ์˜ deprecated ์—ฌ๋ถ€ (์„ ํƒ, boolean)
    annotations:
      example: ํ‚ค๋กœ ๋งคํ•‘๋œ ์ฃผ์„๋“ค์˜ ๋ฆฌ์ŠคํŠธ (์„ ํƒ).

     

    1.1. Helm ์„ค์น˜

    $ brew install helm

     

    1.2. Chart ์ƒ์„ฑ

    $ helm create <CHART_NAME>
    $ helm create mychart
    Creating mychart
    $ ls mychart
    Chart.yaml   charts   templates   values.yaml
    - Chart.yaml: chart ์ด๋ฆ„, ๋ฒ„์ „ ์ •๋ณด ๋“ฑ chart์˜ ์ „๋ฐ˜์ ์ธ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋‹ค.
    - charts: chart ์†์— ๋˜ ๋‹ค๋ฅธ ์—ฌ๋Ÿฌ chart๋“ค์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” ๋น„์–ด์žˆ๋‹ค.
    - templates/: chart์˜ ๋ผˆ๋Œ€๊ฐ€ ๋˜๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฆฌ์†Œ์Šค๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํด๋”์ด๋‹ค.
    - values.yaml: ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•˜๋Š” ์„ค์ •๊ฐ’์„ ๊ฐ€์ง„ YAML ํŒŒ์ผ์ด๋‹ค.

     

    1.3 templates/service.yaml

    apiVersion: v1
    kind: Service
    metadata:
        name: {{ include "mychart.fullname" . }}
        labels:
          {{- include "mychart.labels" . | nindent 4 }}
    spec:
        type: {{ .Values.service.type }}                 # ์„œ๋น„์Šค ํƒ€์ž… ์ง€์ •
        ports:
          - port: {{ .Values.service.port }}             # ์„œ๋น„์Šค ํฌํŠธ ์ง€์ •
            targetPort: http
            protocol: TCP
            name: http
        selector:
          {{- include "mychart.selectorLabels" . | nindent 4 }}
    • service.yaml ๋‚ด์šฉ์„ ๋ณด๋ฉด placeholder({{ key }})๊ฐ€ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

    1.4 values.yaml

    replicaCount: 1
    
    image:
      repository: nginx
      pullPolicy: IfNotPresent
    
    imagePullSecrets: []
    nameOverride: ""
    fullnameOverried: ""
    
    ...
    
    service:
      type: LoadBalancer
      port: 8888
    ...
    • YAML ํ˜•์‹์— ๋”ฐ๋ผ ์„ค์ •๊ฐ’๋“ค์ด ์ ํ˜€์žˆ๋‹ค. ์œ„ service.yaml์— ์ง€์ •๋˜์–ด ์žˆ๋˜ service.type๊ณผ service.port ํ™•์ธ(example) service.type๊ณผ service.port๋ฅผ ๊ฐ๊ฐ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ์™€ 8888๋กœ ์ˆ˜์ •ํ•œ๋‹ค.

    1.5 Chart ์„ค์น˜

    helm install <CHART_NAME> <CHART_PATH>
    $ helm install foo ./mychart
    NAME: foo
    LAST DEPLOYED: Mon May 30 13:22:06 2022
    NAMESPACE: default
    STATUS: deployed
    REVISION: 1
    NOTES:
    1. Get the application URL by running these commands:
         NOTE: It may take a few minutes for the LoadBalancer IP to be available.
               You can watch the status of by running 'kubectl get --namespace default svc -w foo-mychart'
      export SERVICE_IP=$(kubectl get svc --namespace default foo-mychart --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
      echo http://$SERVICE_IP:8888
     

     

    1.6 Service ์กฐํšŒ

    $ kubectl get svc
    NAME          TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
    foo-mychart   LoadBalancer   10.108.49.163   <pending>     8888:30633/TCP   28s
    kubernetes    ClusterIP      10.96.0.1       <none>        443/TCP          19m
    • Type๊ณผ Port๋ฅผ ๋ณด๋ฉด values.yaml์—์„œ ์ •์˜ํ•œ๋Œ€๋กœ LoadBalancer์™€ 8888 ํฌํŠธ๋กœ ์ง€์ •๋˜์–ด ์žˆ๋Š”๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

    2-1. Helm Repository

    • helm์„ ์‚ฌ์šฉํ•  ๋•Œ์˜ ๊ฐ€์žฅ ํฐ ์žฅ์ ์€ ์™ธ๋ถ€์— ์ž˜ ๊ตฌ์ถ•๋œ ์• ํ”„๋ฆด์ผ€์ด์…˜์„ ์†์‰ฝ๊ฒŒ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค๋Š” ์ ์ด๋‹ค. helm๋งŒ ์ž˜ ์‚ฌ์šฉํ•ด๋„ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ƒํƒœ๊ณ„์—์„œ ์ง€์›ํ•˜๋Š” ๋‹ค์–‘ํ•˜๊ณ  ๊ฐ•๋ ฅํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๋“ค์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    • helm์—๋Š” chart ์›๊ฒฉ ์ €์žฅ์†Œ์ธ Repository ์žˆ๋‹ค. Repository๋Š” ์—ฌ๋Ÿฌ chart๋ฅผ ํ•œ ๊ณณ์— ๋ฌถ์–ด์„œ ๋ณด๊ด€ํ•ด๋†“์€ ์ €์žฅ์†Œ์ด๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์˜จ๋ผ์ธ์ƒ์— ์ œ๊ณต๋˜๋Š” Repository๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ์›๊ฒฉ ์ €์žฅ์†Œ๋กœ๋ถ€ํ„ฐ chart๋ฅผ ๋กœ์ปฌ ํด๋Ÿฌ์Šคํ„ฐ์— ์„ค์น˜ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

    2-2. Repository ์ถ”๊ฐ€

    $ helm repo add nginx-stable https://helm.nginx.com/stable

     

    2-3. Repository ์—…๋ฐ์ดํŠธ

    $ helm repo update
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "nginx-stable" chart repository
    Update Complete. โŽˆHappy Helming!โŽˆ
    
    • ์ถ”๊ฐ€ํ•œ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์˜ ์ธ๋ฑ์Šค ์ •๋ณด๋ฅผ ์ตœ์‹ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ํ•˜๋Š”๊ฒƒ์ด ํ•„์š”ํ•˜๋‹ค. helm์€ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ ์ •๋ณด๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์บ์‹ฑํ•ด์„œ, ์‹ ๊ทœ chart๋ฅผ ์„ค์น˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์—…๋ฐ์ดํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค.

     

    2-4. ์™ธ๋ถ€ Chart ์„ค์น˜

    $ helm install nginx nginx-stable/nginx-ingress --set rbac.create=true
    • ๋กœ์ปฌ ๋””๋ ‰ํ† ๋ฆฌ์— chart๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋”๋ผ๋„ ์›๊ฒฉ ๋ฆฌํŒŒ์ง€ํ† ๋ฆฌ์— ์žˆ๋Š” chart๋ฅผ ์„ค์น˜ ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ์œ„์—์„œ ์„ค์น˜ํ•œ nginx-stable ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์—์„œ nginx-ingress chart๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

    2-5. Nginx-ingress ์กฐํšŒ

    $ kubectl get svc
    NAME                  TYPE           CLUSTER-IP       EXTERNAL-IP                                                                    PORT(S)                      AGE
    kubernetes            ClusterIP      172.20.0.1       <none>                                                                         443/TCP                      18m
    nginx-nginx-ingress   LoadBalancer   172.20.206.178   ac935cd6f67ab42128f5d46606b76e7f-1861304753.ap-northeast-2.elb.amazonaws.com   80:32472/TCP,443:32499/TCP   4m40s
    • ์ด๋ ‡๋“ฏ ํด๋Ÿฌ์Šคํ„ฐ ์œ„์— Nginx ๊ด€๋ จ๋œ ์†Œํ”„ํŠธ์›จ์–ด ํ•˜๋‚˜ ์—†์–ด๋„ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  helm install ๋ช…๋ น ํ•˜๋‚˜๋กœ ์ˆœ์‹๊ฐ„์— ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

     

    References
    https://helm.sh/ko/docs/chart_template_guide/getting_started/

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.