Skip to content

Instantly share code, notes, and snippets.

@olostan
Last active November 4, 2016 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olostan/fcc66e00f852416f6ced6ef334144aae to your computer and use it in GitHub Desktop.
Save olostan/fcc66e00f852416f6ced6ef334144aae to your computer and use it in GitHub Desktop.

Running app

Running locally without container

If you want to run app locally without container (useful for development), you need

  • Have MongoDB and Redis available. Set environment variables MONGO and REDIS where those servers are located. Value should be in format http://<db-service-host>:<db-service-port>. Example

      $ echo $MONGO
      http://192.168.99.100:32188
      $ echo $REDIS
      http://192.168.99.100:30669
    
  • Install NPM dependencies:

    $ npm install 
    
  • Create some sample users

    $ node index.js --create-users
    Creating sample users:
    User user1@test.com created (Password: '123').
    User user2@test.com created (Password: '123').
    All users created
    
  • Start server

    $ node instex.js
    Listening on 8080
    
  • Open http://localhost:8080/

Cluster Configuration

If you want to run app in cluster (local, hosted or cloud provider), you need

  • Build app's docker image
  • Create cluster (local or remote)
  • Start services in cluster

Build NodeJS container

Make sure that docker is configured (you can check by running docker ps).

Then just run:

docker build -t gcr.io/handy-zephyr-148012/4ryan:v1 .

NOTE: if you plan to store docker image in other repository, than Google Cloud, you can change tagging name. Don't forget to modify scripts/k4ryan-depl.yaml to point on correct docker file.

Then you can push built image into repository (so )

Configuring cluster to be run on local machine

To run app on local cluster, you need to have minikube installed.

First make sure that scripts are configured to use local storage by un commenting in files mongodb-rc.yaml and redis.yaml section hostPath and commenting section gcePersistentDisk or other cloud provider's sections.

NOTE: In YAML format, symbol # used for commenting the line.

Configuring for Google Cloud Platform

  • First you need to create cluster (documentation).
  • Create storage for MongoDB/Redis
$ gcloud compute disks create --size 200GB mongo-disk
$ gcloud compute disks create --size 200GB redis-disk
  • Make sure that gcePersistentDisk section is uncommented at scripts/redis.yaml and scripts/mongocb-rc.yaml.

Create Kubernetes services

$ kubectl create -f scripts/mongo-svc.yaml
$ kubectl create -f scripts/mongo-rc.yaml
$ kubectl create -f scripts/redis.yaml
$ kubectl create -f scripts/k4ryan-svc.yaml
$ kubectl create -f scripts/k4ryan-depl.yaml

To check services are running:

$ kubectl get pods
NAME                     READY     STATUS    RESTARTS   AGE
k4ryan-468502131-fwkhq   1/1       Running   0          8h
mongo-controller-rlut9   1/1       Running   0          9h
redis-vwn2a              1/1       Running   0          6h

Create sample users

$ kubectl exec k4ryan-468502131-fwkhq  node index.js -- --create-users
Creating sample users:
User user1@test.com created (Password: '123').
User user2@test.com created (Password: '123').
All users created

Get public ip

You can get public ip by

$ kubectl describe service k4ryan

Name:			k4ryan
Namespace:		default
Labels:			run=k4ryan
Selector:		run=k4ryan
Type:			LoadBalancer
IP:			10.3.242.103
LoadBalancer Ingress:	104.155.93.160
Port:			<unset>	8080/TCP
NodePort:		<unset>	31682/TCP
Endpoints:		10.0.1.11:8080
Session Affinity:	None
No events.⏎  

Public ip will be LoadBalancer Ingress.

Explample deployed on Google Cloud

Example you can find at http://104.155.93.160:8080/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment