콘텐츠로 이동
AggregaAggrega
언어 선택: 한국어
이 페이지는 기계 번역되었습니다. 영어 원문 읽기.

어태치먼트가 게시하는 값에 워크로드 바인딩하기

helm 프로바이더의 Workload 합성으로 Kubernetes에 렌더링되는 단일 stateless 앱입니다. 외부 차트는 없습니다. 이 앱은 해당 Component가 슬롯을 선언하고 Release가 채우는 클라우드 ID로 실행됩니다. 슬롯을 채우는 어태치먼트는 Kubernetes ServiceAccount 하나를 내보내고 그 이름을 게시하며, 앱의 Recipe는 파드를 그 게시된 이름에 바인딩합니다.

여기서 핵심은 흐름의 방향입니다. 생산자는 이름을 한 번 명시하고, 소비자는 그것을 읽습니다. 소비하는 쪽 어디에서도 생산자가 이미 소유한 값을 다시 명시하지 않으므로 둘이 어긋날 수 없습니다.

예제 생성하기

아래 명령으로 이 예제를 빌드하거나, AI 어시스턴트에게 대신 빌드하게 할 수 있습니다.

예제 이름을 딴 새 폴더에 예제를 씁니다:

Terminal window
aggrega scaffold --example workload-identity-binding

그런 다음 이어서 실행할 명령을 출력합니다. 첫 번째 명령은 새 폴더로 이동합니다:

Terminal window
cd workload-identity-binding

빌드

Terminal window
aggrega build --release release.yaml --auto-pull

카탈로그는 .aggrega-config.yaml에 지정된 두 소스에서 해석됩니다. 하나는 예제 자체의 ./catalog(local/compute/identity-app Component와 그 helm/identity-app 합성 Recipe)이고, 다른 하나는 hub 레지스트리(core/gcp-workload-identity Feature와 그 FeatureRecipe)입니다. --auto-pull은 새로 클론한 사본에 없는 잠금 파일을 빌드 중에 기록합니다. 매니페스트 세 개가 dist/helm/helm/ 아래에 생성됩니다.

AI 어시스턴트 사용

Aggrega 도구로 설정한 AI 어시스턴트도 같은 작업을 할 수 있습니다. 다음 프롬프트를 붙여 넣으십시오.

Aggrega 도구만 사용하고, 폴더를 직접 만들지 마십시오. 작업 영역 폴더에 아직 `workload-identity-binding` 폴더가 없으면 `example`을 `workload-identity-binding` 값으로 설정하고 `dir` 없이 `scaffold` 도구를 한 번 호출하십시오. 그러면 새 `workload-identity-binding` 폴더에 예제가 작성됩니다. 그런 다음 `workspace_root`를 `workload-identity-binding` 값으로, `release`를 `release.yaml` 값으로, `auto_pull`을 true로, `write`를 true로 설정하여 `build` 도구를 호출하십시오. 빌드가 작성한 파일을 알려 주십시오. 파일은 `workload-identity-binding/dist/` 아래에 있습니다.

Component는 필요를 선언하고, Release는 그것을 채웁니다

앱은 실행에 사용할 ID가 필요하므로, 해당 Component는 이를 필수 identity 슬롯으로 선언합니다.

catalog/component/local/compute/identity-app/1.0.0/component.yaml
featuresSchema:
identity:
required: true
selector: "feature.aggrega.ai/kind!=secret"
inject: []

Aggregate는 이에 대해 아무것도 작성하지 않습니다. 앱이 어떤 클라우드에서 어떤 ID로 실행될지는 대상마다 운영자가 선택하는 것이므로, Release가 ID Feature와 그 Feature에 필요한 모든 필드로 슬롯을 채웁니다.

release.yaml
features:
identity:
type: core/gcp-workload-identity
infra:
service_account_name: app-workload-identity
gcp_service_account: app-dev@example-project.iam.gserviceaccount.com

슬롯을 채우지 않은 Release는 해당 슬롯을 명시하며 중단됩니다. EKS 클러스터용 Release는 같은 슬롯을 대신 core/aws-irsa와 그 role_arn으로 채우고, 그 Manifest는 해당 Feature를 그 FeatureRecipe에 매핑합니다. 셀렉터는 자격 증명이 슬롯에 들어오지 못하게 합니다. secret 종류의 Feature로 슬롯을 채우면 중단됩니다.

어태치먼트의 게시

Feature는 자신의 schema.provides에서 name을 게시한다고 선언하고, 그 FeatureRecipe가 이를 게시합니다. 게시되는 값은 내보낸 차트가 ServiceAccount 이름을 지정할 때 쓰는 것과 같은 local에서 나오며, Release가 service_account_name을 작성한 경우에는 운영자가 설정한 그 값입니다.

# FeatureRecipe gcp-workload-identity
locals:
sa_name: '{{ default (printf "%s-%s" .context.rendered_name (.attachment_name | replace "_" "-")) .infra.service_account_name }}'
provides:
name: "{{ .locals.sa_name }}"

Recipe의 소비

소비하는 Recipe는 게시된 이름을 .features.<instance-name>.provides.<key>에서 읽습니다.

# helm/identity-app recipe workload
serviceAccount: "{{ .features.identity.provides.name }}"
containers:
main:
variables:
IDENTITY_SERVICE_ACCOUNT: {{ .features.identity.provides.name }}

두 읽기 모두 어태치먼트가 실제로 내보낸 ServiceAccount로 해석됩니다.

app--identity--app-serviceaccount-app-workload-identity.yaml
[… omitted: the apiVersion]
kind: ServiceAccount
metadata:
name: app-workload-identity
annotations:
iam.gke.io/gcp-service-account: "app-dev@example-project.iam.gserviceaccount.com"
[… omitted: the boundary and recipe annotations, and the labels, that every rendered document carries]
app-deployment.yaml
[… omitted: the Deployment's metadata, selector and pod template up to the containers]
containers:
- name: main
[… omitted: the image and the port]
env:
[… omitted: the GREETING variable]
- name: IDENTITY_SERVICE_ACCOUNT
value: app-workload-identity
serviceAccountName: app-workload-identity

반복하지 않고 읽는 이유

대안은 소비하는 쪽에 app-workload-identity를 한 번 더 작성하는 것입니다. 이 방식은 누군가 운영자의 service_account_name을 변경하면서 두 곳 중 한 곳만 갱신하기 전까지는 작동합니다. 그 시점에 파드는 존재하지 않는 ServiceAccount를 요청하게 되며, 두 표기 모두 유효한 문자열이므로 컴파일 과정에서 이를 감지하는 것은 아무것도 없습니다.

.features.identity.provides.name을 읽으면 두 번째 표기가 사라집니다. 같은 형태가 모든 어태치먼트에 적용됩니다. 자격 증명은 자신의 Secret 로케이터를 .features.<slot>.provides.name에 게시하고, 사이드카는 포트를, ID는 이름을 게시합니다. 필드별 전체 어태치먼트 형태는 templates/template-context-contract.md에 있습니다.

운영자 사이징

release.yaml은 환경별로 운영자 사이징 원칙을 충족합니다. 컨테이너 이미지 태그는 infra.image_tag(myapp:1.2)에서 오고, ID, 즉 그 Feature와 그 Feature의 필드는 슬롯의 채움에서 옵니다. 개발자의 Aggregate는 둘 다 포함하지 않습니다.