Deploy changes to your k8s deployments right from your CI tool.
REPO_NAME
: Image name (if you use CircleCI, you can useREPO_NAME=${CIRCLE_PROJECT_REPONAME,,}
)PROJECT_NAME
: Your Google cloud engine project nameCLUSTER_NAME
: Your Google container engine cluster nameCLOUDSDK_COMPUTE_ZONE
: Compute zone of your nodesGCLOUD_SERVICE_KEY
: base64 hash of your iam key (check below for instructions)
PROJECT_NAME="your-project-name"
gcloud iam service-accounts create circleci --display-name=circleci
gcloud projects add-iam-policy-binding ${PROJECT_NAME} --member serviceAccount:circleci@${PROJECT_NAME}.iam.gserviceaccount.com --role roles/container.admin
gcloud projects add-iam-policy-binding ${PROJECT_NAME} --member serviceAccount:circleci@${PROJECT_NAME}.iam.gserviceaccount.com --role roles/container.clusterAdmin
gcloud projects add-iam-policy-binding ${PROJECT_NAME} --member serviceAccount:circleci@${PROJECT_NAME}.iam.gserviceaccount.com --role roles/container.developer
gcloud projects add-iam-policy-binding ${PROJECT_NAME} --member serviceAccount:circleci@${PROJECT_NAME}.iam.gserviceaccount.com --role roles/storage.admin
gcloud iam service-accounts keys create key.json --iam-account circleci@${PROJECT_NAME}.iam.gserviceaccount.com
GCLOUD_SERVICE_KEY=`base64 key.json`
Full instructions on: https://github.com/RefurbMe/k8s-sample
# GCLOUD_SERVICE_KEY=`base64 key.json` # comes from the guide above
CIRCLE_TOKEN="your-circleci-api-token"
GIT_ACCOUNT="your-github-username"
IMAGE_REGISTRY='us.gcr.io'
PROJECT_NAME="your-project-name"
CLOUDSDK_COMPUTE_ZONE='us-east1-b'
CLUSTER_NAME="your-cluster-name"
repos=( "api" "frontend" )
for repo in "${repos[@]}"
do
echo "\n$repo\n"
curl -X POST --header "Content-Type: application/json" -d "{\"name\":\"GCLOUD_SERVICE_KEY\", \"value\":\"${GCLOUD_SERVICE_KEY}\"}" "https://circleci.com/api/v1.1/project/github/${GIT_ACCOUNT}/${repo}/envvar?circle-token=${CIRCLE_TOKEN}"
sleep 0.5;
curl -X POST --header "Content-Type: application/json" -d "{\"name\":\"IMAGE_REGISTRY\", \"value\":\"${IMAGE_REGISTRY}\"}" "https://circleci.com/api/v1.1/project/github/${GIT_ACCOUNT}/${repo}/envvar?circle-token=${CIRCLE_TOKEN}"
sleep 0.5;
curl -X POST --header "Content-Type: application/json" -d "{\"name\":\"PROJECT_NAME\", \"value\":\"${PROJECT_NAME}\"}" "https://circleci.com/api/v1.1/project/github/${GIT_ACCOUNT}/${repo}/envvar?circle-token=${CIRCLE_TOKEN}"
sleep 0.5;
curl -X POST --header "Content-Type: application/json" -d "{\"name\":\"CLOUDSDK_COMPUTE_ZONE\", \"value\":\"${CLOUDSDK_COMPUTE_ZONE}\"}" "https://circleci.com/api/v1.1/project/github/${GIT_ACCOUNT}/${repo}/envvar?circle-token=${CIRCLE_TOKEN}"
sleep 0.5;
curl -X POST --header "Content-Type: application/json" -d "{\"name\":\"CLUSTER_NAME\", \"value\":\"${CLUSTER_NAME}\"}" "https://circleci.com/api/v1.1/project/github/${GIT_ACCOUNT}/${repo}/envvar?circle-token=${CIRCLE_TOKEN}"
sleep 0.5;
done