Kubernetes 이야기

pulumi kubernetes operator 본문

개발/pulumi

pulumi kubernetes operator

kmaster 2022. 9. 2. 15:34
반응형

 

Kubernetes에서 (혹은 일반 서버환경) CI/CD 과정을 자동화 하기 위해 여러 방법들이 소개되어 있다. 대표적인 CI 기능으로는 Jenkins, Argo Workflow, Tekton 등이 있고, CD 기능으로는 ArgoCD, FluxCD 등이 존재한다. ( 물론, AWS나 Azure에서도 CI/CD 도구가 존재한다. )

 

보통 이러한 CI/CD 의 흐름을 Gitlab에서는 아래와 같이 소개한다.

https://docs.gitlab.com/ee/ci/introduction/

 

Pulumi 에서는 CI/CD를 위한 다양한 도구들과 쉽게 통하하여 현재와 동일한 프로세스를 사용하여 클라우드 인프라에 대한 업데이트를 검토, 검증 및 테스트할 수 있도록 지원한다.

 

https://www.pulumi.com/docs/guides/continuous-delivery/

 

이 중 Pulumi kubernetes operator는 GipOps 기능을 지원한다. 특정 Git 에 브랜치의 변경사항을 감지하여 원하는 배포를  할 수 있다.

 

Kubernetes에 Pulumi 스택을 배포하면 CI/CD 및 자동화 시스템을 클러스터에 구축할 수 있는 기능을 제공하여 Kubernetes 워크로드와 함께 인프라를 관리하기 위한 기본 지원을 생성한다.

Pulumi kubernetes operator 설치

Operator 는 다음으로 구성된다.

 

  • ID를 위한 Service Account
  • Service Account 에 대한 Role 과 RoleBinding
  • 컨트롤러

운영자 설치는 Kubectl을 통한 Yaml 배포 방법과 프로그래밍 언어를 사용한 Pulumi 기능으로 설치할 수 있다.

설치는 Yaml 배포로 진행해 보자.

git clone https://github.com/pulumi/pulumi-kubernetes-operator
kubectl apply -f pulumi-kubernetes-operator/deploy/crds
kubectl apply -f pulumi-kubernetes-operator/deploy/yaml
kubectl rollout status deploy/pulumi-kubernetes-operator
Go 언어를 사용하여 Operator를 설치하는 예제
    - https://github.com/pulumi/pulumi-kubernetes-operator/blob/master/deploy/deploy-operator-go/main.
Python 언어를 이용하여 Operator를 설차하는 예제
    - https://github.com/pulumi/pulumi-kubernetes-operator/blob/master/deploy/deploy-operator-py/__main__.py

 

다음과 같은 CR Stack을 생성 하기 전에 Pulumi의 access token을 먼저 등록하자.

apiVersion: v1
kind: Secret
metadata:
  name: pulumi-api-secret
type: Opaque
stringData:
  accessToken: <PULUMI_ACCESS_TOKEN>

값에 본인의 access token 값을 넣어야 한다.

apiVersion: pulumi.com/v1
kind: Stack
metadata:
  name: nginx-k8s-stack-production
spec:
  envRefs:
    PULUMI_ACCESS_TOKEN:
      type: Secret
      secret:
        name: pulumi-api-secret
        key: accessToken
  stack: kmaster8/nginx/dev
  projectRepo: https://github.com/kmaster8/pulumi-k8s-operator-example
  branch: refs/heads/main
  destroyOnFinalize: true
  continueResyncOnCommitMatch: true
  resyncFrequencySeconds: 60
  refresh: true

이제 yaml을 실행해 보자.

# k create -f stack.yaml
stack.pulumi.com/nginx-k8s-stack-production created

 

생성 후 pod상태를 다시 확인해보자 

# k get pods
NAME                                          READY   STATUS    RESTARTS   AGE
nginx-58g93xcw-76d6c9b8c-qfwrr                1/1     Running   0          6s
pulumi-kubernetes-operator-684d4d4f85-cbpmv   1/1     Running   0          15h

 

nginx pod가 생성된 것을 볼 수 있다. 이제 main.go 에서 replica를 3으로 조정하여 commit 해보자.

# k get pods
NAME                                          READY   STATUS    RESTARTS   AGE
nginx-58g93xcw-76d6c9b8c-29dhl                1/1     Running   0          12m
nginx-58g93xcw-76d6c9b8c-qfwrr                1/1     Running   0          14m
nginx-58g93xcw-76d6c9b8c-wv6vl                1/1     Running   0          12m
pulumi-kubernetes-operator-684d4d4f85-cbpmv   1/1     Running   0          15h

 

stack의 상태를 확인해 보자.

# k describe stacks.pulumi.com nginx-k8s-stack-production

...
Status:
  Last Update:
    Last Attempted Commit:   6db56af0e4c3ddafc6a761840834e82ad6162019
    Last Resync Time:        2022-09-02T06:30:46Z
    Last Successful Commit:  6db56af0e4c3ddafc6a761840834e82ad6162019
    Permalink:               https://app.pulumi.com/kmaster8/nginx/dev/updates/24
    State:                   succeeded
  Outputs:
    Ip:  10.106.48.159
Events:
  Type    Reason               Age                 From              Message
  ----    ------               ----                ----              -------
  Normal  StackUpdateDetected  14m                 stack-controller  New commit detected: "8048e20cefa24f3b2059bdf13c9d5c5bda9e6e46".
  Normal  StackUpdateDetected  13m                 stack-controller  New commit detected: "6db56af0e4c3ddafc6a761840834e82ad6162019".
  Normal  StackCreated         32s (x12 over 14m)  stack-controller  Successfully updated stack.

 

Application (Go, Pyhthon, TypeScript 등 ) 으로 workload를 관리할 수 있기 때문에  Git Event를 사용하여 앱을 확장할 수 있는 좋은 기능이다.

반응형

'개발 > pulumi' 카테고리의 다른 글

Pulumi 를 사용하여 EKS Cluster 생성  (0) 2022.04.28
Comments