Skip to content

OwnInTheFoam/multicontainerapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi Container Application

THIS REPOSITORY IS FORKED FROM: codeching

It contains React client, Node.js backend, PostgreSQL and Nginx

You can run it in development mode: docker-compose up --build It contains Dockerfiles for client, server which you should push to your docker hub to be able to pull them down when in next tutorial we will use them in Kubernetes.

Resources

Requirements

Startup

Setup the client and server by installing the dependancies for each.

npm install

Testing

Test the server in development with

npm run dev

Then open browser and check for HI output

curl localhost:5000

Test the client in development with

npm run start

and open browser to

curl localhost:3000

Viewing the network developer tools tab, send a value and notice a http request is sent.

Create dockerfile for dev and prod

These (Dockerfile, Dockerfile.dev) should inherit from a base image like node, nginx, postgres etc. The docker hub for each base image will have documentation for each. A docker-compose.yml file to run the server, client and nginx together in locally environment.

Testing - dev

Ensure you set group, project and image variables Locally on docker desktop

Client

Create Dockerfile.dev in client folder.

Test your docker file and provide a image tag

docker build -f Dockerfile.dev -t registry.gitlab.com/project/group/client-dev:latest .

Run your docker image

docker run -it -p 4002:3000 registry.gitlab.com/project/group/client-dev:latest

Open browser

localhost:4002

Server

Create Dockerfile.dev in server folder

Test your docker file and provide a image tag

docker build -f Dockerfile.dev -t registry.gitlab.com/project/group/server-dev:latest .

Run your docker image

docker run -it -p 4003:5000 registry.gitlab.com/project/group/server-dev:latest

Open browser

localhost:4003

Docker Compose

Create docker compose to run everything together in local docker desktop Use nginx has a ingress. Create default.conf in nginx folder Create Dockerfile.dev in nginx folder

Test all deployments:

docker compose up --build
localhost:3050

Testing - prod

Ensure you set group and project variables Locally on docker desktop

Client

Create Dockerfile in client folder.

Test your docker file and provide a image tag

docker build -t registry.gitlab.com/project/group/client:latest .

Run your docker image

docker run -it -p 3000:3000 registry.gitlab.com/project/group/client:latest

Open browser

localhost:3000

Server

Create Dockerfile in server folder

Test your docker file and provide a image tag

docker build -t registry.gitlab.com/project/group/server:latest .

Run your docker image

docker run -it -p 4002:5000 registry.gitlab.com/project/group/server:latest

Open browser

localhost:4002

Upload to docker registry

Ensure docker desktop is running, then:

Log in to your Docker Hub account using the docker command-line tool:

docker login registry.gitlab.com

Client

Build docker image and provide a tag

cd client
docker build -t registry.gitlab.com/project/group/client:latest .

Push to your container registry

docker push registry.gitlab.com/project/group/client:latest

Server

Build docker image and provide a tag

cd server
docker build -t registry.gitlab.com/project/group/server:latest .

Push to your container registry

docker push registry.gitlab.com/project/group/server:latest

Test deployment to kubernetes

Create deployment token

Ensure you update all project/group/ instances and secret-registry.yml!

  • Create gitlab deploy access token
  • Create k8s/secret-registry.yml OR kubectl create secret docker-registry regcred --docker-server=registry.gitlab.com --docker-username=<your-name> --docker-password=<token>
  • Apply with k8s/secret-registry.yml
  • Test with kubectl get secret regcred -o yaml
  • Create k8s/client-deployment.yml
  • Apply with kubectl apply -f k8s/client-deployment.yml
  • Add to deployment kubectl edit deployment client-deployment and add:
spec:
  template:
    spec:
      imagePullSecrets:
      - name: regcred
  • Test with kubectl get pods
  • Create k8s/client-cluster-ip-service.yml
  • Apply with kubectl apply -f k8s/client-cluster-ip-service.yml
  • Test with kubectl get services
  • Create k8s/database-persistent-volume-claim.yml
  • Apply with kubectl apply -f k8s/database-persistent-volume-claim.yml
  • Test with kubectl get pvc,pv
  • Create secret for postgres: kubectl create secret generic pgpassword --from-literal PGPASSWORD=yourPassword
  • Test with, kubectl get secrets
  • Create k8s/postgres-deployment.yml
  • Apply with kubectl apply -f k8s/postgres-deployment.yml
  • Test with kubectl get pods
  • Create k8s/postgres-cluster-ip-service.yml
  • Apply with kubectl apply -f k8s/postgres-cluster-ip-service.yml
  • Test with kubectl get services
  • Create k8s/server-deployment.yml
  • Apply with kubectl apply -f k8s/server-deployment.yml
  • Add to deployment kubectl edit deployment server-deployment and add:
spec:
  template:
    spec:
      imagePullSecrets:
      - name: regcred
  • Test with kubectl get pods
  • Create k8s/server-cluster-ip-service.yml
  • Apply with kubectl apply -f k8s/server-cluster-ip-service.yml
  • Test with kubectl get services
  • Install nginx ingress controller with kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml
  • Test with kubectl get all -n ingress-nginx
  • Create k8s/ingress-service.yml
  • Apply with kubectl apply -f k8s/ingress-service.yml
  • Test with kubectl get Ingress
  • Test application with browser curl localhost
  • Delete the application with kubectl delete -f k8s

Pull images from container registry

Ensure docker desktop is running with kubernetes enabled in settings. Log in to your Docker Hub account using the docker command-line tool:

docker login registry.gitlab.com

Ensure you have access to your cluster with kubectl

kubectl version

Client

Pull the image from Docker Hub to your local machine:

docker pull registry.gitlab.com/project/group/client:latest

Alternative use kubectl to retrieve the image. A deployment will be created without any pods.

docker run -it -p 4002:3000 registry.gitlab.com/project/group/client:latest

Server

Pull the image from Docker Hub to your local machine:

docker pull registry.gitlab.com/project/group/server:latest

Alternative use kubectl to retrieve the image. A deployment will be created without any pods.

docker run -it -p 4003:5000 registry.gitlab.com/project/group/server:latest

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published