 Welcome everyone to the webinar. Are you ready to delete some by email by Abhishek Gupta or what do you have a shake? Awesome. Awesome. Thanks so much. So before doing anything, let me pick things off and hello everyone. Thanks so much for tuning in this afternoon and welcome to this talk. My name is Abhishek Gupta. I am a developer advocate at AWS joining you today from New Delhi, India, where it has been raining quite heavily for the past few days actually. So I hope everything holds up well, at least for this session. So I realized this is a post-lun session. So I hope you have your tea, coffee, or your favorite beverage handy with you. But the good thing is that this session is relatively short. It's about 20 odd minutes. So hopefully I'll have your attention for that period of time. And I just have three slides, which this includes one of them. So let's see how this goes. So really, why am I talking about deleting YAML? So to be perfectly honest, I don't have anything against YAML as such. I have tolerated XML in the past. So I guess YAML is fine. But I'm a developer. I want to write code. I love writing code. And the last time I checked, YAML wasn't really a proper programming language. But if you think in terms of Kubernetes, YAML is the king. It's like this lingua franca of the Kubernetes world. And if you look at existing tooling like helm or customize, or even if you were to write manifests by hand, it's all YAML. So although the talk says delete some YAML, take it with a pinch of salt, it's actually more about circumventing it or putting it behind the scenes so that YAML isn't in your face all the time. So yeah, in the next probably 18 to 19 minutes or so, I will talk about this tool called CDK for Kubernetes or Cloud Development Kit for Kubernetes. I'm going to call it CDKs, just a short name there, so which is an open source project under the CNCF landscape, the Cloud Native Computing Foundation. And then very, very simple terms, CDKs is nothing but a framework using which you can actually define and model your Kubernetes resources and application. So I'll give you like a whirlwind tour of sorts. Like I said, I'm a shot of how you can actually use CDKs with the Go programming language. So with that said, I'm going to switch over to my IDE now and we'll spend some time looking at some code and trying to make sense of things in whatever limited time which we have. All right, so with that said, let me switch over and give me a second. Yeah, all right, awesome. So I want to actually start by talking about how would you typically use something like CDKs? So as you can see here, this is actually a high level workflow but conceptually it's quite simple. So you bootstrap a project, a CDK project, write some code to define your Kubernetes application and then you can ask CDKs to convert that code into YAML. And once you have that YAML manifest, it is really up to you as to how you want to use it and apply it and so on and so forth. Now, in addition to being a framework, CDKs also provides a command line interface, a CLI. So what I'm going to kick off with is just demonstrate to you how to use that CLI to bootstrap a very, very simple CDKs application here. So go over here and make a command line. I hope it's big enough. So I'll make a new directory and just change over to that directory and then take things from there. Okay, so what I'm going to do is ask CDKs, say CDKs and initialize a Go app for me. So because CDKs actually supports multiple languages, Go is one of them. So that's why I've mentioned it explicitly. Now, I start out with an empty directory but I ask CDKs CLI to give me something to work with. And if you see here, CDKs came back with a simple, it's very simple, but it's very useful starting point from where on I can build stuff. Okay, so if I were to open this main.go file here and just to show you things, right? So what I want to clarify here is every CDKs application consists of this hierarchy or a tree of components and each of them is called a construct. Now, what you can do is combine basic constructs like development, I'm sorry, deployment, service or an ingress and so on and so forth and make it or combine it within a chart and a chart is yet another construct. So let me draw your attention to this function called new my chart. It actually returns something called CDKs.chart. And finally, what you can also do is put one or more of these charts inside an application or an app in short. So app is actually the root of the tree, so to speak. It's top of the hierarchy. So if I were to scroll down here and look at and show you the main functions, I've created a new app and I've made sure that I include this chart within the app itself. Okay, so as you can see, this chart, this app only has one chart and this chart is actually empty, doesn't have a lot of business logic here. So I'm going to add some code here, our favorite Nginx, the simple canonical hello world of Kubernetes. So that's what I'm going to just start off with, just to get you warmed up. And in the interest of time, I'll do some copy paste. I apologize in advance, but if I were to write out all the code, I don't think I'll be able to do anything in 20 minutes, so copy paste is going to be. So I'm going to fill up some code here and just make sure I want to correct some imports here just to make sure. Yeah, should be fine. All right, awesome. So even if you have deployed a simple Kubernetes application, say a deployment or a service, I think you will be familiar with what you see. So if you look at this code right here, so there are things like selectors and labels and containers and a deployment. So just like you would define an HTML manifest, nothing too fancy here, but the big difference is that now, this is everything here, what do you see on the screen? It's in the form of code. This just happens to be go code, but CDK supports Python, TypeScript, and Java as well. Now, while this actually looks pretty simple, and if you spend some time rocking it, and you might feel like there's enough, wow, this is awesome, but trust me, things are going to get pretty verbose when you start building some serious applications using these simple primitives. So what I'm going to do is stick to this nginx example, but show you how you can actually improve this. So for that, I'm going to hop over into a different project now, a different folder. I'm just going to open that up. And if I were to open this file here, and if you look at this function, just draw your attention to this function, and now this code, again, it might look similar to what I just showed you a second ago, but trust me, at the same time, it is different. The reason is because I'm using something called CDKATES plus API. So if I were to scroll up and take a look at this, so this is a different package. So I'm using the CDKATES plus API, which is much more natural and intuitive. So what I do is I define a deployment, I add a container to that deployment, and then I expose that deployment via a service which happens to be a type load balancer. So if you notice, you don't really need to include a lot of boiler plate code here, things like selectors, label, and so on and so forth. So this is all go code, quite natural and intuitive, at least to me. Now, what I'm going to do is convert this code into manifest, a YAML file. So I'll go ahead and switch back to that CDKATES CLI I was talking about. And in order to convert my CDKATES code into YAML, all I need to do is call CDKATES and use this command called sub command called SYNTH or synthesize. And if I hit the enter button, it's going to leave its magic and give us and spit out a YAML file, essentially. So this has generated a YAML file in this disk folder. And if I were to walk you through it, again, nothing fancy. All you see is a deployment, just like you would write by hand maybe, or maybe you, you know, by any other way. You have your pod spec, you have your labels, you have your selectors, all the good stuff, all Kubernetes stuff, and you have also a service in this case, which happens to be off of type load balancer. Now, once, like I said earlier, once you have this manifest, it's really up to you. You can, you know, the natural thing is to use kubectl, kubectl apply and then, you know, sort of deploy this to your Kubernetes cluster, but integrating this into your, you know, sort of existing GitOps workflow is something very obvious as well. Now, it's a very interesting topic, but to be honest, I don't have, you know, time to cover that in detail. So I'm going to move on. And any Kubernetes demo is like incomplete without, you know, a hello world engineering thing, right? So let's deploy this thing and see how things go. So what I'm going to do is I'm using, excuse me, I'm using a local Kubernetes cluster here. You can see I have a client cluster already set up and ready for you. So what I'm going to do is apply this, the contents of this disk folder and quickly check how things are going. If I do a kubectl get all, if you see, if you notice that this container, this pod is still in the container creating phase, it has created a load balancer service, which I sort of mentioned or put that, you know, that was there as a part of the code, as well as the deployment and of course, the replica set, which is associated with the deployment. So let's see, I'm going to do a kubectl get pod here and see if it's ready. So yeah, the pod is up and running now, so we can try that out. And I'm going to use the, you know, familiar, I'm just going to, you know, to access the nginx container, I'll just use nginx pod. I'm going to just use, you know, simple port forwarding in this case, right? 1990 to 1990. I'm going to go over to my browser and just go to this page right here, okay? So hello world nginx, but it's good to get something up and running, right? So, and just to make sure, right? If I were to close this, I don't have anything fancy up and running in the background. So if I were to go back and access this, it's not running. So it's actually the thing which I'm running right now, just for you to trust me. All right, so very simple nginx example, but now let me move on to something a slightly more, you know, involved, right? Basic plus plus, so to speak. Now I'm going to show you a WordPress stack that has MySQL database along with the WordPress app itself. So for that, I'll have to switch into another project or another folder here. So let me do that real quick. All right. Okay, so if I were to open this main.go file and scroll up, now I actually, we have two charts here, right? One is for MySQL, which is this chart. And the other one, if I were to scroll down a little bit, and this is for the WordPress chart. Okay. Now as you can, you might note that there's a lot going on here, right? We are defining lots of Kubernetes resources, which includes a secret, you know, a deployment, which is of course expected, and we're adding a container to that deployment. We have environment variables, and we have persistent volume claims and persistent volumes, right? Things, you know, sort of slightly more, you know, beyond the basic Kubernetes, you know, constructs here, and the same goes for the WordPress chart, to be honest, right? Now, this is great. You think, okay, this is amazing, right? I'm able to deploy a, you know, stateful application here, but trust me, you do not want to write these things over and over again, say by multiple teams in an org or in a company. What you ideally want to do is sort of have this as a reusable artifact, and for that, you can use something called custom constructs within CDKs. So let me show that to you as well for that as always. I'm going to move into yet another project, right? And open this main.go file. Now, just imagine, right? Just imagine someone wants to stand up a WordPress cluster. What they can do is simply go in, and the developer can use this custom construct as an API. Just like you were using those deployments and services, right? To CDK its APIs out of the box, you can now use this WordPress custom construct. Now, what is that custom construct? Now, if you notice this new WordPress stack, it's a function. What it actually does is if I go inside it, it actually behind the scenes, it creates something called a construct. Notice that this is not a chart. This is a construct. And within this, the logic of this function is actually the same code, pretty much the same code which you saw earlier. It has now encapsulated much more clearly. It has exposed some configuration, you know, methodologies and so on and so forth, right? So that a developer can easily and flexibly go and define their WordPress cluster, okay? So all right, cool. Then let's go ahead and, you know, what are we waiting for? Let's go ahead and deploy this WordPress cluster on Kubernetes. So the same old thing. You're probably getting bored, but I'll repeat the same thing. CDK its synth. It's going to give me a file, and I'm going to go ahead and, you know, what first I'll keep a watch on the pods here, and then go to a new window and apply the contents of that disk directory of the YAML file which was just created by CDKs, right? So if I were to go back here, if you see things have, you know, started happening, pods are getting created, but I think it's a good time to quickly look at this YAML file, right, which is actually sort of getting provisioned to Kubernetes now. So like you saw in the code, these are the same things. So it's a secret. There is a deployment pod for my MySQL pod for my MySQL sort of, you know, stateful component. There is a PVC, there is a service. Yeah, all the good stuff, right? And the same will apply for the WordPress application as well, deployments and so on and so forth, okay? So while this is happening, I see, all right, awesome. So we have, so the MySQL deployment as well as the WordPress deployment seem to be ready. We can also take a look at the persistent volume here. Yeah, so we have two persistent volumes, and I think we can take a look at the PVC. Yeah, and they are bound to the persistent volumes as well. All right, so far so good. I'm moving quickly in the interest of time, of course. And all right, yeah, let's try out this thing because our pods are ready. Everything, you know, our workplace application should be up and ready for us to access. I have five odd minutes. So all right, let me go back to my browser and access this WordPress on port 8080. So long way out. All right, cool. So local host, port 8080. Let's see what happens. All right, awesome. So what you see is a, you know, sort of brand new vanilla WordPress cluster. You know, this all this is formality. I mean, you can go ahead install WordPress to your liking, you know, do what you want. That's fine. I'm just going to like fool around with this a little bit. And yeah, you can install WordPress, use it as you want. You can log in with that same password, which I just use. And yeah, just good old WordPress on Kubernetes using CDK, right? This is the WordPress admin dashboard. And if I were to remove this and just access 8080, you can sort of access the WordPress site as well. So just a demo, like I said, you can obviously play around with this WordPress site all you want. You can delete the MySQL deployment to see how things go, how the fault already handled and all the good stuff. But I'm going to move on now. I have like five more minutes left, maybe less. So I'm going to look at a slightly, explore a slightly advanced case of how to use CDK ads along with custom resource definitions. Now, if you're not familiar or maybe just as a refresher, custom resources are actually part of the Kubernetes extension API. So just like you have pods and deployments and other native objects, you can define custom ones as well. And it's actually the custom resource definition API that makes it possible in Kubernetes, right? And although CRDs and their implementations are relatively advanced, but at the end of the day, if you want to deploy it, most likely you'll write some YAML code directly or indirectly, right? But with CDK, what you can do is, you can import existing CRDs or existing custom resource definitions and actually use them as API as code, okay? So let me show you an example of a project called Strimsy. I'm a huge fan of Strimsy. I've used it a lot. So it's actually Kubernetes operator that helps you manage and run Kafka on Kubernetes. So let me quickly go into that. Let me open yet another project here. Oops, not this. Type code CRD. And okay, so I actually have these CRDs already installed in my Kubernetes cluster, okay? So as you can see, there are a bunch of CRDs, but I'm going to be using the ones for creating a Kafka cluster and for the topic, right? So Kafka topics. I'll be using this CRD and this one, right? All right, so let's, I'm going to go ahead and import these CRDs using the CDK8s CLI. So the first one, the first CRD I'm going to import is the one which it uses with the Kafka clusters. Let's give it a second. And now the second one is, let me clear this up. And now I'm importing the CRD for handling Kafka topics, okay? All right, cool. Now that's done. I can actually look at the imports folder here. Okay, so if you see, I have two folders here. This is nothing but code, right? This is nothing but code. So I have CRDs available to me as API within my Go code. So I can actually go ahead and use that to define and write code to define a Kafka cluster. To define a Kafka cluster, right? So if I were to go ahead and open this file right here, and if you look at this function called new Kafka chart, what it does is, again, return a CDK8s.chart, but behind the scenes, it uses this function, another function called new Kafka, and it simply defines a cluster. So I have a version. I want to say how many Kafka brokers do I need? I want some broker-related configuration. I can define that. And similarly, I can define ukeeper as well, right? That's that. And, you know, if I were to go into the main.go file, and this is where it's all sort of tied together. Here, what I do is I define an app, and then I add that Kafka cluster of mine, that chart, into that app, and that's it, right? Now, if I were to try and create a Kafka cluster, the same old boring flow, which you have seen earlier, CDK8s synth, it's going to give me a file, a YAML file within my disk folder. It has generated it. If I were to open it and see, you would have typically written this by hand. And this looks quite short because I'm using an example. Otherwise, the configuration and the head-up is actually much more involved. It has services and so on and so forth. So, right, I mean, this is a Kafka sort of CRD and the same old things, the same thing that you saw in the code, right? Now, to apply this, I can simply go ahead and do kubectl apply, nothing too fancy or nothing surprising here. kubectl apply. And this has actually kick-started the creation of a bunch of resources, right? And to be honest, this is going to take some time, like three to five odd minutes, but I don't have that much time. So, because there are a bunch of resources which are going to be created. So, in the interest of time, I'm going to stop here and sort of hop back into my presentation. But before that, let me show you how things are going, right? So, yeah, things are actually running along. Like, pods are getting created, corresponding to the ZooKeeper, my ZooKeeper deployment, the Kafka deployment and all the good stuff, right? So, yeah, I'm not going to wait for this. I'm going to hop back into my presentation because we are at time, actually. I'm going to take just a couple of more minutes. If that's okay. And yeah, that's about it. I could only cover so much in about 20 odd minutes, but just to quickly recap things for you, right? What we covered is the basic CDK8s API and how to bootstrap a project and write a Kubernetes deployment. And then you saw how to use the CDK8s plus API, which provides a better experience in terms of a more natural and intuitive way of writing code. And we also explored how to abstract a way of WordPress as a custom component and then use that on demand to spin up a complete WordPress deployment on Kubernetes. And finally, some advanced stuff, right? Where we imported a custom resource definition as an API and wrote some go code and then kicked off a Kafka cluster on Kubernetes, right? So, lots of things covered in a short amount of time, but really what I'm hoping for you is to think about this concept of infrastructure is code as opposed to infrastructure as code, right? And what you just saw is a code first approach using the programming languages we are familiar with and what we use day in, day out, right? So, if you want to learn more, of course, there are lots of resources you can refer to. Just if I have been writing up a series of blog posts, I think it's about six posts. I've written about three to four. So, check that out. I'm pretty confident it will be helpful for you. But of course, you can read up more on the CDK8s documentation as well. There are lots of examples on GitHub. Of course, there's the API reference as well. So, you can check all that out. So, thanks again for joining and I really, really hope you found this useful and enjoy the rest of your conference. Yes. Hey, thanks Abhishek. It was a really wonderful session with 20 minutes. So, see you.