Awwvision is a Kubernetes and Cloud Vision API sample that uses the Vision API to classify (label) images from Reddit's /r/aww subreddit, and display the labelled results in a web app.
Awwvision has three components:
- A simple Redis instance.
- A webapp that displays the labels and associated images.
- A worker that handles scraping Reddit for images and classifying them using the Vision API. Cloud Pub/Sub is used to coordinate tasks between multiple worker instances.
-
Create a project in the Google Cloud Platform Console.
-
Enable billing for your project.
-
Enable the Vision and Pub/Sub APIs. See the "Getting Started" page in the Vision API documentation for more information on using the Vision API.
-
Install the Google Cloud SDK:
$ curl https://sdk.cloud.google.com | bash $ gcloud init
-
Install and start up Docker.
If you like, you can alternately run this tutorial from your project's Cloud Shell. In that case, you don't need to do steps 4 and 5.
This example uses Container Engine to set up the Kubernetes cluster.
-
Create a cluster using
gcloud
. You can specify as many nodes as you want, but you need at least one. Thecloud-platform
scope is used to allow access to the Pub/Sub and Vision APIs. First set your zone, e.g.:gcloud config set compute/zone us-central1-f
Then start up the cluster:
gcloud container clusters create awwvision \ --num-nodes 2 \ --scopes cloud-platform
-
Set up the
kubectl
command-line tool to use the container's credentials.gcloud container clusters get-credentials awwvision
-
Verify that everything is working:
kubectl cluster-info
From the awwvision
directory, use make all
to build and deploy everything.
Make sure Docker is running first.
make all
As part of the process, a Docker image will be built and uploaded to the
GCR private container
registry. In addition, .yaml
files will be generated from templates— filled in
with information specific to your project— and used to deploy the 'redis',
'webapp', and 'worker' Kubernetes resources for the example.
After you've deployed, check that the Kubernetes resources are up and running. First, list the pods. You should see something like the following, though your pod names will be different.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
awwvision-webapp-vwmr1 1/1 Running 0 1m
awwvision-worker-oz6xn 1/1 Running 0 1m
awwvision-worker-qc0b0 1/1 Running 0 1m
awwvision-worker-xpe53 1/1 Running 0 1m
redis-master-rpap8 1/1 Running 0 2m
List the deployments. You can see the number of replicas specified for each, and the images used.
$ kubectl get deployments -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
awwvision-webapp 1 1 1 1 1m awwvision-webapp gcr.io/your-project/awwvision-webapp app=awwvision,role=frontend
awwvision-worker 3 3 3 3 1m awwvision-worker gcr.io/your-project/awwvision-worker app=awwvision,role=worker
redis-master 1 1 1 1 1m redis-master redis app=redis,role=master
Once deployed, get the external IP address of the webapp service. It may take a few minutes for the assigned external IP to be listed in the output. After a short wait, you should see something like the following, though your IPs will be different.
$ kubectl get svc awwvision-webapp
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
awwvision-webapp 10.163.250.49 23.236.61.91 80/TCP app=awwvision,role=frontend 13m
Visit the external IP of the awwvision-webapp
service to open the webapp in
your browser, and click the Start the Crawler
button.
Next, click go back
, and you should start to see images from the
/r/aww subreddit classified by the labels provided
by the Vision API. You will see some of the images classified multiple times, where multiple
labels are detected for them.
(You can reload in a bit, in case you brought up the page before the crawler was
finished).
To delete your Kubernetes pods, replication controllers, and services, and to
remove your auto-generated .yaml
files, do:
make delete
Note: this won't delete your Container Engine cluster itself. If you are no longer using the cluster, you may want to take it down. You can do this through the Google Cloud Platform Console.