Super simple deploy using spring boot, docker, k8s and kind

Overview

Target

Target of this repository is show how to build spring boot application Docker image and deploy it with kind and k8s at least in local.

Prerequisites

We will need next tools installed:

  1. JDK 8+
  2. Docker
  3. Kubernetes
  4. Kind

Project

This is simple rest application that response with 'Hello World!' on root rout. To get try you can clone it with:

git clone https://github.com/demkom58/gradle-spring-boot-deploy-example.git

or

git clone [email protected]:demkom58/gradle-spring-boot-deploy-example.git

Build

We can build Docker image using Cloud Native Buildpacks (Paketo Buildpacks) without writing any Dockerfile or Docker-compose.

To build image we need spring boot plugin. Here are few examples:

Maven

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

Gradle

plugins {
    id 'org.springframework.boot' version '2.5.4'
}

It's included by default in spring start project generator. Now we can start Docker and enter command to build image:

Gradle Maven
./gradlew bootBuildImage ./mvnw spring-boot:build-image

When execution will be done, we should see new image appeared in docker images with name of project and current version of project in tag.

Open terminal and enter docker images gradle-spring-boot-deploy-example:0.0.1-SNAPSHOT to get detailed info about built image. Result:

REPOSITORY                          TAG              IMAGE ID       CREATED        SIZE
gradle-spring-boot-deploy-example   0.0.1-SNAPSHOT   93abbee19f85   41 years ago   289MB

To check that everything build right we can run our image and check out application. Also, just for fun we can redirect port 8080 to 80: docker run --name gradle-spring-boot-deploy-example -p 80:8080 gradle-spring-boot-deploy-example:0.0.1-SNAPSHOT

Go to localhost or localhost:80 in your web browser and check that everything works correctly, we should get in response:

Hello World!

We can stop container using Ctrl + C and remove container using docker rm gradle-spring-boot-deploy-example.

Deploy

Let's start Kubernetes cluster using kind:

kind create cluster

We need say K8s to load Docker image from registry like that:

kind load docker-image gradle-spring-boot-deploy-example:0.0.1-SNAPSHOT

To create deployment in k8s open terminal and enter next command:

kubectl create deployment example-app --image=gradle-spring-boot-deploy-example:0.0.1-SNAPSHOT

Now we can use kubectl get deployment to get deployments and kubectl get pod to get pods.

> kubectl get deployment
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
example-app   1/1     1            1           44s

> kubectl get pod
NAME                           READY   STATUS    RESTARTS   AGE
example-app-584b66b696-q6ggs   1/1     Running   0          46s

Now we need make application in k8s accessible from outside. Using next command we will expose our deployment's port 8080:

kubectl expose deployment example-app --type=ClusterIP --name=gradle-spring-boot-deploy-example --port=8080

We can check created services with kubectl get svc:

> kubectl get svc
NAME                                TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
gradle-spring-boot-deploy-example   ClusterIP   10.96.58.78   <none>        8080/TCP    34s
kubernetes                          ClusterIP   10.96.0.1     <none>        443/TCP   25m

Now let's configure port forwarding like with Docker, execute: kubectl port-forward service/gradle-spring-boot-deploy-example 801:8080

Open localhost:801 in web browser, and we should see same response that have with docker only :)

To terminate port forwarding we can press Ctrl + C

Clear workspace

  1. To delete service enter: kubectl delete svc gradle-spring-boot-deploy-example
  2. To delete deployment enter: kubectl delete deployment example-app
  3. To delete cluster enter: kind delete cluster
You might also like...

mall-swarm是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch、Kubernetes等核心技术,同时提供了基于Vue的管理后台方便快速搭建系统。mall-swarm在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。文档齐全,附带全套Spring Cloud教程。

mall-swarm是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch、Kubernetes等核心技术,同时提供了基于Vue的管理后台方便快速搭建系统。mall-swarm在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。文档齐全,附带全套Spring Cloud教程。

mall-swarm 友情提示 快速体验项目:在线访问地址。 全套学习教程:《mall学习教程》。 Spring Cloud全套教程:《SpringCloud学习教程》。 专属学习路线:学习不走弯路,整理了套非常不错的《mall专属学习路线》。 项目交流:想要加群交流项目的朋友,可以加入mall项目

Jan 3, 2023

Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

Sep 13, 2022

Spring Boot Log4j - CVE-2021-44228 Docker Lab

Spring Boot Log4j - CVE-2021-44228 Docker Lab

