CloudONE(3). Spinnaker 를 이용한 Helm chart 배포 파이프라인 구축기

Jiyoon·2021년 4월 5일
0

Kubernetes

목록 보기
3/10

Background

SpaceONE의 helm chart 배포는 manifest values.yaml 파일들을 Gitlab에 업로드후 수동 배포를 했기 때문에, yaml 파일이 산재해있어 관리가 어려운 issue가 있었다. 이와 더불어, gitlab repo와 연동해 values.yaml 들을 관리하기 위해 Spinnaker를 이용해 편리하게 관리하고 싶어 도입하게 되었다.

Goal

Prometheus monitoring 용 prometheus-mongodb-exporter를 helm chart와 spinnaker pipeline을 구성해 재설치하기

Helm 배포시에 필요한 작업환경은 다음과 같다.

여러 사람이 파이프라인을 구성할 때에도, 공통된 Helm Chart 명명법을 사용하기 위해 Naming Rule을 정의했다.

Helm chart 배포 시의 Naming rule

  1. Helm chart name

helmhelm chart name(여러개라면 특징에 따라) 순번

helm_prometheus-mongodb_exporter_rs1

  1. values.yaml name

helm chart name_values.yaml

ex) prometheus_mongodb_exporter_values.yaml


Spinnaker Application 생성

여러가지 helm chart 배포 시 마다 사용할 파이프라인 구성을 위해 helm application을 먼저 생성해준다.

Pipeline 구성 방식

Helm application을 생성한 후, Spinnaker에서 배포가 진행되는 순서와 configuration을 정의하는 pipeline을 다음과 같이 구성했다.


Helm chartspinnaker로 배포하기 위해서는 2개의 stage 구성이 필요하다.

그리고 Stage를 구성할 때에는 다음과 같은 정보를 설정해야한다.

  • Type

  • Stage Name

  • Depends On

    설정한 특정 stage가 실행되지 않으면 설정정보가 환경에 deploy 되지 않을 것이라는 제약단계를 명시하는 부분


Stage 1. Bake helm values

  • Helm deploy를 위해서는 spinnaker의 templating engine을 이용하여 templatemanifest로 바꾸도록 Bake(Manifest) stage를 구성한다.

    이 단계에서 사용한 manifest configuration은 다음과 같다.

그리고, 필요한 Artifact는 다음과 같다.

주의할 점
overrides artifact에 들어가야 할 gitlab file은 file자체의 경로가 아닌 Gitlab repository-file api 요청경로를 입력해야 한다.
ex.https://gitlab.example.com/api/v4/projects/:id/repository/files/:file_path/raw?ref=master&private_token=xxxx(access_token)

SpaceONE의 경우, 기존에 artifact를 halyard를 이용해 관리했기 때문에, mongodb-exporter용 helm artifact를 추가했다.

*$su hal
*$ hal config artifact helm account list
*+ Artifact accounts for helm:
*  - helmprometheus-operator-ac
*  - helm-prometheus-community-ac # account name

