Skip to content

Instantly share code, notes, and snippets.

@JaniKibichi
Created June 29, 2021 16:16
Show Gist options
  • Save JaniKibichi/9f5c656672eff2ffddcfc309527cda36 to your computer and use it in GitHub Desktop.
Save JaniKibichi/9f5c656672eff2ffddcfc309527cda36 to your computer and use it in GitHub Desktop.
Recipe

INTRODUCTION

ABOUT BBOXX API
  • Allow users to query a shortcode and pay for their electricity meter bill
  • Allow users to query their meter balance
TECHNOLOGY
  • API : Akka
  • DB : Firestore
  • Mobile Money : Safaricom API
  • Short Code : Africa's Talking API
  • Deployed : Google Cloud Platform
CREATE GKE CLUSTER, GKE NODES + AUTOSCALER, HORIZONTAL POD AUTOSCALER
  1. gcloud init && gcloud compute machine-types list --filter="zone:(us-central1-a)"
  2. gcloud container clusters create bboxx-cluster --zone us-central1-a --num-nodes 1 --enable-autoscaling --min-nodes 1 --max-nodes 10 --machine-type=n1-standard-1
  3. gcloud container clusters get-credentials bboxx-cluster --zone us-central1-a --project vivo-ussd-november-26th-2019
  4. gcloud projects add-iam-policy-binding vivo-ussd-november-26th-2019 --member=serviceAccount:[email protected] --role=roles/container.developer
OPERATIONS

Set Up CloudBuild to: Build Image, Upload Image to GCR, Deploy Image to GKE

  1. Run sbt stage to create files to target/universal/stage/bin
  2. Generate Dockerfile using sbt docker:stage
  3. This file can be found at target/docker/stage/Dockerfile
  4. Create the CloudBuild Yaml
  5. gcloud builds submit --timeout=900S --project=vivo-ussd-november-26th-2019 --config cloudbuild.yaml
SET UP THE SERVICE
  • echo "Configure The Service"
  • kubectl apply -f deploy/service.yaml
  • kubectl get svc
CONFIGURE HORIZONTAL AUTOSCALING
  • echo "Configure Horizontal Autoscaling"
  • kubectl apply -f deploy/horizontalpodautoscaler.yaml
  • kubectl get hpa
ADD HELM
  • echo "Add Helm Nginx Repo"
  • helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
  • helm repo update
  • helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true
  • kubectl --namespace default get services -o wide -w nginx-ingress-ingress-nginx-controller
DEPLOY INGRESS
  • echo "Add Kubernetes Ingress"
  • kubectl apply -f deploy/ingress.yaml
SECURING INGRESS
  • echo "Creating Cert Manager Name Space"
  • kubectl create namespace cert-manager
  • echo "Add Jetstack Helm Chart"
  • helm repo add jetstack https://charts.jetstack.io
  • helm repo update
  • echo "Install Cert Manager into the cert-manager namespace"
  • helm install cert-manager jetstack/cert-manager --namespace cert-manager --version v1.2.0 --set installCRDs=true
CREATE ISSUER TO ISSUE LETS ENCRYPT CERTIFICATE
  • echo "Creating Production Issuer"
  • kubectl apply -f deploy/productionissuer.yaml
  • echo "Introduce Certificates to Ingress Resource"
  • kubectl apply -f deploy/ingressupdate.yaml
  • echo "Check Certificate Issuance Progress"
  • kubectl describe certificate hello-kubernetes-tls
OPTIONAL ----------------------------------------->>>
CLOUD SOURCE REPOSITORY SET UP
  1. gcloud init && git config credential.helper gcloud.sh
  2. gcloud source repos create bboxxapi
  3. gcloud source repos list
  4. git init && git remote add google https://source.developers.google.com/p/vivo-ussd-november-26th-2019/r/bboxxapi
  5. git add . && git commit -m "Update to project structure"
  6. git push --all google
CREATE GITLAB CI/CD PIPELINE TO KUBERNETES
  1. Create service account in the GCP Project with roles Viewer, Cloud Builder Editor and Storage Admin
  2. GCP IAM > Service Accounts, create JSON Key and Download.
  3. Gitlab Settings > CI/CD, Add Variable GCP_PROJECT_ID, GCP_SERVICE_KEY
SET UP GITLAB CI/CD
  1. Operations > Kubernetes
  2. Enter Kubernetes cluster name, API URL, CA Certificate
  3. Apply the service account : kubectl apply -f gitlab-admin-service-account.yaml
  4. Enter Token from : kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep gitlab | awk '{print $1}')
REFERENCES
  1. Ingress: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-on-digitalocean-kubernetes-using-helm
  2. Ingress 2: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes
  3. Dockerizing AKKA : https://medium.com/@konstantinbodnia/create-and-deploy-a-scala-http-server-to-google-kubernetes-engine-gke-36a25e395d48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment