- http://localhost:8765/currency-exchange/from/USD/to/INR
- http://localhost:8765/currency-conversion/from/USD/to/INR/quantity/10
- http://localhost:8765/currency-conversion-new/from/USD/to/INR/quantity/10
Since you have a pom.xml
file with the spring-boot-maven-plugin
configured:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>said160/ms-${project.artifactId}:${project.version}</name>
</image>
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
</configuration>
</plugin>
</plugins>
</build>
you can build the Docker image locally using Maven. Run the following command:
mvn clean install
This command will:
- Compile your Spring Boot application.
- Prepare the Docker image as specified in the pom.xml.
After the Maven build is successful, you can use the Maven Docker plugin to build the Docker image. Run:
mvn spring-boot:build-image
This will:
- Trigger the spring-boot-maven-plugin to build a Docker image using the configuration in your pom.xml.
- Create an image named said160/ms-${project.artifactId}:${project.version}. The artifactId and version will be replaced based on the project details (e.g., ms-currency-exchange-service and 0.0.1-SNAPSHOT).
Once the build completes, check if the Docker image was created successfully by running:
docker images
Look for an image with the name said160/ms-currency-exchange-service:0.0.1-SNAPSHOT (or the corresponding name/version).
Once the image is built locally, start your application using docker-compose:
docker-compose up
- First make sure you are logged in
docker login
- Tag the image (if needed)
docker tag said160/ms-currency-exchange-service:0.0.1-SNAPSHOT said160/ms-currency-exchange-service:0.0.1-SNAPSHOT
- Push the image to Docker Hub
docker push said160/ms-currency-exchange-service:0.0.1-SNAPSHOT
- Verify the image on Docker Hub
- Optional: Pull the image to test
docker pull said160/ms-currency-exchange-service:0.0.1-SNAPSHOT
- A Google Cloud Platform (GCP) account.
- A Kubernetes cluster created in GCP.
kubectl
andgcloud
CLI tools installed and configured.
-
Authenticate with GCP:
gcloud auth login
-
Set the active project:
gcloud config set project <your-project-id>
-
Connect to the Kubernetes cluster:
gcloud container clusters get-credentials <your-cluster-name> --zone <your-zone>
-
Create a
currency-exchange-deployment.yaml
andcurrency-exchange-service.yaml
files:apiVersion: apps/v1 kind: Deployment metadata: name: currency-exchange-service spec: replicas: 2 selector: matchLabels: app: currency-exchange template: metadata: labels: app: currency-exchange spec: containers: - name: currency-exchange image: said160/ms-currency-exchange-service:0.0.1-SNAPSHOT ports: - containerPort: 8000
apiVersion: v1 kind: Service metadata: name: currency-exchange-service spec: selector: app: currency-exchange ports: - protocol: TCP port: 8000 targetPort: 8000 type: ClusterIP
-
Similarly, create YAML files for
currency-conversion-service
,naming-registry-service
, andapi-gateway-service
, modifyingports
andimage
as required. -
For
api-gateway-service
, set the service type toLoadBalancer
:apiVersion: v1 kind: Service metadata: name: api-gateway-service spec: selector: app: api-gateway ports: - protocol: TCP port: 8765 targetPort: 8765 type: LoadBalancer
-
Deploy each service by applying the corresponding YAML files:
kubectl apply -f currency-exchange-deployment.yaml kubectl apply -f currency-conversion-deployment.yaml kubectl apply -f naming-registry-deployment.yaml kubectl apply -f api-gateway-deployment.yaml
-
Verify deployments and services:
kubectl get deployments kubectl get services
-
Identify a pod from the
currency-conversion-service
:kubectl get pods
-
Access the pod's shell:
kubectl exec -it <pod-name-of-currency-conversion-service> -- /bin/sh
-
Inside the pod, validate communication with another service:
wget -qO- http://currency-exchange-service:8000/currency-exchange/from/USD/to/EUR
-
Get the external IP of the
api-gateway-service
:kubectl get services
-
Test access to the API Gateway:
curl http://<external-ip>:8765/currency-conversion/from/USD/to/EUR/quantity/10
-
View logs for a specific pod:
kubectl logs <pod-name>
-
Scale a deployment as needed:
kubectl scale deployment currency-exchange-service --replicas=3
To delete all deployments and services:
kubectl delete -f currency-exchange-deployment.yaml
kubectl delete -f currency-conversion-deployment.yaml
kubectl delete -f naming-registry-deployment.yaml
kubectl delete -f api-gateway-deployment.yaml
You have successfully deployed and validated your microservices on Kubernetes in Google Cloud!