Kubernetes is a popular platform to run and manage containerized applications. A CI/CD solution is often needed but not always provided. You might need to set this up for yourself. In this blog post I’ll provide a minimal end-to-end solution for Java applications. This starts with a commit in source control and ends with deployment to Kubernetes.
Tools used:
- Jenkins as CI/CD platform
- Kubernetes deployed with Kubespray on KVM (here)
- MetalLB as Kubernetes loadbalancer
- GitHub as version control system
- Smee to forward Webhook calls from GitHub to Jenkins
- Maven to build the Java code
- Google Jib to wrap my compiled Java in a container
- DockerHub as container registry
The Java application
I’ve created a simple Spring Boot service. You can find the code here. I hosted it on GitHub since it was easy to use as source for Jenkins.
I needed something to wrap my Java application inside a container. There are various plug-ins available like for example the Spotify dockerfile-maven plug-in (here) and the fabric8 docker-maven-plugin (here). They both require access to a Docker daemon though. This can be complicated, especially when running Jenkins slaves within Kubernetes. There are workarounds but I did not find any that seemed both easy and secure. I decided to go for Google’s Jib to build my containers since it didn’t have that requirement.Â
Docker build flow:
