Skip to content

ruslan-byondxr/node-ms-monorepo

Repository files navigation

Running NX monorepo microservices locally with Docker, Kubernetes and ArgoCD

Install the following

  • NX
  • docker
  • kubectl
  • minikube
  • virtualbox

Install on mac

npm install -g nx
brew update
brew install kubectl
brew cask install docker
brew cask install minikube
brew cask install virtualbox

Install on Linux (Debian)

install nx npm install -g nx

To install docker, follow the instructions here: https://docs.docker.com/engine/install/ubuntu/

Install docker-compose

sudo apt install docker-compose

Docker Desktop works on Mac and Windows only. A proper alternative is dockstation app: https://dockstation.io/

To install kubectl follow the instructions here: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/

To install minikube follow the instructions here: https://minikube.sigs.k8s.io/docs/start/

To install virtualbox follow the instructions here: https://www.virtualbox.org/wiki/Linux_Downloads


Check if installed properly

kubectl version --client
docker --version
docker-compose --version
docker-machine --version
minikube version

Run docker desktop

Open docker desktop standalone app


Start the kubernetes cluster with minikube (minikube is local Kubernetes)

minikube start

Check if minikube node is ready

kubectl get nodes

You should see something like that

NAME       STATUS    ROLES     AGE       VERSION
minikube   Ready     master    40s        v1.14.0

Build docker images of our microservices

You can run the following commands with you NX IDE extension (vscode or intellij)

nx run svc-cart:dockerBuild

nx run svc-products:dockerBuild

nx run svc-user:dockerBuild

Check whether docker images has been created

docker images --format "table {{.ID}}\t{{.Tag}}\t{{.Repository}}"

You should see something like that

IMAGE ID       TAG       REPOSITORY
9d280d1feec7   latest    svc-user
01a97cac7c74   latest    svc-products
73de4fa41b44   latest    svc-cart
8768eddc4356   v0.0.25   gcr.io/k8s-minikube/kicbase

Deploy to kubernetes - Run NX commands

You can run the following commands with your IDE's NX extension (vscode or intellij)

nx run svc-cart:kubernetesDeploy 

nx run svc-products:kubernetesDeploy 

nx run svc-user:kubernetesDeploy 

Check if pods are running

kubectl get pods
NAME                           READY   STATUS    RESTARTS   AGE
svc-cart-8b6dfcfb4-tzccw       1/1     Running   0          39m
svc-products-5b9d7478b-5r5zq   1/1     Running   0          14m
svc-user-5c59cb6776-gdt2h      1/1     Running   0          5m54s

Check if services are running

kubectl get services
kubernetes             ClusterIP   10.96.0.1        <none>        443/TCP        18h
svc-cart-service       NodePort    10.99.159.203    <none>        80:32180/TCP   25m
svc-products-service   NodePort    10.105.26.125    <none>        80:30915/TCP   16m
svc-user-service       NodePort    10.102.239.226   <none>        80:32085/TCP   8m13s


Access services outside the node (minikube is able to create tunnel )

minikube service svc-cart-service --url

You will see something like that:
πŸƒ  Starting tunnel for service svc-cart-service.
|-----------|------------------|-------------|------------------------|
| NAMESPACE |       NAME       | TARGET PORT |          URL           |
|-----------|------------------|-------------|------------------------|
| default   | svc-cart-service |             | http://127.0.0.1:53401 |
|-----------|------------------|-------------|------------------------|
http://127.0.0.1:53401
❗  Because you are using a Docker driver on darwin, the terminal needs to be open to run it.

Open up http://127.0.0.1:53401/api in your browser

You should see:

{"message":"Welcome to svc-cart!"}

Open another terminal instance and run another service

==============================================

Monitor services with minikube dashboard

minikube dashboard

Screen Shot 2021-08-25 at 19 59 01



Deploy services locally with ArgoCD

Install Argo CD with kubectl

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Download Argo CD CLI

Mac:

brew install argocd

Linux and Windows:
https://argoproj.github.io/argo-cd/cli_installation/

Expose ArgoCD API Server

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

Config ArgoCD CLI with username admin and password admin

kubectl -n argocd patch secret argocd-secret \
    -p '{"stringData": {"admin.password": "$2a$10$mivhwttXM0U5eBrZGtAG8.VSRL1l9cZNAmaSaqotIzXRBRwID1NT.",
        "admin.passwordMtime": "'$(date +%FT%T)'"
    }}'
argocd login localhost:8080 --username admin --password admin --insecure

Expose ArgoCD UI

kubectl port-forward svc/argocd-server -n argocd 8080:443 

Finally, open ArgoCD UI in your browser

https://localhost:8080/

Screen Shot 2021-08-25 at 19 59 01

Login

user: admin

password: admin

Screen Shot 2021-08-25 at 19 59 01

Create new App

Click on NEW APP button

Fill out the fields

Application Name: cart-service

Project: default

Repository URL: https://github.com/ruslan-byondxr/node-ms-deployment

We are going to use separate git repo for our deployment config files. It's best practice in the industry.

The use of a different Git repository to hold your kubernetes manifests (separate from your application source code), is highly recommended. See best practices for further rationale. https://argoproj.github.io/argo-cd/user-guide/best_practices/

Path: svc-cart

Cluster URL: https://kubernetes.default.svc

Namespace: microservices

Click on Create

You should see The service: Screen Shot 2021-08-29 at 12 17 21

πŸ”₯ Click on SYNC

Access microservice locally

kubectl port-forward -n microservices svc/svc-cart 7000:8080

Open up your browser: http://localhost:7000/api

Now you should see a json response:

{"message":"Welcome to svc-cart!"}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published