docker 使用Google Cloud Build执行Skaffold部署?

zfciruhq  于 2024-01-06  发布在  Docker
关注(0)|答案(2)|浏览(149)

我为kubernetes和skaffold以及dockerfile开发了yaml文件。我使用Skaffold的部署在我的本地机器上运行良好。
现在我需要在我的Google Cloud项目的k8s集群中实现相同的部署,由GitHub存储库中的新标记触发。我发现我必须使用Google Cloud Build,但我不知道如何从cloudbuild.yaml文件执行Skaffold。

kjthegm6

kjthegm61#

https://github.com/GoogleCloudPlatform/cloud-builders-community中有一个skaffold图像
要使用它,请执行以下步骤:

  • 克隆存储库
  1. git clone https://github.com/GoogleCloudPlatform/cloud-builders-community

字符串

  • 转到skaffold目录
  1. cd cloud-builders-community/skaffold

  • 构建图像:
  1. gcloud builds submit --config cloudbuild.yaml .


然后,在你的cloudbuild.yaml中,你可以在这个基础上添加一个步骤:

  1. - id: 'Skaffold run'
  2. name: 'gcr.io/$PROJECT_ID/skaffold:alpha' # https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/skaffold
  3. env:
  4. - 'CLOUDSDK_COMPUTE_ZONE=us-central1-a'
  5. - 'CLOUDSDK_CONTAINER_CLUSTER=[YOUR_CLUSTER_NAME]'
  6. entrypoint: 'bash'
  7. args:
  8. - '-c'
  9. - |
  10. gcloud container clusters get-credentials [YOUR_CLUSTER_NAME] --region us-central1-a --project [YAOUR_PROJECT_NAME]
  11. if [ "$BRANCH_NAME" == "master" ]
  12. then
  13. skaffold run
  14. fi

展开查看全部
krcsximq

krcsximq2#

您可以使用此图像gcr.io/k8s-skaffold/skaffold
例如:

  1. steps:
  2. - name: 'gcr.io/k8s-skaffold/skaffold:v2.9.0'
  3. args: ['skaffold', 'build']

字符串

相关问题