Spring Cloud on Kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to talk this talk on spring cloud on kubernetes how did everyone enjoy the keynotes yes did you are you guys all here because of all the talk about Cooper Nettie's you changed your mind okay we both appreciate you guys coming it's really exciting to see so many people here to hear this talk so with that let's get started we have a lot of content to cover we hope to give you guys some opportunity to answer some question the answers at the ask some questions at the end so we want to make sure we have enough time this is the best slide in the presentation right here please read it very fast because I'm about to change it in about two seconds so Who am I I wish I knew my name is Ryan Baxter I'm a software engineer on the spring cloud team at pivotal so I work on various different spring cloud related projects everything from spring cloud netflix to kubernetes obviously the config server I've had my hand in the latest and greatest circuit breaker project so various different things in my time at pivotal I've been a pivotal for about three years before that I worked at a very small company called IBM and when I'm not writing code or working I have a family that keeps me fairly busy so I have two little kids a daughter and a son and my wife also so that's a little bit about me I let Alex introduce himself hi everyone my name's Alexander jamón as you may heard I'm a French I'm from Paris I work as a platform architect working at pivotal Paris and my job is to help our customers to to to use pivotal solutions such as people to a platform but also the Spring Framework the spring cloud and everything we have in the pivotal services marketplace so I joined the company one year ago this is my first time in Austin first time participating to a spring one platform and very happy to be here and to uh to show with Ryan what we can do with spring cloud communities thank you and as you heard I am NOT French so so this is just what we're going to talk about today we're gonna talk about what Sprint what Spring what is Spring cloud kubernetes give you a little background there most of the time is gonna be spent giving demos which I'm sure you all appreciate and then we're gonna talk a little bit about something called native kubernetes implementations at the end just to talk about something a little bit different so that let's get started so as developers we have a lot of choices around the various technologies we use right and one of those choices we have to decide is where are we going to deploy our applications to right and this used to be a very simple choice even just a few years ago when I got into the cloud space this diagram looked far simpler there were really kind of only two pieces there there was infrastructure as a service and platform of the service and it's grown it seems like every year there's something new here that we add right and the platform the type of platform we choose is really just that the only difference is the level of control we're giving up to the platform versus the local control or what we control as the developer right so if we go to one extreme I think everyone's familiar with at this point is infrastructure as a service right where the platform just the the platform provides the hardware in the virtualization and then we get to control everything from the operating system up right and you go to the other extreme where we have functions as a service where basically the only thing we're deploying is a small piece of code not even an entire application and the platform controls everything below that right so it's it's about what you want to have control over and what you don't want to have control over but in between we have two different choices right so I think everyone's familiar with a platform as a service at this point II Cloud Foundry I think most people are familiar with that but there is this in-between state between platform as a service and content and interest service and that's containers of service and generally these platform of the service are actually using containers under the covers or you can see that and that's one of the layers there but if you want containers have a lot of advantages especially for specific types of applications that might need a little bit more control about you know your environment that they're running in and so and they're nice and portable and they can easily be moved from one environment to the next so they have a lot of advantages but from a spring cloud perspective we don't we've never really cared right I don't care if you want to run on an infrastructure of the service or you're gonna run on some bare metal hardware that you have underneath your desk in your office so we have solutions for all these different various platforms and we generally integrate pretty well with the various different cloud providers the other thing is pretty cool when we start to talk about containers is that it's very easy to get boot apps running inside of a docker container for example right if you go to this URL here we have a nice guide up on the spring guide site that shows you how to dock our I as a boot application and the things we love about spring boo all right this is the guide here nope that's not that good this is the guide the things that we love about spring boot make it very easy to put it in a docker container right because after you do your maven or Gradle build what you end up with is a jar file and all you got to do is Java desk jar and execute that jar file and the app starts up right so your docker file to get the app running really only requires a JDK and once you have the JDK there in the container the app runs right that's the only requirement so you can see here just to dock our eyes quote-unquote Abood app is it's fairly simple doesn't take much to do it so that's all well and good but in a cloud architecture where we have you know not just one of these containers or two of these containers we have potentially hundreds of these containers your your left you know what do you do with all them right how do you manage these containers right how do you make sure that they're all running how do you make sure they're healthy how do you make sure something happens to one of them that automatically gets restarted how do you make sure that you how do you do all the networking between all the - all the containers right all this stuff is something that docker doesn't solve out of the box it just provides you with a container right but if you have lots of these containers what do you do right so that's about that's where kubernetes comes in kubernetes is kind of your imagine it as your container management system right who here is already familiar using kubernetes today lahter yes cool so so a lot of you already know what kubernetes is right so we can deploy our containers there and run our apps and and it takes care of all that hard stuff that we don't really want to have to worry about as developers but when we think about layering not just running boot apps in in kubernetes but also adding spring cloud on top of that what does that look like well it's kind of a up until recently has been kind of of a kind of a iffy situation right if you're familiar with some of the traditional spring cloud stuff we have things like spring cloud Netflix which has a Eureka server which provides service discovery and service registry we have a ribbon there for load balancing we have some circuit breaker stuff right we have a config server that externalizes configuration but when you look at kubernetes and you start to learn more about what kubernetes provides willow per product provides a lot of this stuff already right it has the concept of a service registry and service discovery it has the concept of externalizing configuration via config maps and secrets it does load balancing to some extent at the service layer right so it has a lot of these things already there in it right but if you're familiar with spring cloud we know that we've abstracted a lot of these concepts out right we have interfaces for some of these things the and we have different implementations not just spring cloud Netflix that provides the implementation we have things like zookeeper and console and other things integration with other cloud platforms that implement all these interfaces so as you move your applications around right we don't care your code doesn't have to change depending on the platform you're running on we just adapt and make it work so this is where spring cloud kubernetes comes in and Alex is gonna tell you a little bit about that thanks Ryan so what is spring cloud technologies so it's time to go deep dive on this framework and see what we can do with this framework so the idea is to write portable apps using spring cloud as soon as you have you start with using spring boot as soon as you add the spring cloud kubernetes to your project as a dependency that's all the things that you need to do you don't need to update your source code you don't need to adapt your application in order to deploy your application to sprinkler to to communities and this is a great feature because you just keep the same source code and you can just deploy your application to privileges with no time which very easy and no matter which environment you use using spring cloud you have the right abstraction platform abstraction toward to do this and the good thing with the sprinkler kubernetes is that it provides a seamless integration with everything you know about Spring boot and Spring cloud you don't need to learn new features you don't need to to to to we learn everything that you would've done with the spring but if you know how to develop a spring boot up then you already know how to leverage sprinkler theologies and sprinkle equivalent it is available publishes since early this early this year so let's go into details and see what we can do first things using spring calculate is you have native config map and see with support with your application which means that as soon as you edit a config map file with your kubernetes clusters then the your application will be will be able to read this configuration the only thing you need to do is to just use the thing that you need that you already do with the Springbok springboard so just use add value just use add configuration properties just like the thing that you already know about spring boot and using spring cut abilities you have native support for reading this config map that you use with cuba cutter and the same thing is with secret to to load credentials for your application and a nice feature from sprinkler humanities is that as soon as you update your config map you have the ability ability to automatically reload your application which means that you don't even need to kill your pod or to redeploy your the wall application you can just apply the new configuration live without reloading your application that's that's a nice feature another nice feature from sprinkler kubernetes is a native service discovery which means that when you have many quality services that you declare with within your application then using sprinkler abilities you have a discovery client implementation coming for free which means that you don't even need to deploy Netflix Eureka server to your communities cluster the only thing you need to to do is to add these pink cloud kubernetes dependency with your with your application and then as soon as you you use the add load-balanced annotation if you are using the discovery client service available in spring boots and spring cloud then you will automatically discover available services within your communities cluster and there is nothing else to do to leverage this and the nice thing about sprinkler kubernetes it's that it's already leveraging the the new spring cloud circuit breaker abstraction which means that you can just leverage Netflix tricks and resilience for j4 your application just by reusing everything you know you already know about spring boot and spring cloud and the right thing about sprinkler kubernetes is that you also have access to the pod elf indicator which means that using this endpoint you will know if your application is running fine so you will have access to all environment variables that are made available to your application and you have a quick peek about what's going on with your pod is this pod holding is everything ok just eat the slash actuator slash off and you have everything you need to know about your application running on privileges the last thing I wanted to show you is the fact that if you need to provide custom configuration for your application then the only thing you need to know how to do is to create a file application - privileges dot Yamal or dot properties and you're done sometimes you need to provide custom configuration for your application and if you need to set specific properties that are only available and only enabled if your application is running with communities then this is the way to do just create this file and as soon as the application will start this configuration will be loaded for you and you have nothing else to do so enough talking we this is this this was a quick introduction to sprinkler kubernetes and we have about 200 Ryan and what you're about to see is how to deploy your cloud native application to humanity's library leveraging deployment generation so you see how to that how to deploy an application without ever writing a Yama file you see service discovery in action and we will also show you how to do load balancing within the the your kubernetes cluster and also config map support with the application so now back to you Ryan it's demo time thanks Alex all right so if at any point you can't see something and you want to see something just yell at me and let me know and I can make things bigger or try to explain it so I'll do the best I can here so we have a couple of basic applications here which is kind of fictional ecommerce micro services applications this has a couple of services I know you can't see probably some of the the project layout here but I'll describe it it's very basic there's three different services there's a fashion service a hot deal service and a toy service each one of these services just returns some products right some fashion items and toys or some items that might be on sale via the hot deal service right and these are basic boot apps there's nothing there's nothing special about them each one of them looks pretty much exactly the same there is your your main application here and then there is a rest controller that just returns a static list of items here okay so nothing fancy going on in any of those apps the fourth app is a gateway which is leveraging spring cloud gateway which we just heard about a little bit about in the in the keynote here and there's a lot of other sessions that will go into the details of how to use the gateway and all that stuff I'm not going to do it today but basically we just created some routes in our gateway that are going to route traffic from the Gateway to these micro services that are sitting behind that and the Gateway also contains its own endpoint here which is called start page which basically aggregates all the information from the other services together and returns it in one giant response for you know applications that might want well everything in one one response instead of having to create each service individually that won't make sense everyone all right so right now the app is just using your basic spring cloud stuff right nothing is not using there's nothing here about kubernetes or anything just basic spring cloud netflix stuff so I'm gonna start the apps they're going to register with a eureka server that I already have running and we're just gonna run them locally see how they work so everyone gets an idea about that and then we're going to show how to take these apps and then get the same apps running on kubernetes okay so each one these apps like I said is going to start up they're all going to register with Eureka and start the Gateway as well like I said I have a Eureka server already running here so this is just running locally on my machine right you can see all the apps have registered here as I started up so nothing crazy going on here if we look at what these apps do so if we go to 808 one I gotta remember all the the right ports or everything it area so this is the toys service right it just returns you a JSON array of toys right the fashion service is 808 - so forget a fashion slash best seller at 8:08 - same deal and then the hot deal service if you can see a pattern here in the port is a 283 all right so nothing fancy going on there the gateway you can then route request to any of those service so if I go to slash toys slash best seller you can see I get the information from the toy service same thing with the fashion service right so these are all the routes that I created in my gateway and then lastly the hot deals right and then I mentioned also that we have another endpoint called start page on the gateway so if we go to slash start page you can see we get everything all right so we have the toys we have the fashion items and the hot deals all here right so one of the cool things that we have with the gateway is integration so we have you can provide resiliency at your at the gateway level right so we've integrated circuit breakers at the gateway so when we're out a request like this to slash start page and everything gets you know the gateway makes request all the different services they're all wrapped in a circuit breaker so if anything goes wrong there we can provide some resiliency so one of the so another tool that I'm using here in the apps if everyone's familiar with Cass engineering is this really cool tool called chaos monkey for spring boot which basically allows you to implement chaos engineering principles into your spring boot apps so one of the things this tool will do which is really cool is just inject random latency in to rest controllers right so I hit a rest controller and every so often randomly it's gonna hit a delay and be very very slow to respond right so this is one of the areas where you might want to think about providing resiliency in your applications using something like a circuit breaker to trip that circuit breaker when the app is just taking way too long to respond right so I'm gonna enable chaos monkey here on the toy service so if I make a post request to this actuator endpoint you can see that we've enabled chaos monkey so now if I hit 8:07 those toys slash seller randomly this should take a few seconds to respond and the best part about random things that happen in demos is you never know when it's gonna happen so you can see here whoa now I really can't see anything in here that was not no okay that's the first time that has happened in about three years of giving live demos alright I promise that wasn't part of my chaos engineering down there we go all right that was not part of my chaos engineering demo all right that should all be awesome on the video recording so you can see here it took too long to respond we hit the the circuit breaker got tripped and we returned an empty array you could be more creative and return some cash data here if you wanted to I'm not that creative but you do see here that we got the fallback response from the Gateway so that's just indicating that we just got a fallback all right now what this looks like when you do when you hit the start page is that that you'll see here okay so there it got tripped right so we get this we get this status response and this in the start page telling us that we hit the fallback and you know we get the fallback date and all that stuff right so that's basically how the apps work anyone have any questions about that before we move on to the next part all right cool you guys are all very smart thank you all right so now write this this whole session is about kubernetes right so what we want to do is get these apps running on kubernetes right and in an ideal world we can we want to do this just without making any code changes right I don't want to touch a single line of code I just want to maybe manipulate some configuration properties maybe add maybe add a configuration properties file for kubernetes specifically and and do some stuff that way right so obviously the first thing we need to do here is actually add the spring cloud kubernetes the pensee right so in our parent palm we have our or importing the spring cloud bomb here okay so we have that or adding that dependency and so in each of these projects we need to go ahead and add the dependencies for spring cloud kubernetes right so we'll add a new dependency here and it's spring cloud starter kubernetes and the group ID is four okay we just add that starter there and when the starters on the class pass one is one of the things that's going to do that Alex had mentioned is that it will automatically detect when it is running in a kubernetes environment and it's going to enable that kubernetes profile all right there's gonna be important for kind of transitioning things from one environment to the next right so right now we run the app locally and we run we want to run the app in kubernetes right so when we run the app locally so in our default application properties we're just going to disable spring cloud programs to make sure it's not doing anything right so we'll say spring cloud kubernetes enabled bulbs all right and we're gonna add another configuration properties file here specifically for kubernetes so application - kubernetes Emmel okay and here what we're gonna do is say since we're running on kubernetes we don't need eureka anymore all right we're going to take advantage of kubernetes service discovery so we're gonna say Eureka client enabled faults all right and in obviously in this case we want to enable spring cloud kubernetes so I'll say spring cloud kubernetes enabled true alright that makes all sense that's all we have to do that's really it okay now these app is ready to be deployed the grenades we do need to dock your eyes this thing right there we need to put it in a docker container since I told you that every boot app looks exactly the same when dock when we're creating a docker container I've already added docker files for each one of these things and this you know we'll just go to that guide you can copy and paste that code and throw it in your application it will work exactly the same that's basically what I did here and to save us a bunch of time I've already pushed these built these containers push them to a registry so that's all done so we don't have to watch the magic of the network actually take place here live so that's done as well the other thing we need to deploy something kubernetes is generally you'll create a deployment for an app you'll create a service for an app you might as part of doing that create a configure health checks you might add specific environment variables all the stuff and the way kubernetes does all these things is through the magic of y amal now I don't really mind ya know like when I have to write this amount of yamo I don't mind it but when you do this in kubernetes it's a lot of gamble it's a lot and every time I need to do it I have to go back to the kubernetes documentation you know figure out what the right properties are and type it all in and it takes me forever and it's really annoying but someone told me about this really cool tool that I'm gonna use today just so it's not as annoying called decorate this is specifically for Java apps and they have some nice integration with spring boot so it inspects things like your application dot properties the pom file I'll get everyone get out their cameras and take a picture of this lock is really cool I really like it so it inspects those things and it will automatically generate the yamo for you for the most part right and you can tweak things if it doesn't generate exactly the way you want but it integrates as part of your maven build so when you run maven clean package or install or whatever when you run that goal it will automatically create this UML file for you so I'm gonna use this tool and you'll see how much time it's actually going to save us so I'm just going to go down here and in our parent pom I'm gonna add another dependency to our dependency management section here for decorate so they have a spring starter specifically and then I'll go up to our fashion application and I will add that dependency as well okay and the one thing I already know that I'm gonna have to tweak about the yamo that it's gonna generate so by default the service that it creates the service animal is going to be a cluster server side for cluster IP but I want to be able to access each one of these services and demo you to make sure that the rest points are working and all that stuff so an easy way to do that is and expose each service via a node port so instead of using cluster IP I'm gonna just configure this slightly to expose and the service as a new port so really the cool way to do that is just via some configuration properties so decorate kubernetes service type it was gonna be a node port okay that's the only thing I'm gonna do and now I'm just gonna build this thing so it generates our ml so I'm going to CD into the fashion app I'm gonna run maven clean path whoops not capslock mean package and then I'm gonna do something that no one should ever do I'm going to skip tests in the interest of time I promise everything passes I just want to make sure that this is we have enough time so once that runs if we look in the target folder here under classes meta in decorate we have this y ml file all right and for those that you love yeah Mille you'll be very excited about this but I'm very excited mainly because I didn't have to write it all and you didn't have to watch me do that so it generates a lot of things right like I said it inspects things like the the port the server dock port property to come up with the container port at the right container port it sees that actuator is on the classpath so it automatically sets up liveliness and readiness probes for kubernetes it determines the image name based on my user name from my machine as well as the application ID and a a handful of other things here it sees that this will explain this a little bit later explicit spring cloud kubernetes is on the classpath and creates some roll bindings and servers accounts for spring cloud cover needs to use so it does a lot of stuff that I would have had to done do by hand that I'm thankful that I don't have to do and I'm sure you are all also thankful but that's enough Yammer for today ok so we want to get the app deployed the kubernetes so I have for those of you not familiar with kubernetes a really easy way to get started with kubernetes is if you're on a Mac or Windows and you use docker desktop if you go to docker desktop and you go to the preferences here there's a kubernetes thing here right you can just click enable kubernetes and it sets up a local kubernetes cluster for you which is really nice and easy for development so that's what I use I really liked it I like it a little bit better than mini queue but I've had a lot more or I've had a lot less issues with docker desktop and I have with mini cubes so I have that running on my machine I have this other nice little tool called k-9s which is just gonna kind of give us a visual representation of things that get deployed to kubernetes the local kubernetes cluster ok so what I'm gonna do is use Kubb CTL to create our or deploy that yamo file so be easier if I do this there so that's our UML file that was generated if I run that yep yeah I had mentioned earlier that I already did all that stuff built the docker image deploy you know created all that stuff ahead of time just so we're not doing that well I stink of stuff yeah yeah there's nothing nothing special about that it's just just because it's a plain old building docker right okay so we can see that we got our deployment here for the fashion service is there the pod will hopefully come up fairly quickly here for that deployment you'll also see that there so the the pods up right so there's a service that got created as well see that service is here and if we look at that service we'll see that it has that node port exposed here all right so here's the new port for the fashion a seller app so we can hit that node port so if we go to that port slash fashion slash best seller there so the app is running in kubernetes and returning the data we expect so now we want to do the same thing for all the other apps right so the cool thing is that once you've done it once it's really easy to do it again and the reason why it's really easy to do it again is because I've created a patch to just do it so instead of having me go through do the same stuff for each one of the other apps I'm just going to apply a get patch on top of this thing that's going to do all that stuff I just did for the fashions app for the other apps okay just in the interest of time I just want to save everyone the pain of having to watch me do that okay so apply that patch and like we said just to make sure you know we look if you look at the gateway palm for example we have the kubernetes starters as well as the decorate starter is somewhere here be somewhere there right there so and then also each one now has a efficient kubernetes file with the same stuff in it that we had before in the in the fashions app okay and again I've already built all the docker images for these apps and and in my local docker registry so we don't have to do that but what we do have to do is run the build to generate the yamo files that so we can deploy all these apps to kubernetes trains so I'm just gonna go which directory I'm in the right directory now yeah I'm gonna run say maven come in again don't don't do this at home yeah look folks I'll get about this now and that all happens so now each one of these apps also has their kubernetes EML created for them right so now all I need to do is get these all deployed to kubernetes oh one thing before I do that so remember how I enabled chaos monkey in the toy service and I hit that actuator endpoint to do that when I was running locally well I want to demo one of the other things that Alex talked about and that is externalizing configuration via config Maps so I'm going to externalize the property to enable chaos monkey to a config map right so if we look in the toys by cellar app here I have this config map yeah mo and this is just a demo file as you might expect for for that that property and so once spring cloud kubernetes is enabled it will look for a config map of the net with the name of the application in this case toys bestseller and apply in properties that it finds in there as a property source in the boot app alright so I'm gonna create this config map as well in kubernetes so gue CTO create here that's our config map so if we now go to there we see we have that config map and if we look at the ml we have that sets of faults right okay so I'll just keep that in mind and now we're going to group CTL creates fashion so toys groups eto create hot deals and then create gateway alright so so we have our services for all those I'll come back to that in a second we have our deployments for everything because everything comes up here so we have the toys app running hot deals app is running gateways coming up as we speak so let's go back to the services I'm going to look up some node ports for these apps so for example Hot Deals you'll see that the node port is here so law Hot Deals there we go that's working let's look at the toys app and this is the node port for that and I'm gonna do a couple other things with this toys app first so one thing I wanted to show so Alex had mentioned about the integration with the health endpoint of the actuator health endpoint so I'll show that real quick / actuator / health so you can see if we scroll down here we have a kubernetes item here which is providing you some details about the pod specifically so that's pretty cool I also show you the environment oops not in C + V V here's our config map right with our chaos monkey enabled equal defaults okay I'm gonna go into I'm gonna go back to our config map here and I'm going to edit this config map okay and I'm gonna change the property from false to be true true okay and you'll see that if i refresh this the value got changed it true so you have automatic refresh as you change values in your config maps that will automatically be reflected in the application so again that's you know part of being cloud native is externalizing configuration like that changing it on the fly so that's all working so let's make sure that back here let's make sure that the actual data comes back yeah so we hit that app slash toy slash bestseller we got our data for the toy service so let's just check out the gateway so here's our node port for the gateway / tour we'll just do the start page for now okay so we can see everything of course first time chaos monkey own everything decided to die there but there we go got all the data for all the services through our gateway running on the kubernetes and eventually the toys service should hang itself right so we got the fall back working as well all right so that's our configuration map changing enabling chaos monkey and showing that and I think okay I got everything all right it seemed to go too smoothly for for a demo alright so I'm gonna hand over to Alex and he's gonna demo some other cool stuff thanks yeah so no surprise it was work yeah but what about adding data base to this application right because you know any real-world application would use a database so let's do that so first of all I'm about to use another Cuban cheese cluster so this one is using PKS people toll container service and this this cluster is hosted on on a DCP tenant so we are doing a live and the cluster is not running on this laptop so hopefully the network is good and everything should be fine okay so first of all I want to add I want to add a database so let me show you cube apps so what is cubes cubes is an open source project from bitNami now vmware so this is a Elm dashboard that you can deploy on any coupon I t's cluster and the nice thing about this this tool is that I can easily deploy any services as long as your service is available as Elm charts so let's do that let's click on the catalog here you can see that I can just create about anything so let's create a PostgreSQL database you know you can see the the page I just need to click on this deploy and we then may give this database name so let's use s1p right and let's add a password for this database so again don't do this on production okay I'm getting used to the screen oh is it readable for women yeah yes okay so hopefully you should be able to read them so where was my password now I need to alright okay so change me right and let's give this database name let's call it with s1 all right and that's about all the things I need to do just click Submit and in a couple of minutes a new database will be deployed to my Cuban I t's cluster so now let's switch to the to my cluster again it should be readable okay so here you can see that I have a bunch of pods running on my Comanches cluster right and the s1p database is about to to be deployed in a soon but meanwhile let's go back to the IntelliJ and in order to go faster I already created a branch called GPA and let me show you what I what I've done so here is the domain model classes so the only thing I need I had to do is just basic spring data GPA so here we can see that I just added a notation GPA annotation right nothing fancy here and in the toys bestseller application I'm I am leveraging spring data GPA and spring data rest as you can see here so I can just use my data base and I will connect to this database and use it in my with my application so let's check if everything is running all right so I have my data base here running so I want to check that everything is working fine so let me just connect to this database so I'm using here this command cube serial port forward so I'm basically I'm opening a connection between this laptop and the real both humanities cluster so I want to connect to the database and the name he is over there so s1p - podcast cool all right and I want to open sorry I want to open a port okay so from this point if I connect to this port and we just connect actually to the remote database so let's do that let's create a new database oh let's remove this one maybe we will start from scratch all right so let's create a new data source sorry oh do you have something to resume on the screen maybe maybe like this maybe we can just control and then we cannot cancel all right so average should be readable for everyone so I am connecting so let's remember that I was using this user the password is changed me all right and the database name is s 1 P so let's connect to this database fine everything is working so now you can see that from my workstation I can connect to the database and as you as you can all expect the database is empty so let's connect my application first I will connect an application running locally on this laptop to the to the remote database just to make sure that everything is working so in order to do that I would just copy past the gtb/c where URL because I'm about to use it you know in a second so oh and there is everything already set that's fine so as you can see here when you use spring data GPA you need to add some attribute right so spring data source URL to to say how to connect to your database and then you need to set the database credentials but it's already set on this on this property so just just stop the application now all right so my application is starting now here you can see that spring data GPA so that it was my application was connected to some database running on my kubernetes cluster so the the right hibernate dialect was selected all right and then we can just refresh refresh the schema all right let's up the network is working all right and then we have the product table as expected right so my application is still running on my laptop so the next thing I want to do now is to publish everything that was running on the docker desktop local kubernetes cluster I want to push this application to a real kubernetes cluster running on the cloud so let's do that in order to do this I have a ready-made script here you can see so I'm about to hand the script alright alright so we have a bunch of parts now that are about to be deployed here you can see that fashion bestseller is starting and we you can also see that I created a load balancer object in order to access my application so here I'm asking the tributaries cluster to give me an IP address so that I can just connect to my application using a real world IP address so we just have to wait for the tributaries cluster to give me this address so in the meantime let's check that everything is working all right our pods are running and I have my IP address here so if I eat this endpoint oh is it is it the right yeah we'll figure out in in a minute so now I just I want to use the GPI stuff that we added earlier and I want to publish this docker image to my to make micromanages cluster so let's edit the deployment of toys bestseller and let's see if we can find the image where is it alright so I already built a docker image for the GPI stuff and my docker image was published to some docker registry running on the cloud so here you can see that I am using elbow elbow is a docker registry from VMware it's an open source project that you can also deploy to just any kubernetes cluster and using our bow you will have nice features like I major scanning and a lot of fancy stuff so yeah you can see that I have an eye patch already deployed so what I need to do is just to get this and I will replace the image with the one deployed to elbow so my elbow is deployed on this public endpoint all right how to exceed behind and just the question for every developers ok so yeah we have the parts and here you can see a new part is about to be to be deployed for my toys bestseller and while we are waiting for the photo pod tool to deploy in the meantime what I want to do is to connect my application so I would just edit this config map just as we saw earlier here you can just recognize the cows monkey enabled feet property so let's just add the same attributes that we set in when we were running the application locally so you know the the property so let's set the URL alright and let's let's be lazy just copy pasty this template all right of course the data beige is not running on localhost so I need to get the service name and the service name is set here all right then I need to set the credentials okay so yeah and finally I need to set the password all right everything should be okay just make sure that I'm using Oh what is it on this American keyboard all right I found it all right all right so since I touched the that the spring data GPA configuration this is a special case yeah so I need to restart the pod because you know there is a pool of GBC connections that were opened by spring data GPI so actually I need to delete this pod only for this use case so let's do this and while the this pod is about to be to be terminated a new pod and stones will be started and this time this part will be connected to my database so just cut fingers everything should be okay let's see if we have everything running so let's just kind of just kill this one yeah yeah okay already done okay okay it's funny all right all right so now we will just connect to the sorry and IP address is not good so this is the IP address I need to use all right here you can see I am connected to the database all right so let's add a new let's had a new entry oops I don't think it's that the white one excuse me where is it I think I missed it no problem let's create a new table yeah this might not be the right time to update all right good decision yeah all right this is not what I was expecting to do where is it we have to figure out okay I'd like to post so I need to to get the it was the posters from JD JK yeah it was that first one you search fast oh yeah but you lost dear anyway all right what it is right to the Gateway it's always - my soul toys - best sad or - GPA yeah slash toys your right name so let's do this name equal to let's create V goes long limited edition with this category all right all right is it it's working so let's check that everything is working so I would just update the database and then you can see so my application is really really connected to my database so as soon as I interact with my that with my application using the rest controller that was generated I spring that arrest when I do SQL insert query just like this you see that my application is actually connected to the database so it's just a matter of adding the right dependencies to your application and then you just need to set the credentials to connect to your application the same kind of sauce that you would be using if you were connected to your database using your your workstation locally and in the end it's just basic stuff you just edit the config map and you're done you connect it to the to your database so let's go back to the to the slides Brian to conclude there thank you so do I need sprinkle kubernetes it's kind of an odd question to ask in a session about spring cloud programs if you are really deeply familiar with kubernetes you probably know that well I can do service discovery and via DNS I can you know mount config maps into my application we have via volumes and as long as those config maps are configured in like a Hamel format in a place that the boot app knows where they are it will work the refresh part that that does that's unique to spring cloud kubernetes when I change that property and automatically saw it reflected in the boot app that's unique to spring cloud kubernetes but you can also make the argument there that this is a cloud platform these apps are you know we don't really care about them so I can deploy get another instance up and running kill the lawn the old one with the old configuration and just you know what that happened you know load balancing we don't really need ribbon we have that via at a service layer that's you know a difference there is that in with ribbon or the new spring cloud load balancer you know that's all client-side and you know if you're taking advantage of the service itself from kubernetes that's you know platform based and there's different types of load balancing that could be enabled depending on how your admin configured kubernetes so you know there's a little bit of an unknown and and what what amount of control do you want to give up as a developer I'm not sure so you can make it argument that while everything else from kubernetes does can be done natively with just kubernetes concepts and it's a perfectly valid argument you know today what we do under the covers in spring cloud kubernetes that you might have kind of seen if you're very observant when we were looking at the Yambol files is that we use a a client a kubernetes client Java client to communicate directly with the crewneck kubernetes api server under the covers to do some of these things and in some cases that might not be okay right your admins might say I don't want my apps talking to the API kubernetes api server i don't allow that so that that could be an issue for some people as well so basically as it always comes down to in development tasks you got to use the what is right for the for the situation that you're in right if you're taking existing applications that are using spring cloud that have you know using discovery client they're using ribbon there they they are used to using already use a client side load balancer and it's okay to use the kubernetes api you can use spring cloud kubernetes right it works it's going to make that transition as you saw very smooth right we didn't touch any of the code at all we just added some configuration properties a couple dependencies and and things worked right if you're very kubernetes savvy and you're this is a brand-new applications not using it's not using spring cloud already and you just want to run you know using taking advantage of what the platform offers you can do that too right there's some caveats right there's some things that might not work exactly the same but you can certainly do that right so the choice is really up to you and what you want to do and yes so we just want to make sure we use the right tool for the right situation you know obviously spring cloud kubernetes is a very new project and we're going to evolve it and perhaps there might be different implementations of some of these things that don't use the Cooper Denny's API directly in the future and that's something we're talking about and looking into so you can look forward to that in the future and if anyone has any input also give us any feedback on that feedback is always welcome please reach out to us and let us know with that before I open up for questions you can always reach out to me or Alex on Twitter we're always happy to help obviously we're going to be here for the rest of the week so find us and ask questions if you're interested in another kubernetes session there's another one this afternoon at 2:00 which I highly suggest you attend the source code for this is all on my github repo there there's a readme with all the details and all that stuff the slides you'll get a copy of those slides and this is all recorded so it will be up on YouTube in a and very soon so you can review that as well and with that I'll open up the questions if anyone has any questions yeah yep yep yeah when we allow the same thing as for CarGurus yep yep so there's no real service mesh there right we were using the concept of the spring cloud gateway right if you use the service mesh like sto for example there's another layer of complexity that keeps at it in we don't do anything small smart there when something like this do is present right so if you have use cases for something like that I'd love to hear them and then talk to you more about that that's not something we tackled yet okay yep I'm sorry I can't hear you sing so we don't use version numbers you have to use a spring cloud bomb never use the version number directly so its Greenwich s r3 is the current GA version okay are you talking about kubernetes namespaces is there a specific change to this specific change you're talking about specifically where are we talking about this service discovery across namespaces I think that I pretty sure that changes in Greenwich s are three if not it will be in Greenwich SR for I can't remember off the top my head though yeah yeah yeah yeah yeah yeah it was merged I know it's merged and I can't remember if that was merged before we did SR 3 or it's we haven't done a release with it yet but it will be fairly soon within weeks problem yep via so customizing the mo that decorate generates yeah so it's all configured via configuration properties yeah so if you remember back to where I actually I think you understand that you don't have to use decorate with spring cloud technologies you don't have to you don't have to if you if you really want to write the yeah more files by yourself it's up to you right we use the decorate in this demo you know to to go to go faster and to generate these files for us because you know we are not yeah more architects so but yeah if you do want to customize it it's all done via configuration property so if that decorate kubernetes that's how I change for example the service type that was generated yeah yeah yeah that's yep there are different granularities so different everything is documented yeah the website so yeah that's all fine annotation kubernetes stuff so if you look here know just read it just reading yeah see we have this cluster roll or is it yeah yeah it's there you learn to do that yeah I can't find it in the CAPM oh yeah yeah so it's whether you want the service but this little load balancing client-side or you want to just let the platform take care of it right so if you use ribbon for example you as a developer could have control over the algorithm that's being used if you just rely on the platform it's gonna be whatever the admin of the platform is configured yep yeah other questions thank you everyone Oh so that enable Eureka client and enable discovery client annotation is no longer required so you can take it out of your code actually it just gets triggered when the dependencies on the class path but the application will build fine right but you'll just have to disable Eureka when you like we do in the app and the when the profile is enabled yeah so you can leave it there it's not required you can take it out actually so you can go back and do that when you get back home any well seven questions yeah we have to get kicked out yeah yeah yeah last last question good using sorry book using that the service name so just the difference between using the discovery client spring cloud discovery coin and or first is not using discovery by and letting kubernetes resolve the service name the dns for the service name is that we're talking about yeah in one case we under the covers are fetching all the pods for that service via the kubernetes api client and returning that information to you in the other case you're just we're making a regular rest client rest template or web client requests and letting the kubernetes DNS resolve the IP address for that service and letting this the service route the request so yeah that's the difference you have choices yeah okay we're gonna thank you everyone appreciate it [Music]
Info
Channel: VMware Tanzu
Views: 10,746
Rating: 4.951807 out of 5
Keywords: pivotal software, agile development, pivotal labs, cloud native, big data, data science, pivotal cloud foundry
Id: pYpruogcb6w
Channel Id: undefined
Length: 74min 0sec (4440 seconds)
Published: Wed Oct 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.