Check out a free preview of the full Complete Intro to Containers, v2 course
The "Kompose" Lesson is part of the full, Complete Intro to Containers, v2 course featured in this preview video. Here's what you'd learn in this lesson:
Brian migrates the project to Kubernetes using Kompose, a tool for converting Docker Compose projects to container orchestrators such as Kubernetes. The docker-compose.yml configuration file is modified to work with Kompose and the Kubernetes configuration files are generated. The kubectl utility is used to run all three services.
Transcript from the "Kompose" Lesson
[00:00:00]
>> Brian Holt: So that means that we have kubectl, it's installed, and it is ready to interact with our Kubernetes cluster, which is great. Now, we just have to give it some configuration to work with. As you might imagine, something like this requires a lot of configuration, right? Because there's something that Kubernetes can assume about your cluster, you have to basically be very, very explicit.
[00:00:26]
I don't write Kubernetes configurations on the regular I leave that to my DevOps team, and I'm not a DevOps person. So there is a very cool project that we're gonna look at today that's made to get developers Started with Kubernetes. It's called kompose with a K. It's an official project directly from the cloud native foundation.
[00:00:52]
So you can see here it's actually directly on the Kubernetes organization itself. So it's a supported thing, it's been around for years. We're gonna use that and it takes a Docker Compose YAML file and it turns that into Kubernetes configuration. So it's meant to be, you get a bunch of stuff working, you're satisfied with it, now you wanna get it on Kubernetes, Kompose is meant to be that first step.
[00:01:18]
So it's purely just It takes this configuration and translates it into this other configuration. It's like a one step thing you're not gonna use Kompose over and over and over again. At this point you're supposed to like switch over to then, maintaining your Kubernetes files.
>> Brian Holt: So we're just gonna use the same product here.
[00:01:38]
We're gonna make a couple minor modifications, just so that we can get some better output. So first one is yeah, we're just in this the same project here, Docker Compose, and I'm gonna say, links, db, that's fine. We're gonna also add a, depends on.
>> Brian Holt: Db, this is just being more explicit to Kubernetes to say hey, this cannot start until this other thing starts because Kubernetes is very particular.
[00:02:13]
It's okay, I'm gonna start this thing first and then I'll start this thing. So that's good, we want that. There's also this thing called labels that, if you give stuff labels in your Docker Compose things and then you deploy that it'll show you all the labels so it can kind of help you find those things.
[00:02:37]
And it's also just useful for things like traffic, right? And traffic's another ingress server we're not doing traffic, so no thank you. But we're gonna say compose.service.type and there's a node port.
>> Brian Holt: So this is basically saying, I'm gonna run all of this stuff. And then the way that I want you to expose it to the rest of my cluster is on through one port.
[00:03:05]
So it's basically gonna do some load balancing internally for you. And then the other thing that we're gonna do, because this is all being developed locally and we have not published this, typically Kubernetes wants to pull from a registry. It doesn't wanna pull from your local computer. I think that makes sense, right?
[00:03:20]
We're gonna say, kompose.service, no, that service, image, poll, policy. And you can do if not present, that's not what you really want is actually never, because I haven't published this anywhere, so please don't try and pull it from anywhere. We have to be more specific about ports here, you can't just assume.
[00:03:49]
So, that's all that we're doing there. And then web, build web links. This one we have to do, we do have to link it to the API.
>> Brian Holt: And we also have to say depends on API, and then we have to give it some labels as well.
>> Brian Holt: Okay, and this is gonna be compose.service.type.
[00:04:27]
And we want this to be a load balancer, because ultimately that's what nginx is really good at. It does load balancing very well. Load balancer is really just a special type of node port, but what this is signifying to like whenever you go to deploy this to Azure Aks it's gonna instead of making this a node port it's gonna make it into azure front door for you.
[00:04:53]
So it's actually a signal to whatever cloud provider that you're providing is like hey actually want you to take over here and do all my load balancing for me, okay. So luckily this will just be running nginx very likely in production it'll be done by front door whatever when you are traffic or something like that.
[00:05:11]
>> Brian Holt: Kompose service.expose and the answer is true.
>> Brian Holt: Because this is actually a service that we want to be made available publicly. And then, again, this is built, yeah, exactly. Kompose, image pull policy, never, right, because this is built locally so don't expose that. Again, I have a copy of this if you didn't really feel like copying all that down.
[00:05:40]
We go back here, links to the project here. I have a Kubernetes directory here with all of this stuff already done, but specifically the Docker Compose part here. This should all be the same of what you and I just did together. So now that we've done all of that, I think actually what I'm gonna do here is because I did make some minor modifications to make all this stuff work well to get Together.
[00:06:01]
So if you look here, like the Docker file, I actually did give it its own nginx-conf. Rather than run this directly from the project that we were just in, I'm going to go back to my desktop, and I'm just gonna copy that same directory in. So from /personal /containers-projects/Kubernetes, I'm just gonna copy that to here.
[00:06:29]
So if I go into that directory, kubernetes, and see here. And you don't have to do this, but I'm just gonna remove Astrid.yaml.
>> Brian Holt: Now I have as my Docker Compose file, and if you look at that Docker Compose file, it's exactly what you and I just wrote together, right?
[00:06:59]
>> Brian Holt: Okay, cool. Yeah, let's just look at minorly just quickly what I ended up changing for this because I'm sure that's of interest to you, relatively the same projects that I now have an nginx.conf. This was just to handle all ingressive traffic, right. So now that you don't have a separate lease exposed API service, it's all just being routed through nginx, which is what this location API does.
[00:07:32]
Everything else is exactly what you expect it to be. And then the only thing I did here, I think actually, I think I only did it here inside of the source directory is I modified the API to read from the correct area as well. Okay, cool. So what we're gonna do, is we're gonna say Kompose, which by the way, I think you just say brew installed Kompose as well if I'm not mistaken.
[00:08:04]
But I already have it installed so I'm gonna say Kompose convert dash dash build local.
>> Brian Holt: This will take I'll take my Docker Compose file, which it'll find automatically, right, because it's called the right thing. And if I go into my project now, you'll see that I have a bunch of YAML files here.
[00:08:36]
>> Brian Holt: That have a bunch of configurations that you'll see some of the stuff that came in here from Kompose, right? But generally, this is pretty just vanilla Kubernetes kinda stuff.
>> Brian Holt: And we have a service and a deployment for each one of them. The service describes the service itself and the deployment describes how are you going to deploy this when we go to deploy.
[00:09:01]
Now that we have all of these configuration files, generally, what you would do at this point, if you were happy with it is, you would just delete your Docker compose or move it somewhere else. I have intentionally cheated a little bit so that, as you might guess.yaml and .yml the same thing, but I intentionally named them a little bit differently so that I can do, cube control, apply -f for files, quote, the quote's important so make sure you please put the quote in there, asterisk .yaml.
[00:09:37]
You can't apply Docker Compose, that's why I have different file extensions for both of them, and I'm gonna try and get this up and running on Kubernetes. API created, created, created, yeah. Looks like, I say Docker ps I should be able to see everything running so I can see Kubernetes db Kubernetes api, and Kubernetes web.
[00:10:01]
Okay, and now I should be able to say localhost:8080. Is that what I was supposed to do here? This gets a lot more difficult to debug because it's all kind of in various different places, right? So yeah, here we can do kubectl get all. And kinda get the bird's eye view here of what's happening.
[00:10:23]
So this is running, cool. Which is the api, the db, and the web, that's all running. You can see all the ports that are being exposed here. 8080, 27017, yeah, and then I don't expose the API that's why that's not working.
>> Brian Holt: It should be on 8081, which it is.
[00:10:53]
>> Brian Holt: And I might not have gotten the,
>> Brian Holt: It is working, getting a 200 okay. Why is that get not giving what I expect? it is it's just taking a second. Okay, so everything's working except this is all now running on Kubernetes, right? Pretty cool.
>> Brian Holt: So you can see the node port, load balancer, cluster IP just means that like it's not a node port, right, it's just a cluster of IPs.
[00:11:24]
The deployment is ready, so you can roll forward and roll backwards. it's all the magic of Kubernetes. Get info or what was the other two command, I can't remember what it was.
>> Speaker 1: Show?
>> Brian Holt: Is it show info, cluster info there it is. That's what I want kubectrl cluster-info.
[00:11:56]
>> Brian Holt: Some of the stuff you can actually view directly in your browser, it'll actually give you some dashboards. Yeah, let's find that. Advanced, that's fine, except there is some continue, okay. I don't have it set up correctly.
>> Brian Holt: But there's a bunch of stuff you can actually be able to pull out of it.
[00:12:17]
Yeah, it's got core DNS, so it's actually, like, running its own DNS for you inside of itself. I'm sure dump would just be a bunch of stuff. Yeah, it's a ton of stuff that comes out of this, but you can see this is all the logs that are coming out of it.
[00:12:34]
Turns of very cool stuff here. Things like rancher have a, which is like something on top of Kubernetes, give you really nice dashboards, which are also very cool.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops