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.
- Forked reposity
- Codeching - Dockerizing a React application with Node.js Postgres and NginX - dev and prod - step by step
- Codeching - Kubernetes Multi Container Deployment | React | Node.js | Postgres | Ingress Nginx | step by step
- cluster with kubectl
- docker cli ($ curl -sSL https://get.docker.com | sh -s -- --version )
Setup the client and server by installing the dependancies for each.
npm install
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.
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.
Ensure you set group
, project
and image
variables
Locally on docker desktop
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
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
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
Ensure you set group
and project
variables
Locally on docker desktop
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
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
Ensure docker desktop is running, then:
Log in to your Docker Hub account using the docker command-line tool:
docker login registry.gitlab.com
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
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
Ensure you update all project/group/
instances and secret-registry.yml
!
- Create gitlab deploy access token
- Create
k8s/secret-registry.yml
ORkubectl 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
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
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
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