Helm을 위해 설정한 Artifact 정보

  • halyard를 사용해 artifact 추가

    *1* ##artifact edit 가능하도록 설정 변경
    *2* $ hal config features edit --artifacts true
    *4*+ Get current deployment
    *5*  Success
    *6*+ Get features
    *7*  Success
    *2122*#2. artifact 추가~
    *23*$ hal config artifact helm account add stable-prometheus-operator --repository https://github.com/helm/charts/tree/master/stable/prometheus-operator
    *24*/opt/halyard/bin/hal: 41: cd: can't cd to /root
    *25*+ Get current deployment
    *26*  Success
    *27*+ Add the stable-prometheus-operator artifact account
    *28*  Success
    *29*Validation in default:
    *30*- WARNING Version "1.21.2" was patched by "1.21.4". Please upgrade
    *31*  when possible.
    *32*? https://www.spinnaker.io/community/releases/versions/
    *3334*+ Successfully added artifact account stable-prometheus-operator
    *35*  for artifact provider helm.
    *3637*  ###account 에 repo 추가
    *38*  $ hal config artifact helm account add stable-prometheus-operator --repository https://git.stargate.spaceone.dev/spaceone/helm-values/-/blob/master/helmvalues_test.yaml
    *39*/opt/halyard/bin/hal: 41: cd: can't cd to /root
    *40*+ Get current deployment
    *41*  Success
    *42*+ Add the stable-prometheus-operator artifact account
    *43*  Success
    *44*Validation in default:
    *45*- WARNING Version "1.21.2" was patched by "1.21.4". Please upgrade
    *46*  when possible.
    *47*? https://www.spinnaker.io/community/releases/versions/
    *4849*+ Successfully added artifact account stable-prometheus-operator
    *50*  for artifact provider helm.
    *51*$ hal deploy apply
    *52*/opt/halyard/bin/hal: 41: cd: can't cd to /root
    *53*+ Get current deployment
    *54*  Success
    *55*+ Prep deployment
    *56*  Success
    *57*Validation in default.features:
    *58*- WARNING Field Features.artifacts not supported for Spinnaker
    *59*  version 1.21.2: Artifacts are now enabled by default.
    *60*? You no longer need this.
    *6162*Validation in default:
    *63*- WARNING Version "1.21.2" was patched by "1.21.4". Please upgrade
    *64*  when possible.
    *65*? https://www.spinnaker.io/community/releases/versions/
    *6667*Validation in default.stats:
    *68*- INFO Stats are currently ENABLED. Usage statistics are being
    *69*  collected���Thank you! These stats inform improvements to the product, and that
    *70*  helps the community. To disable, run `hal config stats disable`. To learn more
    *71*  about what and how stats data is used, please see
    *72*  https://www.spinnaker.io/community/stats.
    *7374*+ Preparation complete... deploying Spinnaker
    *75*+ Get current deployment
    *76*  Success
    *77*+ Apply deployment
    *78*  Success
    *79*+ Deploy spin-redis
    *80*  Success
    *81*+ Deploy spin-clouddriver
    *82*  Success
    *83*+ Deploy spin-front50
    *84*  Success
    *85*+ Deploy spin-orca
    *86*  Success
    *87*+ Deploy spin-deck
    *88*  Success
    *89*+ Deploy spin-echo
    *90*  Success
    *91*+ Deploy spin-gate
    *92*  Success
    *93*+ Deploy spin-igor
    *94*  Success
    *95*+ Deploy spin-rosco
    *96*  Success`
  • helm-prometheus-community-ac (2020.10.22 기준 prometheus operator 신 버전 chart)

https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

`1$ hal config artifact helm account get helm-prometheus-community-ac
3+ Get current deployment
4 Success
5+ Get helm-prometheus-community-ac artifact account
6 Success
7+ Artifact account helm-prometheus-community-ac:`

  • helm prometheus-operator-ac (2020.10.22 기준 stable 버전)

    `1$ hal config artifact helm account get helmprometheus-operator-ac
    23/opt/halyard/bin/hal: 41: cd: can't cd to /root/gikang/mongo-exporter/prometheus-mongodb-exporter-values
    45+ Artifact account helmprometheus-operator-ac: 
    67HelmArtifactAccount(name=helmprometheus-operator-ac, repository=https://kubernetes-charts.storage.googleapis.com, username=null, password=null, usernamePasswordFile=null)`

Stage 1을 마무리하면, stage 자체적으로 artifact를 생산하고(Produces Artifacts), 이 artifact를 다음 stage2 로 넘겨서 stage 2에서 cluster에 배포하게 된다.

Stage 2. Deploy to Dev

Spinnaker 가 helm deploy 시 kubernetes cluster에 아래 2가지 명령어를 kubectl , helm cmd 대신 해준다고 생각하면 된다.

  • stage 1: helm template helm template <chart> --values <values-file> > artifact.yaml
  • stage 2: kubectl apply -f artifact.yaml

helm chart 배포 확인

예시

1*k get po -n helm-values
*2*NAME                                                     READY   STATUS    RESTARTS   AGE
*3*helmjy-prometheus-mongodb-exporter-fb746fb65-mqxjp       1/1     Running   0          19h
*4*mongo5x-prometheus-cloudwatch-exporter-c59cb74f8-lh9j6   1/1     Running   0          23h`
profile
Jiyoon in cloud valley, Change the world Why Not? / 오픈소스 생태계를 잘 이해하는 Cloud engineer가 되고 싶은 지윤

0개의 댓글