我为kubernetes和skaffold以及dockerfile开发了yaml文件。我使用Skaffold的部署在我的本地机器上运行良好。现在我需要在我的Google Cloud项目的k8s集群中实现相同的部署,由GitHub存储库中的新标记触发。我发现我必须使用Google Cloud Build,但我不知道如何从cloudbuild.yaml文件执行Skaffold。
kjthegm61#
在https://github.com/GoogleCloudPlatform/cloud-builders-community中有一个skaffold图像要使用它,请执行以下步骤:
git clone https://github.com/GoogleCloudPlatform/cloud-builders-community
字符串
cd cloud-builders-community/skaffold
型
gcloud builds submit --config cloudbuild.yaml .
型然后,在你的cloudbuild.yaml中,你可以在这个基础上添加一个步骤:
cloudbuild.yaml
- id: 'Skaffold run' name: 'gcr.io/$PROJECT_ID/skaffold:alpha' # https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/skaffold env: - 'CLOUDSDK_COMPUTE_ZONE=us-central1-a' - 'CLOUDSDK_CONTAINER_CLUSTER=[YOUR_CLUSTER_NAME]' entrypoint: 'bash' args: - '-c' - | gcloud container clusters get-credentials [YOUR_CLUSTER_NAME] --region us-central1-a --project [YAOUR_PROJECT_NAME] if [ "$BRANCH_NAME" == "master" ] then skaffold run fi
- id: 'Skaffold run'
name: 'gcr.io/$PROJECT_ID/skaffold:alpha' # https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/skaffold
env:
- 'CLOUDSDK_COMPUTE_ZONE=us-central1-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=[YOUR_CLUSTER_NAME]'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud container clusters get-credentials [YOUR_CLUSTER_NAME] --region us-central1-a --project [YAOUR_PROJECT_NAME]
if [ "$BRANCH_NAME" == "master" ]
then
skaffold run
fi
krcsximq2#
您可以使用此图像gcr.io/k8s-skaffold/skaffold例如:
gcr.io/k8s-skaffold/skaffold
steps:- name: 'gcr.io/k8s-skaffold/skaffold:v2.9.0' args: ['skaffold', 'build']
steps:
- name: 'gcr.io/k8s-skaffold/skaffold:v2.9.0'
args: ['skaffold', 'build']
2条答案
按热度按时间kjthegm61#
在https://github.com/GoogleCloudPlatform/cloud-builders-community中有一个skaffold图像
要使用它,请执行以下步骤:
字符串
型
型
然后,在你的
cloudbuild.yaml
中,你可以在这个基础上添加一个步骤:型
krcsximq2#
您可以使用此图像
gcr.io/k8s-skaffold/skaffold
例如:
字符串