Skip to content

Commit

Permalink
remove gcr repo name from images (GoogleCloudPlatform#98)
Browse files Browse the repository at this point in the history
This removes hardcoded GCP project name from images and requires an explicit repository flag to skaffold. Also updating the cloudbuild.yaml for staging with the gcr.io/k8s-skaffold/skaffold image.

Fixes GoogleCloudPlatform#17.
  • Loading branch information
davidstanke authored and ahmetb committed Dec 3, 2018
1 parent d69f1a4 commit 8dabe7f
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 51 deletions.
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,27 @@ Find **Protocol Buffers Descriptions** at the [`./pb` directory](./pb).

kubectl get nodes

2. Enable Google Container Registry (GCR) on your GCP project and configure the
1. Enable Google Container Registry (GCR) on your GCP project and configure the
`docker` CLI to authenticate to GCR:

gcloud services enable containerregistry.googleapis.com

gcloud auth configure-docker -q

3. Set your project ID on image names:

- Edit `skaffold.yaml`, update the `imageName:` fields that look like
`gcr.io/[PROJECT_ID]` with your own GCP project ID.

- Similarly, edit all Kubernetes Deployment manifests in the
[`./kubernetes-manifests`](./kubernetes-manifests) directory. Find the
`image:` fields with `gcr.io/[...]` and change them to your own GCP project
ID.

5. Run `skaffold run` from the root of this repository. This command:
1. In the root of this repository, run `skaffold run --default-repo=gcr.io/[PROJECT_ID]`,
where [PROJECT_ID] is your GCP project ID.

This command:
- builds the container images
- pushes them to GCR
- applies the `./kubernetes-manifests` deploying the application to
Kubernetes.

**Troubleshooting:** If you get "No space left on device" error on Google Cloud Shell,
you can build the images on Google Cloud Build:
[Enable the Cloud Build API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com), then run `skaffold run -p gcb` instead.
[Enable the Cloud Build API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com), then run `skaffold run -p gcb --default-repo=gcr.io/[PROJECT_ID]` instead.

6. Find the IP address of your application, then visit the application on your
1. Find the IP address of your application, then visit the application on your
browser to confirm installation.

kubectl get service frontend-external
Expand Down Expand Up @@ -168,7 +161,7 @@ Find **Protocol Buffers Descriptions** at the [`./pb` directory](./pb).

This is required only once.

5. Deploy the application with `skaffold run`.
5. Deploy the application with `skaffold run --default-repo=gcr.io/[PROJECT_ID]`.

6. Run `kubectl get pods` to see pods are in a healthy and ready state.

Expand Down
35 changes: 21 additions & 14 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# This file is used to build and deploy the app into a GKE cluster using Google
# Cloud Build.
# Cloudbuild.yaml to deploy to staging
#
# Requirements:
# - Give the Google Cloud Build service account "Kubernetes Engine Developer"
# IAM role on the GCP project.
# - Set up Google Cloud Build trigger on Cloud Console.
# PREREQUISITES:
# - Cloud Build service account must have role: "Kubernetes Engine Developer"

# USAGE:
# GCP zone and GKE target cluster must be specified as substitutions
# Example invocation:
# `gcloud builds submit --config=cloudbuild.yaml --substitutions=_ZONE=us-central1-b,_CLUSTER=demo-app-staging .`

steps:
- name: gcr.io/k8s-skaffold/skaffold:v0.16.0
args: ['skaffold', 'run', '-f=skaffold.yaml']
env:
- 'CLOUDSDK_COMPUTE_ZONE=us-central1-b'
- 'CLOUDSDK_CONTAINER_CLUSTER=demo-app-staging'
timeout: 1800s
options: # Add more power, and more time, for heavy Skaffold build
machineType: 'N1_HIGHCPU_8'
- id: 'Deploy application to cluster'
name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0'
entrypoint: 'bash'
args:
- '-c'
- >
gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER;
skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID;
# Add more power, and more time, for heavy Skaffold build
timeout: '3600s'
options:
machineType: 'N1_HIGHCPU_8'
2 changes: 1 addition & 1 deletion kubernetes-manifests/adservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/adservice
image: adservice
ports:
- containerPort: 9555
env:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/cartservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/cartservice
image: cartservice
ports:
- containerPort: 7070
env:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/checkoutservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
spec:
containers:
- name: server
image: gcr.io/microservices-demo-app/checkoutservice
image: checkoutservice
ports:
- containerPort: 5050
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/currencyservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/currencyservice
image: currencyservice
ports:
- name: grpc
containerPort: 7000
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/emailservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/emailservice
image: emailservice
ports:
- containerPort: 8080
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
spec:
containers:
- name: server
image: gcr.io/microservices-demo-app/frontend
image: frontend
ports:
- containerPort: 8080
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/loadgenerator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
value: "frontend:80"
containers:
- name: main
image: gcr.io/microservices-demo-app/loadgenerator
image: loadgenerator
env:
- name: FRONTEND_ADDR
value: "frontend:80"
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/paymentservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/paymentservice
image: paymentservice
ports:
- containerPort: 50051
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/productcatalogservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/productcatalogservice
image: productcatalogservice
ports:
- containerPort: 3550
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/recommendationservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: gcr.io/microservices-demo-app/recommendationservice
image: recommendationservice
ports:
- containerPort: 8080
readinessProbe:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-manifests/shippingservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
spec:
containers:
- name: server
image: gcr.io/microservices-demo-app/shippingservice
image: shippingservice
ports:
- containerPort: 50051
readinessProbe:
Expand Down
26 changes: 15 additions & 11 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ apiVersion: skaffold/v1alpha5
kind: Config
build:
artifacts:
- image: gcr.io/microservices-demo-app/emailservice
# image tags are relative; to specify an image repo (e.g. GCR), you
# must provide a "default repo" using one of the methods described
# here:
# https://github.com/GoogleContainerTools/skaffold/blob/master/docs/concepts.adoc#2-push
- image: emailservice
context: src/emailservice
- image: gcr.io/microservices-demo-app/productcatalogservice
- image: productcatalogservice
context: src/productcatalogservice
- image: gcr.io/microservices-demo-app/recommendationservice
- image: recommendationservice
context: src/recommendationservice
- image: gcr.io/microservices-demo-app/shippingservice
- image: shippingservice
context: src/shippingservice
- image: gcr.io/microservices-demo-app/checkoutservice
- image: checkoutservice
context: src/checkoutservice
- image: gcr.io/microservices-demo-app/paymentservice
- image: paymentservice
context: src/paymentservice
- image: gcr.io/microservices-demo-app/currencyservice
- image: currencyservice
context: src/currencyservice
- image: gcr.io/microservices-demo-app/cartservice
- image: cartservice
context: src/cartservice
- image: gcr.io/microservices-demo-app/frontend
- image: frontend
context: src/frontend
- image: gcr.io/microservices-demo-app/loadgenerator
- image: loadgenerator
context: src/loadgenerator
- image: gcr.io/microservices-demo-app/adservice
- image: adservice
context: src/adservice
tagPolicy:
gitCommit: {}
Expand Down

0 comments on commit 8dabe7f

Please sign in to comment.