indrabasak / spring-k8s-example

Spring Boot example with Kubernetes and Docker.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Quality Gate Technical debt ratio Coverage

Spring Boot Example with Kubernetes and Docker

This is an example of using a Spring Boot application with Kubernetes and Docker.

In this example, Spotify's Dockerfile Maven Plugin is used for creating the Docker image. Spotify reccomends you to use this plugin instead of Docker Maven plugin.

Here is the change to this project's pom.xml.

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.4.4</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>build</goal>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>basaki/spring-k8s-example</repository>
        <tag>${project.version}</tag>
        <buildArgs>
            <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
    </configuration>
</plugin>

To build the docker image, execute mvn clean install command from the parent directory:

$ mvn clean install
...

[INFO]  ---> Using cache
[INFO]  ---> f5d60c9391eb
[INFO] Step 8/8 : ENTRYPOINT ["java", "-Dapp.port=${app.port}", "-jar","/app.jar"]
[INFO] 
[INFO]  ---> Using cache
[INFO]  ---> 3e84ee5ba1cd
[INFO] [Warning] One or more build-args [JAR_FILE] were not consumed
[INFO] Successfully built 3e84ee5ba1cd
[INFO] Successfully tagged basaki/spring-k8s-example:1.0.0
[INFO] 
[INFO] Detected build of image with id 3e84ee5ba1cd
[INFO] Successfully built basaki/spring-k8s-example:1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.519 s
[INFO] Finished at: 2018-10-21T19:55:36-07:00
[INFO] Final Memory: 67M/525M
[INFO] ------------------------------------------------------------------------

If the build is successful, it should create a new Docker image namedm basaki/spring-k8s-example:1.0.0.

You can list all the docker images by typing docker images in any terminal,

$ docker images 
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
basaki/spring-k8s-example                  1.0.0               3e84ee5ba1cd        10 minutes ago      532MB
<none>                                     <none>              963c418de905        14 minutes ago      532MB
<none>                                     <none>              5eeb5eb716b4        29 minutes ago      532MB
...

If you just want to run the newly created Docker image without Kubernetes, please go here.

About

Spring Boot example with Kubernetes and Docker.


Languages

Language:Java 99.3%Language:Dockerfile 0.7%