Hello, my DevNation friends from everywhere in the world. Welcome to another DevNation Tech Talk. And today is a very special day because this is the first Tech Talk of 2021. Happy New Year to all of us. And to start the year, we're going to have a very special guest. I'm going to introduce you to my friend, to my colleague, Sebastien Blanc, or as we call him, Sebi. Sebi is one of the most charismatic speakers of the Java world. So let me show you Sebi. Sebi, you're already on screen. Welcome. Hey, welcome everyone. Hey, thank you, Edson, for the nice words. Awesome, thank you. I'm really happy to be here. And thank you to, well, happy New Year, everyone. And yeah, let's get started. Okay, so today I want to talk to you about building your own cube CTL, cube control. We'll come back on that plugin using Quarkis, okay? First of all, you will see really nice slides. And let me be honest, I didn't make these slides. These slides are from Aurélie Vache and Gael Acas. They gave a presentation on this topic, not with Quarkis, but how to make cube CTL plugins. And I love this talk. That's why I started playing with that. And I asked them if I could use their slides. And they were really happy to say, of course, Sebi, you can use them. So I tweaked them a bit. You can see here, there are some Quarkis logo. You can see also the juke here with the mask. Anyway, who am I? So I'm Sebastian Blanc. But as Edson said, you can call me Sebi. That's my nickname. You can follow me on Twitter. You have my handle there. I put it under my name, under my video, where you see me speaking, you will see my Twitter account as well. Follow me. My DMs are open. You can drop me a message. You can also just drop me a message on my email at Blanc at reddit.com. I'm working in this awesome team together with Edson, Alex, Kamech, and Burr, as director of developer experience. I'm also a Java champion. And what I love, what I really love, is doing what I'm doing right now, is giving talks on topics that I like. Okay? So, hey, and I see here on the chat that Aurélie is there. So, Aurélie, thank you again for the slides. Let's talk about Kube-CTL, or let's start with the disclaimer. How do we pronounce Kube-CTL? Is it Kube-Control, Kube-Kutl, doesn't really matter. I tend to say Kube-CTL, I think, okay? Anyway, that was just for the joke. Let me know in the chat what you prefer to say. Anyway, what is Kube-CTL? Kube-CTL for anyone who's using Kubernetes is the CLI, is the tool that you use the whole time. It's the tool that you use to speak to your Kubernetes cluster, okay? What happens, the Kube-CTL tool speaks to your Kubernetes API server, and from there you can almost do everything. List your pods, create pods, deployments, services, and check your notes, watch on resources. You can do a lot of stuff, okay? And it's a really logical CLI. It's very intuitive, okay? You just type Kube-CTL and then what you want to do, like Kube-CTL, get pods, where in my name space that you pass, okay? And I really like this one. I'm happy that Aurélien and Gael put this one because this one represents really well the Kube-CTL tool. Kube-CTL scale, so I say I want to scale a deployment that is called myDeploy and I want five replicas, okay? So it's really natural way of telling stuff to your cluster. Here you have a list of different stuff that you can do.  Anyway, can I extend it? Can I extend this tool? Well, if you join this talk and you saw the title, you probably know the answer. Yeah, we can extend it, okay? We can do that with Kube-CTL, Kube-CTL plugins, okay? You might think, yeah, maybe I would like to add a new feature and since Kubernetes is open source, Kube-CTL is open source, maybe I can contribute to the project with my really needed feature and I contribute it, but the thing is, yeah, first of all, your plugin, your feature needs to be accepted and secondly, Kube-CTL is tied to the release cycle and we know that the release cycle of Kubernetes is, well, not slow, but there are not a lot of releases, okay? So it might be that you put a PR and that you wait a few years before your feature is included, if it is accepted, okay? So forget about it and just focus on creating your own plugin. Because creating a plugin just enters the whole spirit, the way you think of Kubernetes. You know that Kubernetes is easily extendable, okay? We, if you look at the cluster side, we all know how we can extend Kubernetes with for instance, operators, where you create your custom resource definitions, your own controllers and Kubernetes is made to be extended and that counts for the CLI that comes with it, Kube-CTL. So we can create plugins. Why is it useful to create a plugin? Well, there are different use cases, okay? Maybe there's a really repetitive task that you do every day in your work, okay? And that requires a really long line of code, Kube-CTL. You need to patch maybe a service to change the selector of your services or you want to spin up quickly a pod that contains, I don't know, a podgrass so you can access agent to it and but you keep typing all this stuff, okay? And maybe you have some really specific flows in your team, in your company that you would like to encapsulate inside a plugin and distribute that in your team, your company, okay? So there's no one use case but because it's so easy, let's see how we can do that. And awesome, GIF, GIF. There's another discussion, do we say GIF or GIF? I'm joking. First thing, language and mystics. You can write your plugin in whatever language that you want, okay? You can write it in Bash, okay? One of the most famous plugin, the one which is called Kube-CTLX or Kube NS to switch between your namespaces and your contacts are in Bash. I will show you that. But you can write it in Go, Rest, in Python or in Java and then more particularly in Quarkis and that's what we're going to talk about because I'm a Java developer. I think most of you who join us today are also probably Java developers and maybe I want to write my script and I'm really bad in Bash like me and I don't know really go, okay? There's only one restriction. Your language needs to be able to parse arguments that you pass to your program that you learned, to your binary. You need to be able to create a CLI, okay? And then, and that's probably the only convention that you need to follow. You're the naming of your plugin. When you will create a plugin, it will always start with Kube CTL dash the name of my plugin. That's really the only convention that you need to follow. From there, what do you need to do? You need to make it executable, okay? So here in this example, imagine we have a Bash script inside our plugin and with CS mode, we make it executable. That might be a challenge for Java, remember, because yeah, we can do a Java jar, but anyway, we will come to that later. And then you have to put it in your path, okay? It can be in your user bin, in your user local bin, or you export it in any way. It must be available in the path, in the path. And that's it, you're done. You can now just call your plugin, Kube CTL the name of your plugin, and that's it, it just works. Okay, let me grab. Is something wrong with the video? Ooh, I see people complaining and chat. Okay, let me continue. That's something we'll let me know. Okay, anyway, so let's dive for us into the meat of this presentation, okay? Because my talk is about creating Kube CTL plugins in Java with Quarkus, okay? And we have a few challenges to face, okay? How do we manage CLI options and parameters with Java? You know that with Java, when you have your class, you have your main class and your main class can have arguments, okay? And then you can manually parse all these arguments, inject that into your code, but it's not really easy. Out of the box, Java is not really meant to build CLI tools, okay? That's the first challenge we have to, okay, all good. I said, okay. Second challenge is, well, my Java program need to interact with the cluster, with my Kubernetes cluster. So is there any good library available for that? Good library that is complete, which is updated with the new Kubernetes releases. So that's another challenge. And then how do I quickly bootstrap my project when I have the idea, okay, let's create a new plugin with Java, creating a new project in Java. It's not that easy because, for instance, you need to handle all the dependencies. So you can use Maven for that, but you have to set up a whole stricter for this. And it's sometimes a lot of work for just a simple plugin. And then you have to make it executable, okay? By default, your Java program, once it's compiled, will run with a JVM. You basically do a Java jar pointing to your jar and it runs, okay? Then you can make a nice script to make it like a command, but still, people who are using your plugin must have a JVM. And maybe if you have a really complicated plugin, it might be a bit slow, okay? And that's the last one, how to make it fast. Let's start with the first challenge, how to handle parameters and options, okay? I took here an example, which is not a kubectl plugin, by the way, but a famous comment that we saw before. Just that we know the different differences between the parameters and options. So here in orange, we have skill. Let's imagine that's the name of our plugin. And then we have parameters. And it's really important in which order your parameters are. And then we might have some options, okay? Options with values. And these options could be optional or some could be mandatory. So again, you can do that on your own if you want that. If you look a bit and you search for CLI libraries in Java, you have a few options. And one option that I will show you here is one called Pico CLI, okay? Pico CLI is a small library that you add in your Java project. It's a jar. And then you can do the craziest thing that you ever imagine about CLI in Java. I don't have time to dive into it. I will show you quickly the website and you will find all the information there. But again, if we take the kubectl scale deployment definition replicas, if I want to represent these options and parameters, look, I got some annotations here, but here I just create a string. That's my resource type, which is this one deployment, a parameter. I can give it an index zero. That means that's my first parameter. I can give some description. I could add some help. So when you type to command, it gives you some hints. Here I've got a second parameter and here I have my replicas, for instance. And that's an option. And since I will be giving a number here, for I can put that directly as an int. And Pico CLI will handle that all for me. I just type my command with all the parameters and option and that is all got injected in my code. And I just can use that in my code like an attribute. Okay. Second challenge. How do I speak with my Kubernetes container? So I think there's the official Kubernetes Java client. To be honest, I never really tried it, but there's another library, which is called the Fabricate Kubernetes Client. Okay. So Fabricate, be careful. Some of the project has been deprecated and are called now JCube. It is more on the container side, but the client, the Kubernetes Client still is named Fabricate. And this library is just awesome. Okay. Again, I don't have time to explain everything about this library, but if we'd still come on this same example here, Qube's CTL skill. So once I got my parameters injected, I need to scale my deployment. How can I do that? Well, I just inject my Kubernetes Client into my code. Okay. And then I have a very fluent API. Here I say, Kubernetes Client, give me all the apps, give me all the deployments, give me the deployment that has the name resource name that I got it from my CLA and then do dot skill and the number of replicas. Okay. So, and you will see for every single API that is available for Kubernetes, you can use it from your Kubernetes Client. So you can use it to scale, you can use it to list your pods, to create resources. You can easily create resources. Again, with a very fluent API, using also a lot the builder pattern. And if you know the book Effective Java from Josh Blosh, and I know that Edson really love this book. One of the first tips he gives is the builder pattern. Well, this pattern is applied a lot here in this library. So you can easily shape up your new resources, edit new resources. And what you also can do is watch resources. And that's really important. Maybe your plugin needs to watch your deployment and once your deployment has finished the rollout, for instance, then something other happened. And you can easily add this watchers with this library. Okay, now the rest of the challenges. We need to make it easy to set up a new project. We need to make it fast, okay? And we're speaking about Java, but Java is great, Java is fast, Java can be native. First of all, to set up a new project, I'm going to show you one amazing project. And I don't know if Max is on the call or in the chat, but it's a project created by Max Anderson. It created that one year ago, something like that. And basically what it is is being able to create, to run Java code like a script. All you need is one file with your Java code inside. And look at this convention at the beginning here. You have the slash slash depth. Here you can define your dependencies and then you write your Java class or Java even supported GSH for scripts. And once you have that, well, J-Bang is command line that you install and then you can do J-Bang run my script.java, for instance, and it will just run your script. Even if you don't have a JVM, it will download the GVM for you and et cetera. There's no really naming convention for your script. So if my script is called my plugin without .java, not an issue for J-Bang, it will just run it. And remember, you remember that convention that we say that our plugin needs to be called kubectl-myname. So let's solve this issue. And I will come back on that, but you can build your project as a jar, but you can also build it as a native library. I will come back in that in a few seconds. Let me take the time. Yeah, I'm right on time. And you have this awesome command, which is called J-Bang app install, which will install your app in the past and will make it executable from everywhere. Okay? Then the last part, make Java fast, make Java small. And for this, we're going to use Quarkus, okay? Again, I don't have time to dive into Quarkus, but basically Quarkus is a Java stack from the future, except it's already available now. The most magic of Quarkus is that most of the things that were happening during runtime, like scanning the class path, constructing the meta model, is now happening at build time, which make it really fast to start. And also, because a lot is happening during build time, and we know exactly what will happen at build time, we can clean up our artifact, our jar. And we end up with a really small jar using not so much memory. And we can even go further with Java, with Quarkus. Oh, yeah. We can, sorry, sorry, yeah, that was almost there. Quarkus works with extensions, like kubestail works with plugins. You can extend Quarkus with new features. And we call that extensions, which are basically jars dependencies that we add to our project. And these extensions need to be aware as well of the Quarkus way of building and running. You know what? I have really good news because the two libraries that I mentioned before, Pico CLI and the fabricate Kubernetes client, well, yes, they are available as Quarkus extensions. So I can just add Pico CLI as an extension and the Kubernetes client as an extension and I'm ready to go. So I get all the tools, all the weapons to make it an awesome journey for me to build a kubestail plugin with Quarkus. Last thing, because we still haven't tackled the fact that we still run a jar. If I want to make my Quarkus plugin a real executable, a binary, okay? Well, I need to compile it to a native platform. And good news, I can do that with a project which is called GrowLVN. Again, I don't have time to dive into that but basically it's the uber virtual machine that can take any source code from any language and compile that to native code. And when I say native, it's nothing to do with cloud natives. No, native to your platform. So if I compile that on my machine, on my Mac, it will be a binary for Mac, same thing for Linux, okay? So I get all the answers for my challenges and I just can start writing my plugin, okay? So let me quickly do an overview. Let me see, I got seven minutes left. That should be, that should be quite okay, okay? Let me go here. I'm in my console, let me clear. And to create my new project, I told you I'm going to use J-Bank, okay? So I installed J-Bank here. You can install it easily on your machine using brew, using SDK. On my Linux machine, I use SDK. I love this package manager, by the way. Anyway, and what I can do with J-Bank is say, in it, in it, I can pass your template, I pass in that, definition, and let's call my project, my cube CTL. I was almost missing the convention, cube CTL, definition, live, okay? And I made a typo here, definition live, okay, there we go. And has created for me now, a definition live, okay? I can look inside it, let me do that with VR, because you're less, okay? And I can, I just, I do that because I just want, I'm using an old template. I just want to go to the latest one. And that has created a project for me, okay? With the command line, using Pico CLI for free. And just say hello and the name that I would pass, okay? So let me outside this and let me do a J-Bank run, cube CTL, definition, live, okay? And I say Seb, for instance, okay? So that will, will the draw for me? And we say, hello, Seb, okay? So I get here my script running, okay? I can change the script. I can add any libraries that I want. I just do a J-Bank run to quickly test if it's working. I can do here, definition, something like that. Okay, hello, definition, awesome, clear. What I should do now, and I won't do it here live because it takes a lot of resources. I can say, build my application in a native way, create an executable of it, okay? And I could do that now, but it will take two minutes and all my resources will drop. And I think there are already some issues. Anyway, five minutes left. Anyway, I will show you a native version later, but what I really want to show you is the app install, okay? Here I say, install my app, which app? Well, the one I just created, definition, live, okay? And that will install my command. And normally, now if I do a cube CTL definition test here, it's running like a command. So it's been executable, okay? So let's try it for real now. Let me do cube CTL. So I'm connected here on the cluster, if everything, cluster info, sorry. I'm connected here on my Amazon cluster, which is really slow, okay? There we go. And I should be able to do cube CTL definition. Live test, okay? Did I do an, what did I do? Hmm, maybe it's not, let me see. Did I do, could be that I did something wrong. Let me see. Maybe I need to open a new window, cube CTL, definition, live, live test. There we go. Okay, that's the difference. On my Linux, I don't have to open a new terminal. On Mac, I need to open a new terminal, okay? So I'm doing all my preparation on my Linux and then, but anyway, we got the result here.  Here I got my first cube CTL plugin completely useless because it just print out some text here. But yeah, it's working, okay? So it's that easy. Here we do nothing with the Kubernetes cluster. I got three minutes left. So let me quickly show you a bit more complicated plugin that I created. No, this is the skill one. I want to show you one I wrote during my holidays, which is called cube CTL limits, okay? One thing I often need to do on my deployment is set the CPU limits and the memory limits. And you can do that by editing your YAML. I say, oh, let me do a plugin for this, okay? So again, you can see here it's a J-Bank project. I can add here all my dependencies. I can even add some configuration here. And then I have all my parameters. So what is the deployment that I want to deploy? What is my CPU limit? Okay, I got it here. And then here in my run, I just run my command. And here I'm using this fabricate Kubernetes library, okay? Here I'm using a builder. Remember, I told you it's using a lot of builder. Here I say I created a resource requirement builder and I say, okay, with limits, CPU, quantity, parse the one that I passed in my command line. And then I add that to my command line. Spec template, et cetera, in my first container, okay? I make a shortcut. I assume you have only one container and done. And it's all I need to do. And with that, I can set limits on my deployments. Let's see if this works. QCTL plugins, I got it here, limits request, okay? So I think I only have it here running to the run. I should have it here. Yeah, so let's try to run it with J-Band for it. So it got QCTL limit, my app. So the name of my deployment CPU limit, let me put 250, okay? And that should go to my real cluster in Amazon and change this. So if I do get deployment at the YAML, I got here to the YAML and where is it? Where I'm blind, I'm blind when I'm stressed. Oh, there it is, 250, okay? I already installed a native version of that, but I didn't install it yet. So let me do it and then we will be done. J-Band app install, okay? No, this one, QCTL source, QCTL limit, okay? I install it and let me just, J-Band, almost there, run limits. Let me just take this because I'm lazy, you know? Let me open a new terminal because now I know I need to open a new terminal. Let me increase that and now let me do QCTL limit, my app, let's put that to 180, that's 50. And if the demo gods are with me, yes, there we go. QCTL gets deployment. It should be on 150, there we go, okay? I got my plugin running. And I'm out of time, so, and that was everything that I wanted to show you. One last thing, the slides have been shared, I think, with you already. I didn't mention the whole part of packaging your plugin and how to distribute it, but Aurelie and Gael did add some slides on that. I, these slides are still available on my slide deck at the end, so if you want to know how to package that, there's a really nice package manager for QCTL plugins, you can read it there. That's all for me. I hope you really enjoyed it and I can maybe take some one or two questions, Etton. Etton, maybe you're on mute, no? Oh, I'm on mute, yeah. Well, I just was thanking you, Sebi, for these amazing presentations and we do have questions. Jean-François-Mauri is asking, the fabric of Java client is lacking some abstractions against the API versioning. Do you have any comments about it? To be honest, no, because I don't know enough about it. I wonder if that hasn't been solved in the latest version. Version five has just been released two weeks ago, I think that, and a lot of stuff has been added there. So maybe this issue has been tackled, but no, I don't know enough about it. He has to ask to our colleagues from Reddit. They will be able to answer. Yeah, maybe following up on the fabricate mailing list could be like a starting point too. Okay, and another question from Pablo Jose Gonzalez Granados. Could you show up the size of the Java binaries? One of the examples? Yeah, well, one of the examples. Maybe the easy ones, the one I created to steal definition life. Oh, no, now I'm running the plugin. Oh, yeah, to be honest, I don't know where, I don't know where J-Bank puts the cache. It's somewhere in the cache. Oh yeah, something like that. I think export, export cube CTL, definition life, maybe that were, let me just try this, export LS, and here I should have the jar, yes. And now I can do LS LA, and here you can see the jar. The jar is, is that for, I don't know what. Find LS-LH. L-H. Hotel, yeah. Okay, so you see it's really small. To be honest, the native version will be bigger, especially if you have the Kubernetes client, it's a bit bigger, but yeah, still the jar you can see it's extremely small. Yeah, yeah, it's amazing what you can do with 146 kilobytes of disk size. Exactly. And no other questions, no, I think. Yeah, looked through the chat. I think that was all the questions that we had for today. Yeah. Okay. Yeah, well again, Sabi, thank you for this amazing tech talk. We are up to a good start in 2021. And yeah, stay tuned, don't forget to sub-scratch our channel and give us a thumbs up if you enjoyed this video because we're going to have a lot of great definition content during this entire year. And hope to see you soon in the next definition offering, maybe a tech talk, or maybe even at the show. Yeah, we are in the show is next week. We forgot. Exactly. So stay tuned for next week's, this show. This show, yeah. Thank you, everyone. Bye-bye. Bye-bye.