The course is part of this learning path
Google Cloud Platform has become one of the premier cloud providers on the market. It offers the same rich catalog of services and massive global hardware scale as AWS, as well as a number of Google-specific features and integrations. Mastering the GCP toolset can seem daunting given its complexity. This course is designed to help people familiar with GCP strengthen their understanding of GCP’s compute services, specifically App Engine and Kubernetes Engine.
The Managing Google Kubernetes Engine and App Engine course is designed to help students become confident at configuring, deploying, and maintaining these services. The course will also be helpful to people seeking to obtain Google Cloud certification. The combination of lessons and video demonstrations is optimized for concision and practicality to ensure students come away with an immediately useful skillset.
- Learn how to manage and configure GCP Kubernetes Engine resources
- Learn how to manage and configure GCP App Engine resources
- Individuals looking to build applications using Google Cloud Platform
- People interested in obtaining GCP certification
- Some familiarity with Google Kubernetes Engine, App Engine, and Compute Engine
- Experience working with command-line tools
Okay, welcome to our video demonstration for GCP App Engine. Now we're gonna have some real fun in this little section here. We're gonna actually play around a bit with a real app in the standard App Engine environment. Now, if you made it through the earlier four parts without too much trouble, you should have no problem following along with this demo, though, we do encourage students to actually try things out in their own GCP account, if possible.
So, there are gonna be basically three parts to this demo. First, we'll quickly spin up a sample app in the standard environment. This will be identical to what we showed in part two, very quick. And then secondly, we will practice traffic splitting and migration by creating a second version of the service. So, that we'll walk through how to configure traffic basically. And then finally, we'll check out some scaling functionality, we're gonna manually scale the app up and we'll also go through the automatic and basic scaling system. We'll just show how those are configured and that's basically it.
So let's get started. Welcome to our video demonstration of App Engine on GCP. We're gonna have some real fun now. We're gonna actually play around with a real app in App Engine using the standard environment. Now, if you made it through the earlier four parts without too much trouble, you should have no problem following along with this demo, we are going to encourage students to actually try things out in their own GCP account, if possible, but of course, feel free to just watch along. So, this demo has basically three parts.
First, we'll review the how to spin up a sample app in the standard environment. This will be identical to what we showed in part two, we already have an app up and running for that. Secondly, we'll practice traffic splitting and migration by creating a second version of the service. So, we'll see the traffic shift. And then finally, we will check out some of the scaling functionality by manually scaling the app and walking through the automatic and basic scaling configuration systems. So that's the basic plan.
So, now, let's just review how we deploy a basic app. We start by ensuring that we have our project ID set in the environment. So, you're gonna do an export project ID equals whatever your project name is. Here, it's Test Project CA555. You can get your project ID and organization ID all from the dashboard pretty easily. So we'll export that and what we need to do is get the actual App Engine code. We'll just clone the sample project and that is from Google's GitHub directory. So I do a git clone of that and then we will need to go into the directory with the App Engine configuration. So we'll do this and that'll take us into the Hello World app in standard App Engine, Python 3.7. Be sure to do the Python 3.7 version, there's also a Python 2 version, but that's pretty deprecated now.
So, once you're there, you should see in the directory that it has the app.yaml, the main.py. That's the actual Python code that we're gonna run and a requirements file and a test file there. The app.yaml is what we're interested in. That's gonna, you know, be the actual configuration for App Engine. The only thing here now is the runtime definition, Python 3.7. And then the actual... The deployment command is pretty straightforward. We're just gonna do gcloud app deploy to launch our app.
Now this one is already up. So it'll go through it pretty quickly, but the very first time that you do this deploy, it might take a little while. You know, once it finishes, we should be able to go to the URL and see the code actually running. So, let's just give this a second to complete. Okay and once that has completed, we can run this command, gcloud app browse to actually see the application in the browser. Sometimes you might see this error, did not detect your browser, go to this link instead, we can click on it and we can see it return "Hello world,' which is really all the code is doing, we go into the main.py and we can see that it's really just a server returning "Hello world." That's all it is.
So our app is up and running. Just like that, we have a basic app running in GCP using App Engine. So next, what we wanna do is to test how to do traffic splitting and migration and in order to do this, we'll need a second version of our service and doing this is gonna require a little bit of file manipulation. Specifically, we're gonna need to create two directories with the same service.yaml file and we'll make a minor change in the Python code so that we can see that there are in fact, two different versions of the service running.
So, let's go about creating those two versions of the service. The way we're gonna do that is we're going to create two directories. We're gonna create a v1 and a v2 directory and then we're, you know, we'll see that we have them in the same directory as all of our code right now. So what we wanna do is copy all of our code into those directories. So we have a v1 and we will have everything in v2.
Now, it is important to copy everything. If you try to copy only the yaml and the Python code, it will fail. The requirements that TXT file is very important. If you look at it, you'll see that it is what tells App Engine to install Flask and what version of it. So if you forget that, it'll try to deploy an app, but it will be broken because it won't have Flask. So make sure you do that. So, if we go into, let's say, v2. and we look at our code here, what we're gonna need to do is change the app.yaml file into a service.yaml file. So we can just change it to service.yaml. And then to make it its own... To make it a little bit more unique... Oh, so yeah, we keep the same configuration here, but to make the code different, we're gonna go into the main.py and we're gonna have it return something different. So instead of "Hello world," we'll say this is the other version. Keep it very clear.
So, now we can actually deploy this as another version of the service by doing a similar command, we'll do gcloud app deploy and this time we'll pass in service.yaml. And, again, it'll use the same... It's the same basic default service, but now it'll have another version with this different code. So hit the deploy, we confirm, it'll take a minute to come up. So let's just wait for that.
Okay, so now that that has finished deploying, we can see again, gcloud app browse if we wanna get the URL for the service, but before we do that, just to verify that we have two versions running, in the console, we can check and see this. We can see it in two places, in the services page, there should be a two under the number of versions there. So we can click on that or we can click on versions and we can reload this. Sorry, here. We can see that if we refresh it, there are two versions here. One of them is getting 100% of the traffic, the other is not.
Now, if we do check the versions here, this is the one getting 100% of the traffic. If we click on it, it'll return the service output, which is the other version, the new one instead of "Hello world." If we click on this one, this is the older one that outputs "Hello world." Now, this is not the official service URL. This is not the app URL. This is just for those individual versions of the service. If we look at the app URL, gcloud app browse, we will get this app URL, testprojectca555.appspot.com and it'll give us this is the other version. It'll do that because 100% of the traffic is going to the new version that we just deployed. You can see it has a more recent timestamp. So, the console gives us these two URLs to see the two versions of the service, but the service itself, remember the traffic allocation is what determines what a user will see.
So now we have to think about splitting the traffic and migration. So that's gonna take a little bit of work, but nothing too tricky. So, let's start by talking about traffic splitting. If we wanna do traffic splitting, we can do that from the command line, but it's a little bit clearer in demo if we use the console. So, what we're gonna do is click on traffic split here and remember that there are IP address and cookies splitting types. For when you need a very precise split, you use the cookie type, though it takes a little more configuration. The IP address one is a little bit simpler. There's also this random option here, you can see. So we're gonna pick that and we're gonna click on, you know, the other version of the service here, these are the two versions running and we can decide what percentage we want. Let's say we want 50/50. So half the time, it should randomly choose the "Hello world" output and half the time it should choose the other one.
So we click save, it'll update our traffic settings, just give it a moment to execute. Okay, that should be done. Now we go back to our Services page. Still, there are two versions there. Go to the versions page, we can see there's a 50/50 split. So, if that's the case, we can test this pretty clearly by going to the app URL and half the time we should get hello world, half the time we should get this is the other version. So let's click on it. There's "Hello world." Reload. This is the other version. Reload. "Hello world." Reload. Well, there's "Hello world" again, but as you can see, it's randomly choosing 50/50 between the two versions of the app. So we have the two versions of the service. So we have successfully split our traffic and the nice thing is that migrating back to a single version is similarly very easy.
We can do it through the web console with just a few clicks. What we do is we click on the version that we wanna migrate to, let's say the newer one, we wanna get that back to 100% of the traffic, all you do is click migrate traffic and confirm. And then in a matter of seconds, 100% of the traffic will go to the newest version of the service. Executed, now we're back at 100%. We should only get this is the other version now. If we reload it, we can see that that's what's happening. Right, there's three times, so. So there you go, splitting and migration, pretty straight forward.
So let's do some scaling. Scaling, there's a few different versions of scaling within App Engine. In the standard environment, the easiest one to test since it won't require any traffic manipulation, it would be manual scaling and manual scaling, we can configure at the level of individual services by just going to our service.yaml and what we're gonna do is add a little bit of configuration.
Now one thing to note, another reason we're showing manual scaling is that automatic scaling is enabled by default in the standard environment. There's also the basic scaling option, but for demonstration purposes, this is actually much neater, much cooler. So how do we add scaling? Well, what we do is we add the manual scaling config to our yaml here, and we're gonna set that to instance count of, let's say five. Let's say we want five instances backing our app. So what we do is we edit that and we redeploy it and we should see it. Oh. Actually, we have a light slight error there. We wanna make that into instances. Sorry. And then that should come up with five instances behind our app. So let's just give that a sec to run and of course, be careful about the name of your configuration, instances not instance.
Okay, so the deploy completed and as we can see, a third version of the service came up because we did the app deploy again and this version will have five instances of traffic behind it, five instances behind it to manage the traffic. We can see here, they all just came up around the same time. So, the scaling is actually pretty fast. You'll recall from the lesson that there is an option for more gradual scaling if you want or gradual migrations, but we're doing just immediate changes here with the deploy command.
Now we can also migrate back with the same method by just deleting that configuration. We can go into service.yaml and just kill that and then just deploy it again. And again, by default, you know, we create a new service and all traffic goes to that... A new version of the service and all traffic will be split toward that new version. Now that's a default that you can override by changing the splitting options or by migration.
So, let's see if the instances go away for this new version. We're doing our update, let's give that a second to run. Okay, so the update completed. So now, again, if we go to our versions here, we'll refresh, we'll see there's a fourth version now. It's getting all the traffic and if we look at our instance count, there are no instances. They're all gone because the scaling config was deleted.
So we can see, it's really that simple to manually adjust the scaling with your App Engine services. So that's basically it, congrats. That's it for our App Engine demo. We've done quite a bit in just a few minutes. We spun up a basic app, we created multiple versions, we split traffic, we ran a migration, we scaled everything up and down, pretty cool stuff. You should have a good basic understanding. Thanks for toughing it out and cheers.
Introduction - Section One Introduction - Kubernetes Concepts - Cluster and Container Configuration - Working with Pods, Services, and Controllers - Kubernetes Demo - Section Two Introduction - Creating a Basic App Engine App - Configuring Application Traffic - Autoscaling App Engine Resources - App Engine Demo - Conclusion
Jonathan Bethune is a senior technical consultant working with several companies including TopTal, BCG, and Instaclustr. He is an experienced devops specialist, data engineer, and software developer. Jonathan has spent years mastering the art of system automation with a variety of different cloud providers and tools. Before he became an engineer, Jonathan was a musician and teacher in New York City. Jonathan is based in Tokyo where he continues to work in technology and write for various publications in his free time.