Spring Boot Log4j - CVE-2021-44228 The Log4Shell vulnerability (CVE-2021-44228) ultimately is a quite simple JNDI Injection flaw, but in a really real

Jun 10, 2022

Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

Jan 5, 2023

Boilerplate code for hello world java score and deploy it on testnet.

Java SCORE Examples This repository contains template of a java SCORE and instructions on how to deploy a simple java score. How to Run 1. Build the p

Feb 1, 2022

With this template, you are ste to deploy your application to Heroku

Template for deployment With this template, you are ste to deploy your application to Heroku. I´m using a Spring backend, React JS Frontend with Mongo

Jun 23, 2022

JHipster Lite ⚡ is a development platform to generate, develop & deploy modern web applications & microservice architectures, step by step.

JHipster Lite ⚡ is a development platform to generate, develop & deploy modern web applications & microservice architectures, step by step.

JHipster Lite ⚡ Description JHipster is a development platform to quickly generate, develop & deploy modern web applications & microservice architectu

Jan 3, 2023

Deploy this 🔥🔥🔥 BLAZING FAST 🔥🔥🔥 API to get instant access to ✨✨✨ INNOVATIVE ✨✨✨ API to quickly define whether the numbers are odd or even.

Deploy this 🔥🔥🔥 BLAZING FAST 🔥🔥🔥 API to get instant access to ✨✨✨ INNOVATIVE ✨✨✨ API to quickly define whether the numbers are odd or even.

Is Odd API This 👈 is 🅱 💰 a 🐍 simple API that 🍑 returns 💌 whether 📊 📊 a 🔥 number 💦 🔢 is 🙈 💦 odd 🤥 or 💰 not. ♂ With 👏 👼 this 🏽 👈 API

Sep 23, 2022

Spring Boot JdbcTemplate example with SQL Server: CRUD Rest API using Spring Data JDBC, Spring Web MVC

Spring Boot JdbcTemplate example with SQL Server: Build CRUD Rest API Build a Spring Boot CRUD Rest API example that uses Spring Data Jdbc to make CRU

Dec 20, 2022
Owner
Max
Hahaha. My favourite programming languages are Java and Rust, also I enjoys to learn someting new & play random things.
Max
Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose

springboot-mongodb-docker Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose Steps & Commands pull mongo image from docke

Java Techie 9 Nov 25, 2022
👮🏻‍♀️ simple k8s admission controller using spring boot

spring admission controller Spring boot를 이용해 만든 간단한 Kubernetes admission controller 입니다. Admission controller의 Validating webhook을 이용하여 Pod의 생성을 제한합니다

Bobae Kim 2 Dec 22, 2021
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
An implementation of a sample E-Commerce app in k8s. This online retail marketplace app uses Spring Boot, React, and YugabyteDB.

An implementation of a sample E-Commerce app in k8s. This online retail marketplace app uses Spring Boot, React, and YugabyteDB.

yugabyte 1 Oct 27, 2022
8INF138-TP3-SECURITY-DOCKER - Le docker du tp3 du cours 8INF138 de l'UQAC

?? TP3 - 8INF138 Ceci est le TP3 du module 8INF138 de l'Universite du Quebec a Chicoutimi Le rapport ce situe dans le depot Le travail visuel n'a pas

Aurelien Marc 2 May 30, 2022
消息推送平台 - 所使用的技术栈包括:SpringBoot、SpringDataJPA、MySQL、Docker、docker-compose、Kafka、Redis、Apollo、prometheus、Grafana、GrayLog等等

项目介绍 austin项目核心功能:发送消息 项目出现意义:只要公司内有发送消息的需求,都应该要有类似austin的项目,对各类消息进行统一发送处理。这有利于对功能的收拢,以及提高业务需求开发的效率 系统项目架构 austin项目核心流程:austin-api接收到发送消息请求,直接将请求进MQ。a

Java3y 2.9k Dec 31, 2022
Microservice Architecture with Spring Boot, Spring Cloud and Docker

Piggy Metrics Piggy Metrics is a simple financial advisor app built to demonstrate the Microservice Architecture Pattern using Spring Boot, Spring Clo

Alexander Lukyanchikov 12.1k Jan 1, 2023
Spring-boot project using open-api, docker, maven, REST

library-service spring-boot project using open-api, docker, maven, REST I used docker to run the project, as well as open-api to generate basic GET an

Sandy Huang 2 Nov 27, 2022
An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

obaydah bouifadene 14 Nov 8, 2022