Giter VIP home page Giter VIP logo

0mq-k8s-multi-language-example's Introduction

0mq k8s example

Example of using 0mq inside K8S environment with multi-language communication.

Diagram

Golang <----- 0mq -----> Node.js (Web Server) (bridge) (Database Engine)

Prerequisted

  • Docker
  • k8s

How to

  1. Install Ingress NGINX (Community Edition) ingress-nginx if you haven't.

  2. Build Go web server in fiber

cd fiber
docker build -t docker -t fiber-prisma-main .
  1. Build Node.js Database Engine in database-engine
cd database-engine
docker build -t fiber-prisma-db-engine .
  1. Move deployment.example.yaml to deployment.yaml and append DATABASE_URL environment variable.
# deployment.yaml
31 env:
32  - name: DATABASE_URL
33    value: <Postgres Connection URL>
  1. Port forward nginx Ingress if you haven't. (I'm going to forward to localhost:8080)
# Find the ingress name
kubectl get pod | grep ingress-nginx-controller-

# Copy ingress name from above to here
kubectl port-forward ingress-nginx-controller-[hash]-[hash] 8080:80
  1. Run service
# At project root
./up.sh
  1. To stop service, simply run
./down.sh

Automated Deploy to Google Cloud

Even with automation, manual setup is still required and is complicated. So I think I will implement basic deployment which can be automated.

Note: The template is not the best practice, you can improve it much better but I the idea is to prove that this work and I want to reduce any complexity where possible as state above.
Note: For some reason, you might have to run deployment command 2-3 times to make it complete for some reason.

What this do

1 Command automate deployment to GCP. Including:

  • Create VPC Network, subnetwork and private network service for internal service communication.
  • PostgreSQL with users.
  • Create Autopilot Kubernetes Engine and deploys the images.
    • Deploy pod with replicas and load balancer service.
    • Install nginx helm chart and use ingress to direct traffic.

Prerequisted

Pre deployment

  1. Push docker image of fiber and database-engine to any registry.
  • Make sure Google Cloud can access the registry.
  • The easiest way is to host it in Google Cloud Image Registry, so the image is private, GCP can access it.
  1. Rename config.ts to .ts and fill the form.
  • Rename src/config.example.ts to config.ts.
  • Rename src/config.example.ts to config.ts.
  1. Config deployment zone and project id
pulumi config set gcp:project <Your GCP project ID>
pulumi config set gcp:zone asia-southeast1-a

Deployment

Run:

cd infra && yarn up

The deployment will take a couple minute before complete. Once complete, you will be able to access the deployment.

Post deployment

If you access any endpoint the use database-engine, you will notice that it will return success: false response. Because the automation doesn't create Database schema, you have to created one yourself.

  1. Go to your SQL deployment on GCP.
  • Go the GCP console
  • Select SQL from sidebar
  • Select <your deployed database>
  1. Grab the IP address into local database-engine/.env.
DATABASE_URL="postgresql://<username>:<password>@<Cloud SQL IP Adress>/prismaQueue?schema=queue"
  1. Enable Cloud SQL local machine access.
  • Select Edit in GCP SQL console page
  • Scroll down and expand Connections
  • Check Enable Public IP if not enabled
  • Under Authorized Networks, click Add Network
  • Name your network and add your current IP Address (Check your ip here)
  1. Migrate schema and table from your Prisma defination to Cloud SQL.
  • Go to database-engine
cd database-engine
  • Run npx prisma migrate <stack name> (This repo's default is dev)
npx prisma migrate <stack name>

After following Post Deployment process, the Database Engine should be able to query and everything should be working just fine.

Note

If you want Ingress IP, you can find one in GCP Console.

Enterprise

0mq-k8s-multi-language-example's People

Contributors

saltyaom avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.