Code Monkey home page Code Monkey logo

node-kubernetes's Introduction

Deploying a Node App to Google Cloud with Kubernetes

Want to learn how to build this?

Check out the post.

Want to use this project?

Docker

Build the images and spin up the containers:

$ docker-compose up -d --build

Run the migrations and seed the database:

$ docker-compose exec web knex migrate:latest
$ docker-compose exec web knex seed:run

Test it out at:

  1. http://localhost:3000
  2. http://localhost:3000/todos

Kubernetes

Google Cloud Platform (GCP)

Install the Google Cloud SDK, run gcloud init to configure it, and then either pick an existing GCP project or create a new project to work with.

Set the project:

$ gcloud config set project <PROJECT_ID>

Install kubectl:

$ gcloud components install kubectl

Kubernetes Cluster

Create a cluster on Kubernetes Engine:

$ gcloud container clusters create node-kubernetes \
    --num-nodes=3 --zone us-central1-a --machine-type g1-small

Connect the kubectl client to the cluster:

$ gcloud container clusters get-credentials node-kubernetes --zone us-central1-a

Docker

Build and push the image to the Container Registry:

$ gcloud auth configure-docker
$ docker build -t gcr.io/<PROJECT_ID>/node-kubernetes:v0.0.1 .
$ docker push gcr.io/<PROJECT_ID>/node-kubernetes:v0.0.1

Secrets

Create the secret object:

$ kubectl apply -f ./kubernetes/secret.yaml

Volume

Create a Persistent Disk:

$ gcloud compute disks create pg-data-disk --size 50GB --zone us-central1-a

Create the volume:

$ kubectl apply -f ./kubernetes/volume.yaml

Create the volume claim:

$ kubectl apply -f ./kubernetes/volume-claim.yaml

Postgres

Create deployment:

$ kubectl create -f ./kubernetes/postgres-deployment.yaml

Create the service:

$ kubectl create -f ./kubernetes/postgres-service.yaml

Create the database:

$ kubectl get pods
$ kubectl exec <POD_NAME> --stdin --tty -- createdb -U sample todos

Node

Update the image name kubernetes/node-deployment-updated.yaml and then create the deployment:

$ kubectl create -f ./kubernetes/node-deployment-updated.yaml

Create the service:

$ kubectl create -f ./kubernetes/node-service.yaml

Apply the migration and seed the database:

$ kubectl get pods
$ kubectl exec <POD_NAME> knex migrate:latest
$ kubectl exec <POD_NAME> knex seed:run

Grab the external IP:

$ kubectl get service node

NAME      TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
node      LoadBalancer   10.39.244.136   35.232.249.48   3000:30743/TCP   2m

Test it out:

  1. http://EXTERNAL_IP:3000
  2. http://EXTERNAL_IP:3000/todos

Remove

Remove the resources once done:

$ kubectl delete -f ./kubernetes/node-service.yaml
$ kubectl delete -f ./kubernetes/node-deployment-updated.yaml

$ kubectl delete -f ./kubernetes/secret.yaml

$ kubectl delete -f ./kubernetes/volume.yaml
$ kubectl delete -f ./kubernetes/volume-claim.yaml

$ kubectl delete -f ./kubernetes/postgres-deployment.yaml
$ kubectl delete -f ./kubernetes/postgres-service.yaml

$ gcloud container clusters delete node-kubernetes --zone us-central1-a
$ gcloud compute disks delete pg-data-disk --zone us-central1-a
$ gcloud container images delete gcr.io/<PROJECT_ID>/node-kubernetes:v0.0.1

node-kubernetes's People

Contributors

mjhea0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-kubernetes's Issues

docker-compose command fails

Step 4/8 : RUN npm install
---> Running in 30db06b6bed6
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/migrate/index.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/migrate/migrate-stub.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/migrate/migration-list-resolver.js'
npm WARN tar ENOENT: no such file or directory, lstat '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/migrate/stub'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/migrate/table-creator.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/migrate/table-resolver.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/knex-fb2d704c/src/query/builder.js'
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/nan-436ccec2/README.md'
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected]
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'node-kubernetes'
npm ERR! notarget

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-04T00_05_24_354Z-debug.log
ERROR: Service 'web' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1

How to add a domain and ssl

Thanks for the k8 setup. I was curious if there is any follow up on how to attach a dns name to the cluster(ip), and run it on ssl instead of running it on IP:Port @mjhea0

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.