This code integrates with Google Cloud by:
- providing a logger based on bunyan that outputs json formatted logs in a format parsed by Google's log ingestion service
- Providing
/ready
and/health
endpoints that Google Cloud uses to determine if a service is alive and healthy. See./lib/health_monitor.js
- Providing a class that publishes messages as text to Google PubSub
system-alerts
topic. These are then forwarded to to the user by other microservices.
- Search and replace in the source code for
my-service-name
and replace it with a slug for your service. - Search and replace in the source code for
my-google-project
and replace it with the ID of your Google project.
First run ./setup-gcloud.sh
which creates the service account and
grants basic permissions.
Note: TODO: this uses legacy permissions on Google Cloud, this should be hardened up to use role based permissions
You need to create the pubsub topic. Look up the directory tree for the pub-sub/
dir which has batch scripts for this. Something like:
# gcloud pubsub topics create system-alerts
First set the namespace in the env. Note this needs to match everywhere, including GitLab's auto deployment setup.
export KUBERNETES_NAMESPACE=my-service-name
Upload the Google service account credentials to GKE with:
kubectl create namespace $KUBERNETES_NAMESPACE
kubectl create secret generic my-service-name-service-account \
--namespace=$KUBERNETES_NAMESPACE --from-file=credentials.json=credentials.json
Upload any credentials with:
# replace ... with the actual values
PUBLIC_API_KEY= ...
SECRET_PRIVATE_KEY= ...
kubectl create secret generic tr-binance-credentials \
--namespace=$KUBERNETES_NAMESPACE \
--from-literal=PUBLIC_API_KEY=$PUBLIC_API_KEY \
--from-literal=SECRET_PRIVATE_KEY=$SECRET_PRIVATE_KEY
Note you must set the namespace to the same value for GitLab and the kubernetes secrets or the containers will get stuck in creation because they can't see their secrets.
To get the token:
kubectl describe secret gitlab-token-abcde
To get the certificate:
.. hmm maybe just copy it from an existing job