설정 가이드에 설명된 대로 Connect 게이트웨이 및 기타 필요한 API가 프로젝트에 사용 설정되었는지 확인합니다.
1. Cloud Build 서비스 계정에 IAM 역할 부여
기본적으로 Cloud Build는 MY_PROJECT_NUMBER @cloudbuild.gserviceaccount.com 형식의 주소를 사용해서 Google Cloud 서비스 계정을 사용하여 모든 필요한 작업을 실행합니다. Google Cloud 콘솔의 Cloud Build - 설정에서 프로젝트에 대한 이 서비스 계정 이메일 주소를 확인할 수 있습니다.
게이트웨이 설정 가이드에서 IAM 권한 부여의 안내에 따라 프로젝트에 필요한 역할을 이 계정에 부여합니다.
2. Cloud Build 서비스 계정에 RBAC 정책 지정
게이트웨이 설정 가이드에서 RBAC 정책 구성의 안내에 따라 사용하려는 모든 클러스터에서 Cloud Build 서비스 계정에 적합한 권한을 부여합니다.
정책 컨트롤러를 사용하여 여러 클러스터에서 RBAC 정책을 배포하고 유지관리하는 것이 좋습니다.
3. Cloud Build 파이프라인 만들기
Cloud Build 워크플로에는 파이프라인을 구성하기 위해 cloudbuild.yaml 파일이 필요합니다. 다음은 정적 매니페스트를 2개의 서로 다른 클러스터( Google Cloud용 GKE 클러스터 하나와 VMware용 GKE 클러스터 하나)에 배포하는 간단한 예시입니다. Cloud Build 파이프라인을 구성하는 방법에 대한 자세한 내용은 Cloud Build 문서를 참조하세요.
Git 저장소에 구성을 푸시하면 Cloud Build 워크플로가 필요한 애플리케이션을 지정된 클러스터에 배포합니다. 또한 링크된 Git 저장소에서 변경사항을 감지하여 자동화된 애플리케이션 업데이트 또는 설치를 트리거하도록 Cloud Build를 설정할 수 있습니다.
고급 사용
표준 Cloud Build 개념이 사용되기 때문에 특정 CI/CD 요구에 맞게 이 예시를 조정하고 맞춤설정할 수 있습니다. 특히 처음부터 이미지를 빌드하여 파이프라인에 배포하려면 gke-deploy 빌더의 준비 모드를 사용하면 됩니다. 예를 들어 다음 Cloud Build 구성을 참조하세요.
이 구성은 Git 저장소 루트에 있는 Dockerfiles에서 Docker 이미지를 빌드하고 여기에 Git SHA 태그를 지정합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Integrate the Connect gateway with Cloud Build\n==============================================\n\nThis is a basic tutorial on how to integrate [Cloud Build](/cloud-build/docs/overview) with the Connect gateway, letting you create a CI/CD pipeline for GKE clusters running across many different environments.\n\nThis tutorial assumes that you are familiar with the previous sections in [the Connect gateway guide](/kubernetes-engine/enterprise/multicluster-management/gateway), and are also familiar with Cloud Build. These instructions leverage the [`cloud-sdk` builder image](https://github.com/GoogleCloudPlatform/cloud-sdk-docker) which requires some minor scripting (as you'll see below).\n\nBefore you begin\n----------------\n\n- Ensure that you have the following command line tools installed:\n\n - The latest version of the [Google Cloud CLI](/sdk/docs/install), which includes `gcloud`, the command-line tool for interacting with Google Cloud.\n - [`kubectl`](/kubernetes-engine/fleet-management/docs/before-you-begin#install-kubectl), the command-line tool for interacting with Kubernetes.\n\n If you are using Cloud Shell as your shell environment for interacting with Google Cloud, these tools are installed for you.\n- Ensure that you have [initialized](/sdk/docs/install-sdk#initializing_the) the gcloud CLI for use with your project.\n\n- Ensure the Connect gateway and other required APIs are enabled for your project, as described in the [setup guide](/kubernetes-engine/enterprise/multicluster-management/gateway/setup#enable_the_gateway_apis).\n\n1. Grant IAM roles to the Cloud Build service account\n-----------------------------------------------------\n\nBy default, Cloud Build uses a Google Cloud service account to run all required work, with an address in the format \u003cvar translate=\"no\"\u003eMY_PROJECT_NUMBER\u003c/var\u003e` @cloudbuild.gserviceaccount.com`. You can find this service account email address for your project under **Cloud Build** - **Settings** in the [Google Cloud console](https://console.cloud.google.com/cloud-build/settings).\n\nFollow the instructions in [Grant IAM permissions](/kubernetes-engine/enterprise/multicluster-management/gateway/setup#grant_iam_roles_to_users) in the gateway setup guide to grant this account the required roles in your project.\n\n2. Specify RBAC policies for the Cloud Build service account\n------------------------------------------------------------\n\nFollow the instructions in [Configure RBAC policies](/kubernetes-engine/enterprise/multicluster-management/gateway/setup#configure_role-based_access_control_rbac_policies) in the gateway setup guide to give the Cloud Build service account appropriate permissions on all the clusters you want to use.\n\nWe strongly recommend using [Policy Controller](/anthos-config-management/docs/concepts/policy-controller) to deploy and maintain RBAC policies on multiple clusters.\n\n3. Create a Cloud Build pipeline\n--------------------------------\n\nThe Cloud Build workflow needs a `cloudbuild.yaml` file to configure the pipeline. The following is a simple example that deploys a static manifest to two different clusters (one GKE cluster on Google Cloud, and one on VMware). You can find out more about how to configure a Cloud Build pipeline in the [Cloud Build documentation](/cloud-build/docs/configuring-builds/create-basic-configuration). \n\n steps:\n - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'\n entrypoint: bash\n id: Deploy to cluster on Google Cloud\n args:\n - '-c'\n - |\n set -x && \\\n export KUBECONFIG=\"$(pwd)/gateway-kubeconfig\" && \\\n gcloud container fleet memberships get-credentials my-gke-cluster && \\\n kubectl --kubeconfig gateway-kubeconfig apply -f myapp.yaml\n - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'\n entrypoint: bash\n id: Deploy to cluster on VMware\n args:\n - '-c'\n - |\n set -x && \\\n export KUBECONFIG=\"$(pwd)/gateway-kubeconfig\" && \\\n gcloud container fleet memberships get-credentials my-vmware-cluster && \\\n kubectl --kubeconfig gateway-kubeconfig apply -f myapp.yaml\n\nYou can put any desired workflow in `myapp.yaml` to configure clusters. Here is an example: \n\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: my-nginx\n spec:\n selector:\n matchLabels:\n app: nginx\n replicas: 3\n template:\n metadata:\n labels:\n app: nginx\n spec:\n containers:\n - name: nginx\n image: nginx:1.14.2\n ports:\n - containerPort: 80\n\nOnce you push your configuration to your Git repository, the Cloud Build workflow deploys the required application to the specified clusters. You can also set up Cloud Build to detect changes in the linked Git repository to trigger automated application update or installation.\n\nAdvanced usage\n--------------\n\nSince it uses standard Cloud Build concepts, you can adapt and customize our example further to suit your particular CI/CD needs. In particular, if you want to build an image from scratch and deploy it in your pipeline, you can use the `gke-deploy` builder's [prepare mode](https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gke-deploy/doc/gke-deploy_prepare.md). For example, the following Cloud Build configuration:\n\n1. Builds a docker image from the Dockerfile in the root of the Git repo and tags it with the Git SHA.\n2. Pushes the tagged image to the project's [Container Registry](/container-registry/docs/overview).\n3. Prepares the Kubernetes manifests in the `manifest` directory by setting the correct image tag(s), placing the output manifests in `output/expanded`.\n4. Deploys to an GKE cluster on premises using the Connect gateway.\n\n steps:\n - name: 'gcr.io/cloud-builders/docker'\n id: \"Build Container\"\n args: ['build', '--tag=gcr.io/$PROJECT_ID/demo-app:$SHORT_SHA', '.']\n - name: 'gcr.io/cloud-builders/docker'\n id: \"Push to GCR\"\n args: ['push', 'gcr.io/$PROJECT_ID/demo-app:$SHORT_SHA']\n - name: \"gcr.io/cloud-builders/gke-deploy\"\n id: \"Prepare Manifests\"\n args:\n - prepare\n - --filename=manifests/\n - --image=gcr.io/$PROJECT_ID/demo-app:$SHORT_SHA\n - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'\n entrypoint: bash\n id: \"Deploy to cluster on VMware\n args:\n - '-c'\n - |\n set -x && \\\n export KUBECONFIG=\"$(pwd)/gateway-kubeconfig\" && \\\n gcloud container fleet memberships get-credentials my-vmware-cluster && \\\n kubectl --kubeconfig=gateway-kubeconfig apply -f output/expanded\n\nNote that in this example we had to create an [image pull secret](http://docs.heptio.com/content/private-registries/pr-gcr.html) to authorize the on-premises GKE cluster to pull images from Container Registry.\n\nFor more ideas for Cloud Build usage, see the\n[Cloud Build documentation](/build/docs/overview)."]]