This is a barebones Spring Boot project testing structural interdependencies among parent, child and sibling (Java) Maven modules, and migrating them to cloud hosting using Kubernetes.
To re-create the process:
- Clone the entire project: https://github.com/CoalChris/Spring-Boot-Maven-Test.git
- Modify the deployment.yaml, service.yaml files in "[service]/k8s" folder and "[service]/src/resources/application.properties" file to reflect desired ports and versions.
- To re-compile the code and output the required JAR library, run Maven command with goals "clean package"
- Upload to GitHub
For this project, we will migrate to Google Cloud Platform, but feel free to use another cloud services provider.
- Create a Google Cloud Platform project
- Enable Kubernetes Engine
- Create a Kubernetes Cluster and assign it with 1 or more compute engines / nodes
- Open Cloud Shell console for the project (You may have to copy the given command to connect the console to your project)
- Clone your repository from GitHub
For each service, move to the main directory of the service (e.g. "name-service" folder) and execute the following commands:
- This will build your Docker image, using Dockerfile, for containers to run on: "docker build -t gcr.io/[your-Google-Cloud-Platform-project-name]/[service]:[version-numbers] ."
- Push the Docker image to the Docker Hub registry: "docker push gcr.io/[your-Google-Cloud-Platform-project-name]/[service]:[version-numbers]"
- Move to "k8s" folder
- Create a Kubernetes pod: "kubectl create -f deployment.yaml". Check status: "kubectl get pods"
- Copy the NAME of the pod
- Create a Kubernetes service: "kubectl create -f service.yaml". Check status: "kubectl get svc"
- Make note of the service port number, between 30000 and 32767
- Install curl command in the container: "kubectl exec [pod-name] apk add curl"
- Check the service runs properly: "kubectl exec [pod-name] curl http://localhost:[port-number]". Default port is 8050 for name-service and 8051 for hello-service
- (Optional) If connection is failing, go to Google Cloud Platform main menu -> VPC Network -> Firewall Rules -> Create Firewall Rule. Add a name, ensure targets is set to "All instances in the network", IP ranges is "0.0.0.0/0" and the tcp port for your Kubernetes service should be allowed. Click the "Create" button
- Check your nodes' external IP address(es): "kubectl get nodes -o wide"
- Test that your service is accessible: "curl http://[node-external-ip]:[service-port-number]"
- Test via browser by accessing the URL "http://[node-external-ip]:[service-port-number]"