- 1. Start the app
- 2. Microservices
- 3. Full duplex asynchronous exchange via gRPC
- 4. Data consistency / distributed transaction
- 5. Continuous Integration with Github Actions
- 6. Kubernetes
- 7. Service mesh
- 8. Composition of services via GraphQL
- 9. Delete resources and stop the cluster
Start Docker
minikube start --cpus=2 --memory=5000 --driver=docker
Set the Kubernetes config
kubectl apply -f configmap.yaml
Set the Kubernetes secret
kubectl apply -f secret.yaml
Launch the Kubernetes deployment and service for PostgreSQL, and the Ingress gataway:
kubectl apply -f infrastructure.yaml
kubectl apply -f microservices.yaml
kubectl -n istio-system port-forward deployment/istio-ingressgateway 31380:8080
Get the list of cars to be rented:
http://localhost:31380/carservice/cars
Rent 2 cars:
curl --header "Content-Type: application/json" --request POST --data '{"customerId":1,"numberOfCars":2}' http://localhost:31380/carservice/cars
https://github.com/charroux/servicemesh/tree/main/carservice/src/main/java/com/charroux/carservice
https://github.com/charroux/servicemesh/blob/main/carservice/src/main/proto/carservice.proto
kubectl get pods
kubectl get services
https://github.com/charroux/servicemesh/blob/main/infrastructure.yaml
Enter inside the Docker containers:
kubectl exec -it [pod name] -- /bin/sh
ls
You should view the java jar file.
exit
Use Minikube to reach the carservice:
minikube service carservice --url
http://127.0.0.1:[port]/cars
How many instance are actually running:
kubectl get pods
kubectl get deployments
Start a second instance:
kubectl scale --replicas=2 deployment/[deployment name]
kubectl get pods
kubectl delete pods [pod name]
A probe is a mechanism used to determine the health of an application running in a container. Kubernetes uses probes to know when a container will be restarted, ready, and started.
Checks whether the application running inside the container is still alive and functioning properly. If the liveness probe fails, Kubernetes considers the container to be in a failed state and restarts it.
Determines whether the application inside the container is ready to accept traffic or requests. When a readiness probe fails, Kubernetes stops sending traffic to the container until it passes the probe. This is useful during application startup or when the application needs some time to initialize before serving traffic.
Health probes must be enabled by the app. See
management.health.probes.enabled=true
Actuator must be added as library. See
implementation 'org.springframework.boot:spring-boot-starter-actuator'
In https://github.com/charroux/servicemesh/blob/main/carservice/build.gradle
Liveness and Readiness must be configured by kubernetes. See
livenessProbe:
initialDelaySeconds: 180
httpGet:
path: /actuator/health
port: 8080
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
In https://github.com/charroux/servicemesh/blob/main/microservices.yaml
On the services are launched, they display the probes at (throw the gateway): http://localhost:31380/carservice/actuator/health
GitHub Actions allows to automate, customize, and execute development workflows right in a repository.
https://github.com/charroux/servicemesh/blob/main/.github/workflows/actions.yml
Kubernetes configuration to test a service in isolation: https://github.com/charroux/servicemesh/blob/main/deploymentaction.yaml
In memory database for unit testing in order to test a service in isolation: https://github.com/charroux/servicemesh/blob/main/carservice/src/test/resources/application.properties
Entities test: https://github.com/charroux/servicemesh/blob/main/carservice/src/test/java/com/charroux/carservice/entity/CarRepositoryTests.java
Use of mocks to test service in isolation: https://github.com/charroux/servicemesh/blob/main/carservice/src/test/java/com/charroux/carservice/service/RentalServiceTests.java
Microservice tests: https://github.com/charroux/servicemesh/blob/main/carservice/src/test/java/com/charroux/carservice/web/CarRentalRestServiceTests.java
Check an existing workflow: https://github.com/charroux/servicemesh/actions
Create a new branch:
git branch newcarservice
Move to the new branch:
git checkout newcarservice
Update the code and commit changes:
git commit -a -m "newcarservice"
Push the changes to GitHub:
git push -u origin newcarservice
Create a Pull request on GitHub and follow the workflow.
Delete the branch:
git checkout main
git branch -D newcarservice
git push origin --delete newcarservice
kubectl apply -f infrastructure.yaml
https://github.com/charroux/servicemesh/blob/main/infrastructure.yaml
kubectl apply -f microservices.yaml
https://github.com/charroux/servicemesh/blob/main/microservices.yaml
./ingress-forward.sh
Ask carservice the list of cars:
http://localhost:31380/carservice/cars
Adding a circuit breaker to carservice:
kubectl apply -f circuit-breaker.yaml
Test the circuit breaker: http://localhost:31380/carservice/cars
Disable the circuit breaker using:
kubectl delete -f circuit-breaker.yaml
Kiali is a console for Istio service mesh.
kubectl -n istio-system port-forward deployment/kiali 20001:20001
Launch the console: http://localhost:20001/
Active again carservice:
http://localhost:31380/carservice/cars
Then inspect the cluster in Kiali.
kubectl -n istio-system port-forward deployment/grafana 3000:3000
kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=jaeger -o jsonpath='{.items[0].metadata.name}') 16686:16686
Launch the console: http://localhost:16686/
Server side coding: https://github.com/charroux/servicemesh/blob/main/rentalservice/src/main/java/com/charroux/rentalservice/agreements/RentalController.java
kubectl delete -f infrastructure.yaml
kubectl delete -f microservices.yaml
minikube stop
https://www.docker.com/get-started/
https://minikube.sigs.k8s.io/docs/start/
Then start the Kubernetes cluster:
minikube start --cpus=2 --memory=5000 --driver=docker
https://istio.io/latest/docs/setup/getting-started/
cd istio-1.17.0
export PATH=$PWD/bin:$PATH
istioctl install --set profile=demo -y
cd ..
Enable auto-injection of the Istio side-cars when the pods are started:
kubectl label namespace default istio-injection=enabled
Install the Istio addons (Kiali, Prometheus, Jaeger, Grafana):
kubectl apply -f samples/addons
Enable auto-injection of the Istio side-cars when the pods are started:
kubectl label namespace default istio-injection=enabled
Configure Docker so that it uses the Kubernetes cluster:
minikube docker-env
eval $(minikube -p minikube docker-env)
eval $(minikube docker-env)
Dockers images have been alreaddy build. You can find those images in the Docker hub :
https://hub.docker.com/search?q=charroux
So you can skip the next steps.
Build the postgres image:
docker build --tag=charroux/postgres:1 postgres
docker push charroux/postgres:1
Build the carservice app:
cd carservice
./gradlew build
cd ..
docker build --tag=charroux/carservice:1 carservice
docker push charroux/carservice:1
Build the carstat app:
cd carstat
./gradlew build
cd ..
docker build --tag=charroux/carstat:1 carstat
docker push charroux/carstat:1
Build the customer app:
cd customer
./gradlew build
cd ..
docker build --tag=charroux/customer:1 customer
docker push charroux/customer:1
Build the graphQL app:
cd rentalservice
./gradlew build
cd ..
docker build --tag=charroux/rentalservice:1 rentalservice
docker push charroux/rentalservice:1
Build the React app:
docker build --tag=charroux/carental:1 carental
docker push charroux/carental:1













