Migrating an app from Docker Compose to Kubernetes: step 1, proof of concept with Kompose

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the application that we're going to migrate from docker compose to kubernetes is a piece of open-source software called tell form it's basically an alternative to Google Forms or type form or something like that so it gives you a really nice interface to create a variety of forms and then it's got features for analytics and managing the answers the forms and all that kind of stuff this project already has a docker compose file if we take a look at that we can get a quick overview of the different components here so we have a Redis instance we have MongoDB we have the tel form app itself and then we have a service called web which is basically nginx that's sitting in front of the tell form app so the first thing I want to do is see if I can get this running locally on my machine with docker compose just to make sure there's no surprises so I cloned the project you do docker compose up to bring it up man I saw some errors there but maybe that's fine you okay cool and here it is I already poked around at the docks a little bit so I know that the username is root and the password is also root and yeah now we have the software we can create a form called whatever add a new field to the form etc I'm not going to go too deep into how the actual software works were more interested in the process of moving it to coop alright so flipping over to the docker compose file again now locally one thing that we could do is go through this chunk by chunk and create the kubernetes equivalents and write manifests for them manually and that kind of thing what I'm gonna do instead though to get a proof-of-concept running is use this really cool tool called compose which will take this docker compose file and turn it into kubernetes manifests so let's see what that looks like compose convert docker compose and we'll call the output coop manifests oops okay and now we're going to have a file here called Kubb manifests so you can see what it's done is generate a bunch of coop manifests it looks like we have about close to 200 lines worth which is notably longer than the docker compose file which was about 50 lines let's just try running it and see what happens before going through all the details of what happened here so I'm working on a Mac I have kubernetes running on top of docker for Mac what I'm going to do is coop cuddle apply - chef coop manifests and ok looks like we've created a couple services a few deployments and a persistent volume claim the next thing I'm going to do is take a look at the pods and see if these are running as expected and the first obvious problem here is that these two bottom pods tell form and web are stuck an image pulled back off let's take a look at what that's all about in the docker compose file we are actually building the images locally for those two and bypassing in this context key rather than pulling the image from a registry like docker hub I spent a little bit of time playing around with this before I started rolling on the video so I know that the image that's in the public registry is actually different than the one that's being built locally so I'm not gonna uncomment this and use the one in the public registry because I'm not sure that that's going to actually work what I'm gonna do instead is and this is just to get it running locally we're gonna have to change this eventually but for those two images tell form and web what I'm gonna do is add an image pool policy of never and I'm also gonna change the image name so that it properly references the images that are already built locally on my machine because of the fact that I did it through docker compose a minute ago and I know that by doing by doing docker images grep tell form you can see they're called tell form web and tell form tell form alright let's go back and apply to manifest again of course I spelled it wrong need to use capitalization okay cool so let's go back to looking at the pods so far so good it says it's running let's try hitting it at localhost we're not seeing anything so let's take a look at what the story is with the Kubb services so get services ok so we see tell form and web but web has no external IP so it actually so web is nginx and that's where we want to make the request from our browser but there's no external IP so on docker for Mac if I make the service the type load balancer then it will expose the service to my local machine let's find the let's find the web service here it is and let's give it load-balanced sir we'll update that then let's take a look at the services again now web is being exposed on localhost so let's try hitting localhost again it's not quite doing what we want right we're not seeing a response so let's take a look in the logs here actually the first thing that I'm going to do before even looking in the logs I'm going to see if it's possible for us to hit the tell form pod directly and the till form pod is listening on port 5,000 so we're just going to map our local machines port 5000 to 5000 in the container and let's try visiting that okay that doesn't seem to be doing what we had hoped so let's take a look at the logs in that pot and see what's going on you okay so there's a bunch of potential problems here right no such file or directory dem unable to find logging file configuration deprecation warning could not connect to again I already played around with this a little bit before I started rolling the film and the real problem here is that we're unable to connect a the other ones are kind of just noise so could not connect to this IP and this port to 701 7 let's take a look at the configuration around this let's take a look among go so here's our deployment and persistent volume claim backing it up so here is the tell form deployment this is like the pod that we're taking a look at right now and there's an environment variable MongoDB URI which is passing in a URI for the application to find I think this is our problem so this identifier that made sense with docker compose no longer makes sense and and actually let's take a look at if we have a service for I don't think that we do this is up here's the till form service and down here is the web slash nginx service so I think that what we actually need here is we need to create a service for so that we have a stable way to reference it from the other service so let's do that compose did this as a list I'm going to just create a separate Yambol document so we're adding a new service we're calling it and what it's going to do is it's going to select based on the label that's on that deployment that was tacked on there by compose if we search for that I Oh doc impose on service equals then yeah we see it over here as well we're putting up a service that's going to target the pods of that deployment and then the next thing we're going to do back over here where we pass in a reference to we're gonna use the conventions put in place by the kubernetes service discovery stuff to to find so it's just going to be to 701 7 okay cool let's try applying that and take a look at the pods so we have a new pod running let's look at the logs there and it's still complaining about things but it is not complaining about being unable to connect a so that seems promising let's go back and try localhost again okay great and let's see if we can login perfect let's take a look at this and get a rough idea of what exactly the composed tool did it generated a bunch of kubernetes manifests this is a service for tell form so what it did was it created a service for each one of the docker compose services that publishes ports so that's the tell forum one and the web nginx one you'll see over here that there are two services till form and web we also want a service for so we wrote that one ourselves on each of the kubernetes objects compose put some annotations to indicate where it came from and it also added some labels in the docker composed file we see that the service made use of a volume and for that reason the composed tool created a persistent volume claim that would be referenced by the deployment and as you can see each one of the docker composed services got compiled to a kubernetes deployment our starting point docker compose file was relatively simple and so the resulting Kubb manifests were also pretty simple but if you're starting from a totally busted situation with the docker compose file the composed tools not going to magically be able to write reasonable Kubb manifests they're also going to be super busted and doing wack stuff using this tool compose is a really neat way to quickly port something over from docker compose to kubernetes manifests and get a taste of what kind of problems you're gonna run into next so we've been able to get a proof-of-concept up and running really quickly but we actually have a bunch of things that are busted for example there's still several errors in the main application logs and I assume that the application doesn't work 100% at this time it's just running at a kind of basic level we're also running two stateful services now inside of kubernetes MongoDB and Redis and we would probably want to think about doing those as stateful sets or even not running those in cluster and instead modifying things and just passing in a string to an externally managed service or something like that using compose is a really neat way to quickly get something up and running and get a sense of kind of the shape of what this is going to be like in kubernetes and then you can take those manifests that it generated and iterate on each piece individually or even just use it as kind of an idea and throw it away and start over from scratch with a better sense of what you have coming
Info
Channel: Stuart Sandine
Views: 7,712
Rating: 4.9080458 out of 5
Keywords: kubernetes, k8s, kompose, docker-compose, docker, nodejs, node.js, kube
Id: _-GGgMRITLc
Channel Id: undefined
Length: 12min 58sec (778 seconds)
Published: Tue Aug 13 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.