Prerequisite :
An existing Razorops account and GCP account
Creating clusters on cloud GCP
Github Repository : https://github.com/Razorops-code/spring-boot.git
You can create GKE cluster by following the official documentation or GUI model
After creating GKE cluster
Setting Up Cluster Access
In order to utilize kubectl to access a cluster, it is necessary to create a Kubernetes configuration file (often referred to as a 'kubeconfig' file) for that particular cluster. The kubeconfig file, which is typically stored in the $HOME/.kube directory and named config by default, contains all the necessary information for accessing the cluster. Once the kubeconfig file has been properly set up, you can begin managing the cluster using kubectl. For Razorops, you can follow the steps to gain access to the cluster. Click here to access the cluster
Afterward, log in to Razorops using a functional GitHub account
Next, navigate to the Kubernetes section and click on the "Add New" button
Next you navigate to add your existing cluster window
At this point, you can assign a name to the cluster and choose an authentication method.
In this case, we can proceed with the Kubernetes ConfigFile.(which is generated by connect credentials )
The resulting configuration file will appear as follows:
For the Authentication section, copy and paste the kubeconfig file, then click on the "Create Cluster" button.
Once you've completed the previous step, your cluster will be successfully added to the Kubernetes section in Razorops and should be displayed accordingly.
The process of adding the cluster to Razorops CICD is now complete, and the cluster should be displayed with the assigned name of Razo-gke.
Next, navigate to the Workflow section in order to run a pipeline and deploy our application onto the Kubernetes GKE cluster.
Now your in workflow dashboard
To access the "Add a New Pipeline" dashboard, click on the "New Pipeline" button.
SELECT GITHUB
SELECT REPOSITORY
And confirm it
After adding the .razororps.yaml file to the repository, a pipeline will be automatically triggered in the workflow based on the commit ID.
.razororps.yaml
tasks:
build-job:
steps:
- checkout
- commands:
- |
mvn clean package # build the package
ls -a
ls target
- docker/build:
image: razoropsrepocode/spring # build the image with Dockerfile
push: true # push image to docker hub repository Which is integrated
tags: ["latest-v2"]
# kubernets deployment
deploy-kubernets:
when: branch == 'master' # only run if code is pushed to develop branch
depends: [build-job]
steps:
- checkout
- commands:
- |
kubectl create -f deployment.yml
kubectl create -f service.yml
kubectl get svc
Kubernetes deployment manifest files are a essential component for running applications in containers. In this case, we utilize the deployment.yml file to deploy a Sample Java Spring Boot application.
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-java-app
spec:
replicas: 1
selector:
matchLabels:
app: java-app
template:
metadata:
labels:
app: java-app
spec:
containers:
- name: java-app
image: razoropsrepocode/spring:latest-v2
imagePullPolicy: Always
ports:
- containerPort: 8080
Service.yaml is a Kubernetes manifest file that describes a Kubernetes Service resource. The Service resource provides a stable, network endpoint for accessing a set of pods that provide the same functionality.
service.yml
apiVersion: v1
kind: Service
metadata:
name: sample-java-app
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
selector:
app: java-app
The following steps will be executed automatically in sequence:
Cloning the source code from the repository.
Building the code using Maven.
Creating an image using the Dockerfile.
Pushing the image to the DockerHub repository.
Pulling the image from the DockerHub repository.
Deploying the container on the EKS cluster using the Kubernetes manifest files - deployment.yml and service.yml.
Accessing the application using the NodePort IP service.
After pipeline running succeeded
We can find logs in logs section
The Sample-java-app pod is up and running successfully, and it can be accessed through the NodePort service on port 31103. You can find it using the <node-external-ip>:31103 address.
In my case i.e 3.109.54.147:31103/spring3/
Note:- This application working on tomcat server we need to mention application name i.e spring3
Conclusion :
Deploying a sample Java Spring Boot application to Google Kubernetes Engine (GKE) using Razorops CI/CD pipeline is a straightforward process that involves creating a pipeline in Razorops, creating a Docker image of the application, pushing the image to a container registry(Dockerhub), and deploying the application to GKE.
To deploy the sample application to GKE using Razorops, you need to have a Google Cloud account and the necessary permissions to create and manage GKE clusters. You also need to have a basic understanding of Docker and Kubernetes concepts. Once you have met the prerequisites, you can follow the step-by-step instructions provided in the documentation, build a Docker image of the Spring Boot application, push the image to a container registry, and deploy the application to GKE
By following these steps, you can automate the deployment process and achieve continuous integration and delivery of your application. Razorops provides an easy-to-use platform for building, testing, and deploying your applications to GKE, allowing you to focus on developing your code and delivering value to your customers.
If you require assistance with this guide, please ask for help by booking a ticket here.
Visit and Signup - https://razorops.com/
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article