If you want to run app locally without container (useful for development), you need
-
Have MongoDB and Redis available. Set environment variables
MONGO
andREDIS
where those servers are located. Value should be in formathttp://<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
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
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 )
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.
- 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 atscripts/redis.yaml
andscripts/mongocb-rc.yaml
.
$ 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
$ 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
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
.
Example you can find at http://104.155.93.160:8080/