development tools

Integrate RazorOps with GKE


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

To access a cluster using kubectl, you have to set up a Kubernetes configuration file (commonly known as a ‘kubeconfig’ file) for the cluster. The kubeconfig file (by default named config and stored in the $HOME/.kube directory) provides the necessary details to access the cluster. Having set up the kubeconfig file, you can start using kubectl to manage the cluster. For razorops you can follow the process mentioned here to access the cluster

Next sign in to razorops with working github account

Next move to kubernetes section and click on Add New

Next you navigate to add your existing cluster window

Here you can add name for cluster and authentication method Here we can go with kubernetes ConfigFile (which is generated by connect credentials )

The config file will look like

In authentication section: Just copy and paste and click on Create Cluster

Next your cluster will added to Razorops kubernetes section successfully show like

Cluster added process completed with name Razo-gke

Next move to workflow section for run a pipeline for deploy our application on to kubernetes eks cluster

Now your in workflow dashboard

You can navigate to the add a new pipeline dashboard by clicking on New Pipeline.

SELECT GITHUB

SELECT REPOSITORY

And confirm it

Enter the razorops pipeline

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

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.yml

apiVersion: v1
kind: Service
metadata:
   name: sample-java-app
spec:
   type: NodePort
   ports:
   - port: 8080
     targetPort: 8080
   selector:
     app: java-app

Next Run your first Build

Next automatically

  • clone source code from repository
  • Build code with maven
  • Create image with dockerfile
  • Push the image from dockerhub repository
  • Deploy the container on GKE cluster with kubernetes manifest file i.e (deployment.yml and service.yml )
  • Access the application with NodePort ip service

After pipeline running succeeded

We can find logs in logs section

Successfully Sample-java-app pod up and running and works on NodePort-service- 30516

We can find :31103 In my case i.e 34.132.123.107:30516/spring3/

Note:- This application working on tomcat server we need to mention application name i.e spring3</b>

Ready to get started?

30 Days Free Trial

Signup Here