GoCD 가벼운 학습

이민석's avatar
Apr 04, 2025
GoCD 가벼운 학습

A. 본문

  1. GoCD 소개

  2. Kubernetes에서의 GoCD

A.1. GoCD 소개

GoCD는 오픈소스 CI/CD 파이프라인으로 복잡한 배포 흐름을 관리하기 용이합니다.

[사진 1] GoCD VSM(Value Stream Mappin) 도식화 [docs.gocd.org/current/]

GoCD는 Task, Job, Stage, Pipeline의 구조를 가지고 있습니다.
기본적으로 절차(순차)적인 방식을 준수하여 편리하게 Pipeline을 구성할 수 있고
속도를 개선하기 위해서 독립(병렬)적인 방식을 Stage 단위에서 사용할 수 있습니다.

단위

구성

실행 방식

하위 요소 실패 시

Task

단일 명령어

Job

N개의 Task

순차

Task 실패 → Job 실패

Stage

N개의 Job

독립(병렬)

Job 실패 → Stage 실패

Pipeline

N개의 Stage

순차

Stage 실패 → Pipeline 실패

[사진 2] GoCD 호출 호출 구조 : Pipeline - Stage - Job - Task

GoCD는 FANIN, FANOUT을 통해서 다수의 Pipeline도 연결할 수 있습니다.

  • FANIN : 여러개의 Pipeline을 하나로 합칠 수 있음 (N → 1)

  • FANOUT : 하나의 Pipeline을 여러개로 나눌 수 있음 (1 → N)

A.2. Kubernetes에서의 GoCD 설치하기

제공된 두 개의 명령어를 사용하면 GoCD 설치 및 접속을 할 수 있습니다.
(실습 환경에서는 local-path라는 이름의 StorageClass를 쓰고 있어서
GoCD Server, Agent에 StorageClass 설정을 추가했습니다.)

[명령어 1] K8s, GoCD 설치하기
helm repo add gocd https://gocd.github.io/helm-chart helm repo update helm install gocd gocd/gocd \ --namespace gocd --create-namespace \ --set server.persistence.storageClass=local-path \ --set agent.persistence.storageClass=local-path
Update Complete. ⎈Happy Helming!⎈ NAME: gocd LAST DEPLOYED: Fri Apr 4 22:06:24 2025 NAMESPACE: gocd STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: 1. Get the GoCD server URL by running these commands: It may take a few minutes before the IP is available to access the GoCD server. echo "GoCD server public IP: http://$(kubectl get ingress gocd-server --namespace=gocd -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" 2. Get the service account token to configure the elastic agent plugin by doing the following: A default role gocd with cluster scoped privileges has been configured. The service account called gocd in namespace gocd has been associated with the role. To check, secret_name=$(kubectl get serviceaccount gocd --namespace=gocd -o jsonpath="{.secrets[0].name}") kubectl get secret $secret_name --namespace=gocd -o jsonpath="{.data['token']}" | base64 --decode To obtain the CA certificate, do kubectl get secret $secret_name --namespace=gocd -o jsonpath="{.data['ca\.crt']}" | base64 --decode 3. The GoCD server URL for configuring the Kubernetes elastic agent plugin settings: echo "http://$(kubectl get service gocd-server --namespace=gocd -o jsonpath='{.spec.clusterIP}'):8153/go" 4. The cluster URL for configuring the Kubernetes elastic agent plugin settings can be obtained by: kubectl cluster-info 5. Persistence ################################################################################################ WARNING: The default storage class will be used. The reclaim policy for this is usually `Delete`. You will lose all data at the time of pod termination! ################################################################################################
[명령어 2] K8s, GoCD 배포 확인하기

1. 전체 확인하기

kubectl get all -n gocd
NAME READY STATUS RESTARTS AGE pod/gocd-server-76ccdb59c9-cqk8x 1/1 Running 0 8m35s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/gocd-server NodePort 10.106.151.2168153:32182/TCP 8m35s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/gocd-agent 0/0 0 0 8m35s deployment.apps/gocd-server 1/1 1 1 8m35s NAME DESIRED CURRENT READY AGE replicaset.apps/gocd-agent-6ccf9697bd 0 0 0 8m35s replicaset.apps/gocd-server-76ccdb59c9 1 1 1 8m35s

2. 서비스 확인하기

kubectl get svc -n gocd
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE gocd-server NodePort 10.106.151.2168153:32182/TCP 8m26s

배포된 GoCD에 접속해보면, 샘플 파이프라인을 볼 수 있습니다.
(History, Compare, Changes, VSM 등의 다양한 옵션이 있음)

GoCD Dashboard
[사진 3] GoCD Dashboard

옵션 중에서 VSM을 눌러서 Stage, Job, Task 순으로 정보 확인이 가능합니다.

GoCD VSM (Stage - Job - Task : command)
[사진 4] GoCD VSM (Stage - Job - Task : command)

샘플 파이프라인은 1개의 Stage, Job, Task가 있어서 단순합니다.
따라서 N개의 Stage, Job, Task가 있는 A.3, A.4, A.5를 진행했습니다.

A.3. Pipeline Wizard 사용하기

Use Pipeline Wizard 옵션에서 4단계로 새 Pipeline을 만들 수 있습니다.

  1. Material — 대부분의 CI/CD 도구에서 Trigger라고 부르는 것과 유사

  2. Pipeline Name — Pipeline에 대한 이름, 그룹, 파라미터 설정

  3. Stage Details — Stage에 대한 이름, 변경 사항 자동

  4. Job and Tasks — Job에 대한 이름, Tasks(command)들

Use Pipeline Wizard
[사전 5] Use Pipeline Wizard

이 과정에서 새 Pipeline을 만들때 N개의 Stage, Job 생성이 불가능함을 알았습니다.
(수동(메뉴얼) 작업에서 오는 일반적인 단점들은 모두 제외한 항목입니다.)

  1. 생성 시점에 Stage를 1개밖에 사용하지 못한다.

  2. 생성 시점에 Job을 1개밖에 사용하지 못한다.

아래 사진을 보면 Stage, Job에 대한 제어가 지원되지 않음을 알 수 있습니다.

Use Pipeline Wizard 예제
[사전 6] Use Pipeline Wizard 예제

A.4. Pipeline Template 사용하기

A.5. Pipeline as Code 사용하기

Share article

Unchaptered