Kelsey Hightower - Keynote - Pycon 2017

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back for our final plenary session of PyCon 2017 the candle has burned low but there is still a flame left what was initially measured in days then in hours now is best measured in the minutes we have left together I am very happy very excited to announce our closing keynote speaker please help me with a big hand to welcome to the stage mr. Kelsey Hightower hello so this is a this is really an honor for me because my very first speaking opportunity was in Atlanta at Georgia Tech and I went to go see what smart people do when they get off work and apparently they go and they continue talking about technology at meetups and I was learning Python at the time and this is when you went to the bookstore for some of the younger people here there's this place you go and you buy these things they call books and the bigger the book the more knowledge in there so all the Python books are like 10 pounds and I bought one of these books and also I'm going to learn Python and I'm going to go to a meet-up because that's what smart people do and I'm sitting there as you guys are sitting here and I'm watching the speakers like I can totally do that so I emailed the organizer there's this guy named Brandon Rhodes I was like I want to give a talk well have you spoken before nope so I can totally do it like you just do a lightning talk or something so to be smart the first topic I picked was comparing Python list comprehensions with Haskell list comprehensions and no one knows Haskell so if I show up I'm just gonna be a smartest person there it's like how you've never gymnast so when ranan reached out again said hey Kelsey I want you to come speak at this event that I'm running I'll fight well how how big is the Meetup and I get him like damn this is a big Meetup so for a lot of you meetups do change or can change your life the Python community has changed my life my very first conference was PyCon in Atlanta and it ruins you because trust me you guys should clap for that the thing about PyCon that's amazing is really the community a lot of people here I actually heard pay their own way to be here the number of people that stick around for the Sprint's are amazing so my first contributions to Python were pip virtual F and dis utils and since then I've grown on and the world of technology oh yes those are fantastic things so last night I want to write some Python to remind myself of why I fell in love with the language after about 3 or 4 hours I tried to deploy the thing that I wrote and find out the things I didn't like about Python so we're going to talk about kubernetes for piping ystos and the root of this talk I'm not going to try to douse you with all of the things that kubernetes can do but I want to educate you a little bit on what containers are and while they're important to people especially in Python many of these languages have very complex dependency systems and it could be a barrier to entry especially if you're building or distributing software so we're going to go through this and think about this from the very beginning of how you would think about containers helping you okay now heard this is a technical conference so this is my last slide if that's ok let me know I can find lots of cat pictures on the Internet so we're going to be in this mode for a while okay so when I first started learning programming that was about 24 years old and I had that book and I wrote my first hello world program kind of like this one and Python is like magic you write a few lines and you really believe you're a real developer I started applying for jobs immediately after this was done senior developer Python five minutes of experience and you look at this code and you're like wow this is this is pretty awesome so I'm going to run it you always automatically should know what this does so we'll say Python and then we'll say our app py okay this is sweet and then you go to your browser and this is where this is where your life changes for the first time if you're new when you see this this is when you run around your house and your spouse is like what are you doing that is not impressive like let's tell the world why I could do that on a piece of paper but it's important okay now I got brave my first UNIX machine FreeBSD house right free s BSD people are serious they have like tattoos of the mascot like you know that's not ever coming off right so we got this hello world thing going so it's like you know what I'm gonna do I'm gonna run it on my server should be easy I got this one file just @py so you copy it to the server and it's tiny and then you go to type Python and nothing's there and then you become assist at men in FreeBSD you do not install Python the easy way you have to heat your whole house from the server you compile from scratch this is what you do so after about six months I got Python on my machine and the app didn't run and then I needed pip two years later my app was running it wasn't that bad but this is what we're asking people to do when we write code we're asking them to go and figure out what version the Python they have what version of the dependencies they have got forbid if you're using some C extension and trying to use that on a Chromebook it's very funny seeing that an airport like your computer is going to write up battery in about 30 seconds so we have all these dependencies and packaging has come a long way in Python right so we have this ability now to say hey here's here's what my app requires now I can just do pip install and I just did a little tweet I'm going to show you guys what it look like so I'm on I'm on my Mac and I'm writing this test app for the demo I do sudo pip install - you guys are already like what the hell are you doing so I'm like yeah I mean what could go wrong I have Python pre-built on my machine they're like dude the first rule of Python is you don't use system Python I'm like hold my keyboard enter you type in your password right and then it's like you're your enter your info SEC team is like what the hell are you doing nothing works anymore but I have flasks and everything I need on my machine so we're winning like I had to do this so we have our app now and we start to ask ourselves that there has to be a better way of doing this so when I used to contribute to Python I told you we we had dis utils and they used to be a war setup tools this you tools and then we made peace and the whole goal was not to reinvent the wheel let's improve what we have so last night I was like what is the state of the art and Python and it turns out we literally reinvented the wheel I thought this is a joke I was like no no no it's not actually called wheels they're like no this is what you do that's like okay wheels it is so the truth is packaging is a pain point for all languages it's a pain point for all software things that work well are like your mobile device you go to an app store you bring the whole package down and the reason why we can have a billion devices is because we do not ask users to go and install other software to use the software that they're interested in as simple as that but we do the opposite when it comes to servers we were making everyone's life difficult anyone have ever heard of DevOps anyone know what DevOps is I took a stab at it DevOps is good therapy for systems and we needed it largely because of packaging it's not just Python all those packages need to be maintained they need to be updated you write a Python app say hey install this and all this is that managed just sleep so how do we make this better and this is where I think containers become interesting how many people think static linking is a good idea how many people like containers it's amazing to me that so few people think static linking is a good idea but they like containers this is static linking on steroids is a bit tarball with everything a full operating system is in there you're linking everything I saw one container it had like a Chrome browser in it all right what are you doing so what we want to do is how can we leverage these containers in a very smart way so just so everyone's on the same page a container there's two parts to this there's a packaging format the goal is we package all of our dependencies into a tarball it is actually a tarball and as a tarball with a specific format so we know how to download it extract it and be very efficient with layers so we're going to do is build one of these things now i've cache most of this because these days no matter what app you build for some reason it downloads like 2/3 of the internet in order to work but i'll show you what one of these looks like so we have our application so we're going to do is start with the stalker file so the docker file here is you'll see the first line there it says from Ubuntu yes that is an entire operating system to put our 2k application into now there's a reason for this how many people here would say they honestly know all their software dependencies exactly so when you don't know you just bring in everything until it works and then we get DevOps [Laughter] so the next thing that you hear is there's a couple of things happening though we take all the tribal knowledge from wiki's and run books and we put them in the docker file now this is not the best we can do but it is a good stepping stone for the majority of the people building software and we can do clever things like cache some of the layers so even though that first layer is pretty big it's actually about 70 so Meg's we can cache that on the servers so we only have to copy it once for our apps okay so the next thing we're going to do here is going to do apt-get install Python 3 everyone's using Python 3 by now please tell me it happened all right just clap in case it just pretends and then we copy our requirements that txt into place now the goal with this whole thing is that now everyone has a very sane and clean build environment they can build our application you can either give people two raw docker file and they can build it themselves or you can build it and store the artifact right so if you've ever built any package of any kind the goal here is to build an artifact and we'll store it somewhere now once we have the artifact we can give someone the image name and they can run it so we'll just build this here so we can see what we're talking about now my python is rusty so if you see any bad code today please give me a pass do not put it on Twitter I promise to follow pet bait later okay so we have this entry point so this is basically going to do the same thing I was doing on my command line and we're just going to set that in an entry point all right so we're going to make a tarball now this is a very fancy way of doing it so we'll just do this docker build command so here what I'm doing is saying hey I want to build this image and I want to run that command but what I want to do is have all of the requirements be pulled down and run inside of a cheer root environment so that I have a clean bill that's reproducible so we'll run this now okay so the luckily thing is here is that I'm having a bit of caching so I didn't change any of the lines at the top now you could run into issues with some of this caching but the nice thing is when you're building and writing applications you want to iterate fast you do not need to run the whole entire app get command or the PIP command again those live as separate layers so once you have that we can just copy in our application and then we can run it how many people think is really easy to run multiple copies of an app on your machine not a lot of hands how many of you are using virtual ant to solve this problem okay so if you're familiar with virtual m2 give us multiple Python environments you can look at this runtime so this is the other part of the equation once we have this tar ball we can run it under a runtime so let's do this really quick so we'll say docker run alright so what we're going to do here is we're just going to run our app to make it a little bit easier so we'll just run it on five thousand to five thousand so I'll just doing a bit of port mapping so I can get to it we're going to run this hello world app and it's going to run in the background so at this point I should be able to hit it in my browser and there it is now I can run as many copies of this as I want maybe map to different ports but this only solves the laptop problem we have this thing packaged it's easy to distribute it's easy to run as many copies as I want but what happens if I have five or twenty servers that I need to push this to how many people are familiar with scheduling every hand should be up every device that you have has probably more than one CPU core and when you launch an application there's a kernel that has to figure out where this thing runs so you have a really effective scheduler there what most people are doing these days and letting you of a scheduler we call it like the meat cloud okay this is where you say hey run this application and a human decides where it runs and sometimes we track in a very fancy database aka spreadsheet and the problem with this is if one of the machines dies they have this thing called a on call okay machine goes down you get a call and you get to put the app back on the machine so what we want to do is like solve this problem in the way that transfer you know goes a little bit further than our laptop so we have a tool called kubernetes now there's other tools that do very similar things but we're going to work with this for now so I have about five nodes in my cluster now the goal with this is that do not want to statically assign my apps and machines they're designed to go away I want to treat each machine as one collective or like a multi CPU system and treat the whole cluster like a single machine so we need a new API we need some abstractions so once I have this abstraction we can we can package our container and what we call a deployment so let's look at this really quick so we have this deployment object so here is the container we've built and we have it hosted somewhere so anyone that wants to run this app can pull this particular container image now some of you are like well how does the system know where to put this since a lot of people didn't raise their hands about what a scheduler is I'm going to explain it now the fastest way I've done this without diving too deep into computer science and hijacking my whole talk we play a game of tetris so how many people here so they have fully automated deployments okay now this is a worthy goal to get to you click a button and your app installs to specific machines I'm going to show you what that looks like you do that in Tetris I'll show you it looks like it's amazing by the way if you can get to this point so the goal is we want one-click deployment of all of our apps now you need to know a whole bunch of information ahead of time in order for this to work you need to know all error scenarios you need to know if a machine is in maintenance or not and you need to make sure there's no network issues because you need to be able to route around them all in bash Python if you're lucky so we're going to do is this is one click deploy this is the DevOps Holy Grail I'm about to show you be ready you ready one-click deployment BAM long click and then you leave it's fully automated by the way but the problem here is your memory and CPU it's just on the floor and you're losing now we're going to cloud provider this is pretty good actually you spin up more VMs so what does the scheduler do so here's the difference the scheduler has to actually examine every workload as it comes in now this is the like x86 architecture you're not doing anything that fancy but things are slightly different so they have different shapes and sizes the goal is we look at these workloads as they come in and then we make a decision so what kubernetes does out of the box is what we call been packing so let's look at what that looks like so here we see a workload and the goal is just to place it by examining it now we look at these workloads as they come in and what we're doing now is just scheduling in a way that we try to utilize all of our resources so this is memory and CPU I'm looking at all of these workloads coming in now happy you're like wow this dude is really good at Tetris if you can totally talk and play Tetris at the same time okay but this is still been packing that's happening here now you asked why is the scheduler doing this well when we examine all the pieces here what we want to do is make sure that we allocate things in a way that imagine a machine learning job comes that needs that CPU and you've been reserving that special machine because it costs a lot more than run things on it and when the right workload shows up you can place it there and then when it's done you get back all the CPU and memory [Applause] he got a Tetris on Twitter so that's kind of the difference between just automation and this idea of orchestration we want to have this online examination of every workload so we can actually use our machines effectively and the goal here is that we want to be able to reuse CPU and memory the best way we can so it's part orchestration so how do we do that for our own applications so for our own apps we have to make this the deployment descriptor now it's a big mo Fallon's declarative but what you'll see here is that we have our app name is called hello world and then we're saying kubernetes when you run this thing I want you to go grab this particular image and when you grab that image I want you to extract it and run whatever the entry point was Python at py and then I want you to also shape this workload now the thing you got to think about in order for us to schedule these things properly we need to know the shape of the piece this is why we have our memory and our CPU requests so we know where it fits in that cluster okay so once we have this we can actually give it to kubernetes so coups et al get pods so what we'll do is we'll create this deployment object now can anyone tell me what machine that it landed on there's a brave guy like ah number four like no the scheduler is going to figure out at runtime the only thing we are asking is that we declare that we want one of these things running so I say cout CTO get pods will see that it's running somewhere now the nice thing about this let's look at what machine it's on so it's on n f6p and it has its own IP address dot 90 but what happens we were to destroy it we're going to destroy the workload now depending on where you work you either fired or you're going to get a call so we delete the workload and this is what we expect we expect it to be replaced quickly and it has a new IP and a nice thing about a system like this is when we replace the workload we keep track of it we know its IP address so we can hook it up to the load balancer automatically now if you've been doing this kind of work this is just from decades of people doing these patterns and now we've just baked it into the infrastructure itself it's kind of like the Python standard library it's massive because there's no reason for people to rewrite these things over and over again so these are things with pretty standard issue if I look here get SVC we'll see that we have a load balancer that's routing traffic to all of those so no matter what I do I have the stable end point where I can hit my application and there we go it's up and running then it gets really complex just like you can't run production Python by just using flask anyone know why one request at a time I spent the hour figuring that out like why is my show hanging one request at a time so what do we do so in the Python world it's common to pair it with maybe some whisky server or nginx so what does that look like in kubernetes now I'm about to show you a lot more on the screen so be prepared so in the container world one would say you build an even bigger docker file and you install nginx in there you put your whiskey in there and then you take a script to launch all of that in the background great you just invented an init system there's no reason to do that what's a better approach well we don't want to pack engine X inside of our Apps container we want those to be separate so what does that look like if you separate them so here's another deployment object and this time we'll do things and this is a lot here I'm going to walk us through it really quick so we all can understand this has multiple containers in them that we can stack think of it like a virtual machine they're just going to run as processes that are co-located together to form the logical app so at the top we have nginx we're using nginx graceful shutdown and then what we also are telling engine next to do you'll notice here in this particular line here we're going to share this particular path and what's going to be there is going to be our whiskey UNIX socket that is exported from our apps so we can actually send traffic to it in the way proposed by their particular Doc's so here we are sharing a filesystem one container is going to write its socket there and another container is going to pick it up and send traffic to it but the nice thing about this is everyone knows how your infrastructure is composed and your next stands alone and the app stands alone so at this point we can actually have kubernetes manage this for us as well Coop's ETL create - F deployments alright so once this is on line get pods great and you'll see that there's two of two ready so we can actually compose these things if you need any helpers you can run your helper scripts as well now once you have infrastructure like this you start to think about why do I need to use conventional ways of interacting with it I've been using command-line tools this whole time so in the Python world one thing that has been amazing over time in Python Python has been used as a facade for more complex systems like tensorflow most big data stacks Python makes it super easy to interact with things so if I were building new tools how would I interact with this now I think if more Python people showed up to the Kerberos community they would also look to simplify things so I found a really good Python library so I wrote a new interface to Python and this is the first time I'm going to show it to anybody ok so if it doesn't work remember well this yesterday so bear with me ok so we're going to do is going to clean up here a little bit get pods Coop's ETL we're going to delete these deployments so it's really easy to spin these things up and down let's clear them out and keep in mind the frame of reference I'm coming from I've been watching a Star Trek The Next Generation for some reason on Netflix so I really believe I'm living in the future right now so when I want to go build this thing I wanted something that felt like that okay so let's just do a watch on here I'm going to show you my new tool as you can tell them a bit shy here so please don't laugh at me if this doesn't work all right so this should terminate let's clean things up man do you know what it's doing trying to gracefully shutdown all right we're down okay so we're going to try this thing so the app I'm using was shipped on Wednesday so this is just double not smart on conference Wi-Fi okay google talk to kubernetes well we need we may have to go to airplane mode because I might need the bandwidth okay okay Google you better work as people are watching I spent all night on this too so talk to kubernetes no way hold on we're not going to abandon ship on this I will be up here for six hours if I have to you just ignore the whole speaker timer okay google talk to kubernetes what is sitting here like oh let's do this let's do this maybe maybe you have to hit the test button maybe we need that but you guys like when the live demo doesn't go well he like he's gonna fail I know it my apologies I don't understand talk to kubernetes this is the top result talk to kubernetes here's the top search result it's trolling me okay google talk to kubernetes sure here is the test version of kubernetes cluster hello Kelsey hi looks like you have a large crowd this time I hope the demo gods are on your side what's my cluster status the PyCon cluster is running with ten CPUs and 37.5 gigs of ram run the hello world application what image tag would you like to deploy 1.0 deploying hello world 1.0 into the PyCon cluster so we got an app running scale the hello world deployment how many replicas would you like 500 divided by like 10 - 40 - 5 5 5 scaling the hello world deployment - 5 [Applause] now here's the thing it's easy to do deployments how many people have ever done zero downtime deployment you liars you still got on call but no it's a tough thing to do so the Holy Grail is to do these downtime zero downtime deployment so we have one dotto running right now inside of our cluster and the goal is we want to upgrade this so this is the nice thing about this fully API driven world from the networking to the stores to the app itself also around auto-scaling so what we want to do here is see if we could update this in place without dropping any of the packets here okay update the hello world deployment what version of the application would you like to deploy 2.0 updating the hello world deployment to version 2.0 thank you okay I gotta admit that was pretty dope and with that I would like to end the presentation thank you so much [Applause] another round of applause for Kelsey Hightower
Info
Channel: PyCon 2017
Views: 29,307
Rating: 4.9543228 out of 5
Keywords:
Id: u_iAXzy3xBA
Channel Id: undefined
Length: 33min 23sec (2003 seconds)
Published: Sun May 21 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.