Ad Code

Ticker

6/recent/ticker-posts

Spring Boot - Hot Build Push and Deploy of Kubernetes-native applications using Skaffold , Kubectl and Jib Maven Plugin

In this Example we are going to use Skaffold to build, push and deploy a Spring Boot Rest API in side our local Kubernetes cluster managed by Docker Desktop.

What is Skaffold ?

It is a command line tool that facilitates continuous development for Kubernetes-native applications. Skaffold handles the workflow for building, pushing, and deploying applications. it helps Developers to focus on iterating on their application locally while Skaffold continuously deploys to local or remote Kubernetes cluster.

Below picture showed the Pluggable Architecture of  Skaffold :

Prerequisites To complete this example:
  • An IDE
  • JDK 11+ installed with JAVA_HOME configured appropriately
  • Apache Maven 3.8.1+
  • Docker Desktop
  • Skaffold Installation
  • Kubernetes Manifests Object Knowledge

Here are the Steps:
1. Please check my posts "Containerizing Spring Boot Application with Maven Jib - Create Docker Image and Publish to Docker hub using Jib Maven Plugin" and "Containerizing Spring Boot Application with Gradle Jib- Create Docker Image and Publish to Docker hub using Jib Gradle Plugin" to know how to Containerize and create/publish Docker images without installing a Docker client or using Dockerfile for a SpringBoot application.
2. Install Skaffold as per Skaffold Installation Guide.
3. For Windows User validate the installation of Skaffold:
From IntelliJ Terminal  use command "skaffold version" and "skaffold help"

    
From Windows Power Shell:

   You can use Windows Command Prompt as well to validate the Skaffold Installation with same commands.
4. Create a maven project using SpringBoot and jib maven plugin in the pom.xml.

5. Create a /hello rest end point.

6. Create skaffold configuration, it similar to any other K8s objects like depolyments, services, configMaps. Here we have created skaffold.yml file. In our configuration we have used kubectl for deploy our K8s manifests. 
We can use Kustomize or Helm as well within our skaffold yaml configuration to build , deploy and push. 

7. Create the K8s deployment object to deploy our Spring Boot hello application image as Container inside Kubernetes pod. With this we will be deploying our "skaffold-springboot-demo" image at container port 8080.

8. To Access the end point of our Spring Boot hello application lets create K8s service object , and expose our deployment as a Service.

9. Now its time to build our Spring Boot Application using "skaffold build" command. We will be able to see Application gets build successfully and our image got tagged and created.

Lets verify our image here:

10. Now lets deploy, push and run our Spring Boot Application Rest APIs , here in this example we are going to use command "skaffold dev". 

There are other several commands for skaffold which can be found here

Our Spring boot application we deployed and pushed successfully in our local Kubernetes cluster managed by Docker Desktop.

Lets verify our local Kubernetes cluster managed by Docker Desktop, we will able to see our "spring-boot-demo" service is created successfully.

11. We can verify the PODs here:

12. Login to Kubernetes Dashboard using token and select the namespace "default" you will able to see the Deployment and POD details there as shown below:

13. run our Rest API. Open http://localhost:8080/hello in any browser and test our Rest End Point:

14. Now its time to see the HOT BUILD DEPLOY PUSH magic of skaffold , lets modify Rest Controller locally in IntelliJ Idea Spring Boot Application and able to update image running as container within pod inside our locally running Kubernetes cluster.
let us change our Rest Api message to:

Let us open two terminal using up-down split
Up Terminal Console:  Shows skaffold automatically detects the changes done locally 
Down Terminal Console:  Shows the status of pod changed at same time after Hot Reload of image running as container within pod inside our locally running Kubernetes cluster.

run our Rest API. Open http://localhost:8080/hello in any browser and test our Rest End Point again, You will able to see the new message as shown below:

Summary:
So in this Example we have the seen the power of HOT BUILD DEPLOY PUSH magic of Skaffold  in a Spring Boot Rest API. 

GitHub Link : rajivksingh13/teachlea
Please feel free to provide your valuable comments, Thanks.

Ref:

https://cloud.google.com/blog/products/gcp/introducing-skaffold-easy-and-repeatable-kubernetes-development

https://skaffold.dev/docs/

Post a Comment

0 Comments

Ad Code