 So I'd like to start today talking about the Kubernetes for Java developers Those that want to take a seat feel free. You are all welcome to stay and see the session My name is Rafael Benevides. Let me introduce myself. I work at Red Hat as a director of developer experience My role in Red Hat is to help developers to be more productive with open source tools in general and Especially with Red Hat technologies If you can get in touch with me by my email address, which is Rafa Benevides at redhat.com But you can also find me and follow in Twitter. I will really appreciate if you have feedback of this session By using my Twitter handle Rafa Bene I've been a Java developer for a while and now I'm more much more involved with containers And that's why I like to talk to you today But before that, I like to invite you to join the micro profile lunch that will happen on Thursday 11 30 to 2 p.m. And Also invite you to join the Red Hat developers portal which is a portal that provides Value valuable resources for developers like free access to products free ebooks Bug posts any kind of resources that can make your life easier. So let's start Focusing on our Main subject here, which is place your application your Java application inside containers And how it can be orchestrated and managed by Kubernetes Let me start with a question Have you any one of you run ran Java application inside a container or ever use the Docker container the question is Is that Java supposed to be? Portable between environments. Why would you put your Java application inside containers? Well, of course, we have a lot of advantages when you run inside containers. We have We can not only amped it and your application, but you can place your Your application server configured with data sources with files environment variables package everything together and that will be Isolated process that you can send to the production But we have a lot of problems when for example when we run Docker run and the name of the image you have a single process running in a single machine, but What happens when you have a lot of containers running in multiple machines? How would you handle port conflicts? How would you know what versions of these containers are running? How will do you update them? So to solve that problem, I like to introduce you to Kubernetes Kubernetes is a project from Google and It uses the Google expertise with containers They use internal project called Borg, but they got that knowledge and released it Released it this open-source project that manages containers So instead of talking I like to show you how that works. I have here An application a Java application That there is a POM XML file. It's by the way, it's a micro profile application that I want to build the application build the fetcher and Place that inside a Docker image So that's what I'm doing now as you can see it's a pure Maven build it's compiling all the Java sources It's producing a war file, but now with the wildfire swarm plug-in I will get this war file and Place it together with the wildfly and create a fetcher Now that I have this fetcher this wildfire swarm fetcher I'm am that this inside a container that has already the open The Java open JDK. I'm setting up setting up an environment variable and now I have this image running For those of you who have a used Docker containers, can you give me a tip? How can I run this in a Docker container? Let's do it together We would do Docker run right The next thing is dash D to create a detached process Then it's also a good practice to give it a name This is a the guest book service. So I would Call it guest book service, right and plus the name of the image Right To run that with Kubernetes. I do I can I replay Kubernetes by Cube CTL run, I Don't need to specify the dash D because it will already created a detached process the name is the second parameter and the Name of the image Will be the third parameter So as you can see it's very similar, but I can also specify that I want I want two replicas of this container running So once that I execute it it will create a replication controller Let's see how that behaves inside OpenShift as You can see here. I created two containers running Each one of these containers has its own IP address. So this is the IP it has the IP 172.05 172.04 I Can do a cube CTL get pods to see those containers So I have here the two replicas and the my sequel that I previously deployed I can even follow the logs of them. So Cube CTL logs Dash F and the name of the pod so I can see here that the application is started But the purpose of the replication controller is to keep always true replicas running So suppose Let me do here the following thing What I will do now is to kill one of this process. So let me execute a terminal inside one of this Java process as You can see I have here the JBoss the JBoss Process running the Java process. I Will do a kill one It killed the process But immediately Kubernetes it started a new one If I do a cube CTL get pods I can see that I have now two pods running it restarted the existing pod again That's the purpose of replication controllers But now this container It could be suppose that I have multiple nodes and If the entire node crashed down it will Recreate this pod in another node and very likely with an different IP address. So to use this service I can't rely on the IP of these pods. I I Like to create an abstraction to access those containers and that's the purpose of Kubernetes service. So what I will do now is expose this replication controller using the port 8080 and when I do that I Create a service that it has its own IP address So when I access this service It will be it will do a load balancing between this two or ten or a thousand pods that I can Execute at the same time another nice feature about Heaven service is that it allows me to have an easy service in discovery. For example as I told you I have here My sequel my sequel database running This Java application connects to this my sequel, but how can I find this in this cluster? So let me show you how I can do that something that I can do with Kubernetes or with open shift besides reading the logs here in the web terminal I can open a new terminal and type commands like For the the one that I did I can see the process, but I can also ping My my service which is called my sequel because inter inside the cluster. I have a software defined network Another thing that I could use to locate this database running is use environment variables, so Among this environment variables that were created I have the my sequel service host or my sequel service port Let me see if I have it also the guest book No, the guest book will have them on the next On the next pod. Well, this is one of the easiest way to create containers but what I like to do is to keep the definitions of these pods and ports and and labels running inside files Because for example, I would get here the next service that I want to run I want to run the front-end to access this back-end service in Java Instead of typing Cube CTL run the name of the image the name of the port the net the port I Prefer to keep it inside a YAML file because there I can Store that in github I can Version that I can easily add labels. I can easily change the replicas and change all the meta the datas and Suppose that I want to run now The other Parts of my application it will be easy as do a cube CTL create Specifying the files the front-end replication controller and the front-end service. I Have another microservice here called hello world replication controller and replic and It's service and when I do that with a single command it will read all of those files and create this Microservices for me So as you can see it will start you can easily see the image that it was Used the image that we're used here And now I need to access this application Something that I can do with OpenShift is create a route That so I can access with my browser inside this container So let me use it here. I will give it a name for example. Let's say Java one and I will use an External DNS here ten one two two Neep dot IO. It's in Neep dot IO is a service that resolves to any IP address that I place it here Once that I create the route I can just click here at the host name that I specified and I Have the application running So it's a very very simple application. Let's let's do some tests here Hi, my name is Raphael and the message is welcome to red hat Booth this triggered this access the Guestbook service and the hello world service and my application But you might wonder that sometimes containers are Supposed to be ephemeral. I have a database running here What would happen if this? My sequel died Let's do the same thing. Let's Kill this container. So let's get the pod Let me access inside the pod create a bash psaxu Let's kill my sequel and Yeah, you can see that replication controller detected that my sequel died and restarted it Automatically, but let's try to use our application again This is my this is a new test and as you can see it restarted reload the same database because Inside this pod I have a percent volume That keeps my data So no matter how how many times I kill no matter how many issues the this Application can face the replication controller will always keep it running If you want to know more about cuban it is I like to invite everybody here to join Three hours lab where we will go through each one of these details of cuban it is We will also show open shift that I just presented here to you. It will be now tomorrow on On the Houston here on the hilton here on franciscan room cnd. You are very welcome to be there Don't forget to subscribe at developers dot red hat dot red hat dot com And if you have any questions any feedback of this presentation Please feel free to add me at Twitter. My Twitter handle is raffa bene and I Really like to thank you the presence of all of you here Thank you