Enable the PubSub, Stackdriver, and Kubernetes Engine APIs in the Cloud Console. You will need to enable Stackdriver premium for use of custom metrics.
Export the name of your project and zone to the shell environment
export PROJECT_ID=[YOUR PROJECT ID]
gcloud config set project $PROJECT_ID
ZONE=us-west1-a
gcloud config set compute/zone $ZONE
Create a service account in the console and download the key json file into the directory that you run these commands from. Assign the service account role Project > Owner when you create it.
export GOOGLE_APPLICATION_CREDENTIALS=???.json
To create the custom metrics build and run the program
docker build -f Dockerfile-setup -t monitoring_setup .
docker run -it --env PROJECT_ID=$PROJECT_ID \
--env GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS \
monitoring_setup
Define the custom metrics:
python setup_sd.py
Build and deploy the sender in a container locally:
docker build -f Dockerfile-sender -t pubsubsender .
docker run -it --env PROJECT_ID=$PROJECT_ID \
--env GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS \
pubsubsender
Uploading to the Google Container Repository
gcloud auth configure-docker
TAG=v1
docker tag pubsubsender gcr.io/$PROJECT_ID/pubsubsender:$TAG
docker push gcr.io/$PROJECT_ID/pubsubsender:$TAG
Start up a GKE cluster
gcloud components install kubectl
CLUSTER_NAME=monitoring-$ZONE
gcloud container clusters create $CLUSTER_NAME --zone $ZONE --num-nodes 2
gcloud container clusters get-credentials $CLUSTER_NAME
Deploy the sender to the cluster:
kubectl run pubsubsender --image gcr.io/$PROJECT_ID/pubsubsender:$TAG \
--env="PROJECT_ID=$PROJECT_ID" \
--env "GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS"
Building and deploying the receiver the container locally
docker build -f Dockerfile-receiver -t pubsubreceiver .
docker run -it --env PROJECT_ID=$PROJECT_ID \
--env GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS \
pubsubreceiver
Deploy to K8s
docker tag pubsubreceiver gcr.io/$PROJECT_ID/pubsubreceiver:$TAG
docker push gcr.io/$PROJECT_ID/pubsubreceiver:$TAG
kubectl run pubsubreceiver --image gcr.io/$PROJECT_ID/pubsubreceiver:$TAG \
--env="PROJECT_ID=$PROJECT_ID" \
--env "GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS"
The sender creates a PubSub topic called 'e2eprobe'. To verify that the sender successfully started up, you can check this with the gcloud command:
gcloud beta pubsub topics list
To check on the receiver, you can list the subscriptions with the command
gcloud beta pubsub topics list-subscriptions e2eprobe
To check that the probes are running in Kubernetes, use the command
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
pubsubreceiver-66f7bf69c7-69d8b 1/1 Running 0 2m
pubsubsender-7d7c8fc757-qnfs9 1/1 Running 0 20m
If you look in the GCP Log Console, you should see log entries from the Python code in pubsubsender.py and pubsubreceiver.py.
Apache 2.0 Copyright 2018 Google. All rights reserved.