Skip to content

Latest commit

 

History

History
118 lines (90 loc) · 2.44 KB

README.md

File metadata and controls

118 lines (90 loc) · 2.44 KB

API

Deploying NGX API

Build

# build app docker image
docker build --tag=ngxapi -f .deploy/api/Dockerfile . 

Run

docker-compose up api
# docker run -it --env TYPEORM_HOST=postgres -p 3000:3000  ngxapi
# to see ditectory content:
docker-compose exec api ./node
docker-compose exec api ./node -e 'console.log(__dirname);'
docker-compose exec api ./node -e 'const fs = require('fs'); fs.readdirSync('.').forEach(file => { console.log(file);})

Test

The app will be available at http://localhost:3000

# test
curl -v -X GET \
  http://localhost:3000/api \
| jq .

Deploy

Docker Push

# login to hub.docker.com to push docker image
docker login

# tag
docker tag ngxapi xmlking/ngxapi:1.2.0-SNAPSHOT
docker tag xmlking/ngxapi:1.2.0-SNAPSHOT  xmlking/ngxapi:latest

# push
docker push xmlking/ngxapi:1.2.0-SNAPSHOT
docker push xmlking/ngxapi:latest

OpenShift Deployment

Deploy ngxapi to OpenShift

# login
oc login <my OpenShift URL>
# oc login https://console.starter-us-east-1.openshift.com
oc project ngx
cd .deploy/api/openshift

# create app (first time deployment)
oc new-app -f api.tmpl.yml -p APPNAME=ngxapi -n ngx

# follow next steps if you want completely delete and redeploy.
# delete only deploymentConfig
oc delete all -l app=ngxapi -n ngx

# delete fully
oc delete all,configmap,secret -l app=ngxapi -n ngx

# redeploy
# From OpenShift Console UI
Applications > Deployments > ngxapi > Deploy

Kubernetes Deployment

assume you already setup ngx context

make sure Env, docker image Version are correct in 04-ngxapi-deployment.yaml

cd .deploy/api/manual

## view all preset contexts
kubectl config get-contexts
# switch to `ngx` contexts
kubectl config use-context ngx

## create (first time deployment)
kubectl create -f ./api.yml
kubectl describe deployment api

## checking
# see logs
kubectl logs -f my-pod
# Once you’ve created a Service of type NodePort, you can use this command to find the NodePort
kubectl get service api --watch
# to get <NODE> names 
kubectl get pod  -o wide

## delete
kubectl delete -f ./api.yml

## redeploy (new image)
update tag in api.yml and delete and create again.

Kubernetes Commands

kubectl get deployment -o wide
kubectl get pods -o wide
kubectl get service -o wide

kubectl exec -it my-pod  -- /bin/bash
kubectl logs -f my-pod
kubectl logs my-pod --previous 
kubectl logs my-pod -c my-container