 Hello everyone and welcome to my session containerize your Java applications using Eclipse JQ My name is Mark and I work as a software engineer for Red Hat I'm currently working on two open source projects to fabricate Kubernetes client and Eclipse JQ which I will be presenting today This is the agenda for today's session. I will start with an introduction then I will List what are the common challenges to deploying applications to Kubernetes nowadays I will go ahead and explain what Eclipse JQ is and showcase a short demo with the features and Finally, I will tell you why you should choose Eclipse JQ instead of some other alternatives so Well, I know that there are many different people with different backgrounds attending DEF CONF So what I want to make sure is that we are all on the on the same page So let's start with this slide that I think that it should look pretty familiar to most of us And this was the traditional workflow when you wanted to deploy your Standard Java applications to a server in the past or your web applications. So basically you started with code Then you had some build process that generated an artifact with a fadjar, a war or something else and then This artifact would be delivered to your operations team that would Deploy it into a production server which contain an operating system and a Java environment and whatnot. So I'm pretty sure that many of the developers were not familiar with this last step and many of the tasks That were involved because probably you had an operations team that took care of all of this But of course the paradigm has or is changing in the last few years and the platform of choice is of course Kubernetes and What this really means is that many of these tasks and infrastructure components are shifting to the left. So Right now you as a developer are starting to be responsible for On top of delivering your your application package You have to deliver a probably a container image Which includes your not only your application package, but a container operating system Java runtime environment and so on and you are now responsible for for creating these images the configurations, etc So, yeah, as we've seen one of the of the Challenges right now for for Java developers is that you will need to deliver Both the container image and also cluster configurations so The classic approach to create a container image is of course using Docker and Well for Docker the the classic approach is to create a Docker file. So this is a very simple Docker file which basically starts with a Open JDK base image, then it adds Your application package and then it provides an entry point that will run your application whenever the container image is deployed So on top of the standard maybe in package You now need to or depend on the Docker CLI to build your image and also to push it to a shared Registry that would be accessible from from the cluster. So of course this image Seems quite simple, but I know and I'm sure that with time this image will grow and Will change and things will start to get more and more complex And for the cluster, it's something similar, but instead of using Docker you need to know about Jamel So you will probably need to provide a few Jamel files to be able to deploy your your application Usually at least a deployment and a service and most probably a config map and an English So you will need to create the Jamel files and configurations for for these resources And of course, you will also need a way to deploy these resources into your cluster So you will probably depend on Qubectl or some other tool like Helm again an external dependency so As we've seen right now all of these Responsibilities that previously were or belong to an operations team They are now they fall on you and you will be responsible to keeping these configuration files updated and Also aligned so if you change something in your Docker file or in your Docker build You will also probably need to change something in your Kubernetes resource and so on so of course these configurations will grow and will become more and more complex and I Think that having to deal with this yourself is really painful and will eventually end up in some bugs or or issues in production and that's not something that we want so This is where JQ comes in handy because it's a tool that will cover the the complete workflow so it will create your container images and also your cluster configuration and Probably you will not even need to add any specific configuration. So Let's go ahead and see what Eclipse JQ piece It's a set of tools and plugins that will help you generate the container images and also Generate the configuration manifest and deploy them to your cluster so the project consists of three components the standalone Java API which we call KIT and Two main plugins as of now that they use this API Use this API so the Kubernetes Maven plugin will be used to Create container images and deploy them to a vanilla Kubernetes cluster and the open shift Maven plugin is built on top of the Kubernetes plugin and will provide more open shift specific Features such as S2i build strategy or more open shift specific open shift specific resources resource configurations Regarding build strategies, I don't want to go very deep on this. Just time we are going to tell you that JQ can provide a Docker, an S2i or a JIP build strategy But what I'm going to tell you is that you can easily change from one build strategy to the other just by Switching a configuration flag. So that's something very powerful that JQ offers you The the plugin can be configured with in three modes So the first and this just is the zero configuration. This means that JQ will make use of its opinionated defaults and support for many multiple frameworks and technologies and will create the container image and cluster configurations without providing any kind of configuration Of course, we all know that our application special and has some specifics So there is an easy way to improve these defaults or to override them by using the XML plugin configuration Even if this is not enough, we also offer these resource fragments Which basically is the option for you to provide Partial general configurations that JQ will pick up and then reach with its opinionated defaults So basically what I'm telling you is that you can go ahead and throw all of those configuration files into the trash And add this simple plugin to your Maven configuration And everything will be automatically integrated into your into your Maven workflow process So just by invoking our specific goals Your project will be ready to be deployed into the into the cluster, but I'm sure that it's better to see this in action. So let me show you this in a in a very quick demonstration Okay, so for today's demo, I chose the Spring Boot Admin application, which is a very very popular project And well, it's basically an admin user interface to administer your Spring Boot applications And I think it can be quite impressive to see how we can deploy this on on a Kubernetes cluster. So This is the project in my In my IDE It's the the main branch, but I created a different branch to include the manual Configurations to be able to deploy the project to the cluster and show them to you, but it's just the unmodified project Okay, this is important to highlight. So basically as we saw the usual approach to to deploy an application to Kubernetes Was to create a Docker file along with your project Again, this is a very simple project. So basically the this is the simplest docker file. I could create It's just basically the base image using a Java runtime environment and copying the artifact and the entry point. Okay Of course along with the docker file, you will have to provide some commands To be able to to build your image and to push it to your short registry. So In this case, I created this script and Finally, this is the the cluster configuration again This is the simplest configuration. I could create to deploy this application in my case I'm going to deploy this to my mini cube cluster. So I just created a service with a node port in order to avoid the creation of an ingress and to simplify things And a deployment again the simplest deployment. I could create No liveness probes. No nothing and it's also important to highlight that this image Name and tag should align with the one that we are tagging in in docker. So You should keep in mind that when you are providing different configurations and using different systems You are responsible to keeping things aligned and again Many errors can start happen happening due to these things Okay, so I could go ahead and show you how to Deploy this in my cluster, but I mean there is not that much time and I will go ahead and start doing the same but with With jcube. So the first step when we are going to use jcube is delete all of these nonsense get rid of these configurations because jcube will provide everything for us and Thing is going to be as simple as adding our plugin okay, and since we want to modify a little bit the configuration because as I said, well, I want to create a node port instead of Just to create an equivalent configuration. So I'm just going to fine-tune the service and create a node port and also Since I want to publish this into my Docker hub account, I need to provide a specific name for my image. So I'm going to use I'm going to use this one. All right or Make it. Let's make it like this. Okay, so That's it the next step just create perform the standard build like even clean package as usual Okay, the build finished and now It's a time for to see jcube in action. So the first thing I'm going to do is build the image It's as simple as maybe khs build This will basically analyze the project see what base image is appropriate for Something wrong happened here Okay, so I was saying This will Basically analyze our project Check which is the the base image that we are going to need and We'll create an image for you will analyze if docker is present in our system and use docker or use something else depending again on our environment. So The image has already been created for us if we create If we check the images available we saw that This image was just created Again with the tag that we specified and now we want to push it to our To our docker hub account in order to make it available for the for the cluster. So again as simple as invoking push goal provided by jcube and Okay, the push is starting you can see it's choosing the the name I selected before and Okay push completed Okay, so it completed successfully And now the image should be available in my docker hub account Okay, so So far so good the part for creating the container image is complete We just added as you saw the plugin and Basically, I configured the tag for the image, but that's it. Nothing else was done. No docker file required And the next step I'm going to create the cluster configuration. So for that we are going to use this khs resource goal Okay, and now once it completes, okay, so This is not necessary for us to check but just To compare with what we had before this is what jcube generated for us So as you can see the configuration is much more thorough than the one that we Provided manually it has labels. It has lots of stuff. It even has support for from ithius And also it's important to know that The jcube detected that this was a springboard project and that it has the actuator So it added a readiness and a lightness probe for us. So again Stuff that we didn't even consider when we were creating our manual configurations has been created for us out of the box Nothing to configure nothing to I mean the only thing we configured was the the the type of the service port. So Yeah, effectively. This is an old port. So basically Now we can apply this to our cluster. So this is the This is a my dashboard of the cluster. So whenever we hit the apply Our apply goal The jcube apply goal will run and we will take these resources we generated And apply them to the to the cluster. Okay, so as you can see The resources were applied successfully created a service it created a deployment and of course the deployment Automatically created the replica set on the on the pod So Okay, it's not marked as ready because we created this Lightness and readiness probe. So until the container is ready and these probes passed It will be marked already, but Let me use the time to show you some other Tool that you will get out of the box with jcube. So for example, we can review the logs So if everything works, yeah, okay, this is actually showing the logs live for more application And if everything worked, okay, I would be able to access the yeah, so user Password, this is the default credentials So, okay Seems that the application is working and it was deployed. Okay We can also see the log down here. So So far so good okay, but Well, we saw that we had the option. I mean Right now We created everything configuration less But let's say that we were using the manual approach and now you wanted to debug your application in the cluster. So Probably you would be Lost already. You would say hey, how I'm going to achieve this again This is another feature that jcube offers and that it's quite useful for for developers. So Just by invoking this khs debug goal The application will Restart in debug mode Hopefully And we will be able to debug our application running in the cluster from our From our ID. Okay, so right now we see that the application is restarted in Again, since we have these readiness probes It takes longer for things to work. Okay, so it's ready Now we can create. Okay, we already have the configuration, but I'm going to recreate it for you. So you can see it from the start and I can create a Debug configuration remote debug Okay, and we even provide the instructions for you to add here, but okay this is the default so We can start the debug section and Okay, it's connected. Perfect. And I'm going to add a breakpoint into the Into this custom endpoint something that it's showed in the in this spring boot admin example so if I Go ahead and try to retrieve that endpoint The ID execution to stop and I should be able to debug stuff so Okay You can go here and Yeah, so let me change this value and Yeah, so I intercepted the call And I was able to replace The value on my eb again. I can hit this So yeah, you could do like a standard debug session if things didn't work. Okay Again, you are debugging directly from the cluster. So it's really cool and useful. Okay Okay, and Let's stop the session. So finally another of the of the tools that jq buffers out of the box is to clean up resources. So Uh, it will hit the undefloy goal. We will be able to remove everything from the from the cluster. Okay, so do this and Eventually all of the resources that were created should be deleted Yeah, you can see everything is deleted. Okay, so We went already from this Manual configuration with docker files and yaml files and so on to just adding plugin and these properties, but What if I told you that I could just Do this And with the vanilla project be able to deploy this into open shift. So since open shift offers additional features it's Even possible to to deploy this simple application, of course, we are taking advantage of the simplicity to Deploy this application. So Let me log in into my sandbox cluster Yeah, for instance, you can you can get these clusters for free because red hat is offering this for developers. So this is what I need and okay Let me go ahead And take advantage of jcube without even adding the dependency. So this is really really cool. Okay, I'm going to go and build the the application so Okay, it detected the open shift cluster and A build just started in my in my cluster. It's using s2i again since it detected The open shift cluster is using open shift specific Open shift specific features in this case s2i build You can see the build progress in the in the log and we could also see this in the if we entered here in the Okay, this log should show exactly the same that we are seeing here. Okay Okay, so the build completed successfully and now we should be able to Deploy this application Okay, again nothing nothing added to my project. It's out of the box Okay, so we should be able to See the application in the topology section of our console Yeah, here it is Okay, so well since again we have this activator And this liveness probe it will take a while to make it ready, but in the meantime we can check the logs from the cluster Okay, it appears to be ready. Let's see what the log shows Running ready. Okay, so if we open this url Yeah, the application was just deployed To our cluster so and it's working just like before. So this is really really really cool Again, we can use the deploy code and our cluster would be clean Yeah, so everything is clean now Okay, so we now saw all of the or many of the features that jcube offer us So let's see why why should I choose eglip jcube instead of some other alternative? Well, so as we saw The main advantage of jcube instead of other alternatives is that it It covers the complete workflow. So it creates your container images But it will also create your cluster configuration and deploy them to the to your cluster. So There is no need to use several tools. Just one tool for everything It's also important to note that there are no external dependencies on any kind of cli tools So you will not need to download anything just add your plugin in your palm or something like that And and it will work out of the box. No need to install any kind of binary and It's also important to note that this to note that this is the java way So if you are developing a java application, it's as simple as adding a Maven plugin to your build or in the future the greater plugin, which is almost ready And yeah other applications other other alternatives just Work for or try to provide a solution for every language available But again, you will need to install a cli provide specific configurations and things like that But this is really really just java Another of the advantages is the zero configuration So We have a strong set of opinion in the defaults for most of the java frameworks or most popular java frameworks available So chances are that most of the things work out of the box for you So you will need won't need to provide any specific configurations as you could see We were able to deploy a Very popular application to open shift without anything not even adding the the plugin to our palm So that's pretty pretty cool and powerful stuff and Finally, well we offer also some additional tools for developers So we have this debug watch and log goals most others that will help you Deal with your application in in the plugin so In the cluster. So that's really I think that these are really strong Strong reasons for you to choose jq instead of any other alternatives or at least to try it out. Okay So, thank you very much for joining my session I really I would really like for you to provide some feedback and to try out the the project So you can find us on twitter or also on gitter and well many places So just visit our homepage and you will find many different ways to contribute and to get in touch with the with the team And now let's in the next qa session. Let's see what questions you have. Thank you very much for joining. See you