RYAN MATSUMOTO: Cloud Shell Editor
makes it easy for you to run code from your web browser
and deploy it to the Cloud.
And Google Kubernetes Engine makes
it easy to deploy, manage, and scale
your containerized applications using Google infrastructure.
So you might be wondering, can I write
the code for my Google Kubernetes Engine apps
in Cloud Shell Editor?
Yes, you definitely can.
With this Cloud code integration,
Cloud Shell Editor gives you the power
to write code for your Kubernetes application,
test and debug the app locally, create Google Kubernetes Engine
clusters, and finally deploy your app to a cluster.
In this video, we're going to learn
how to use Cloud Shell Editor to deploy an application to Google
Kubernetes Engine.
Let's go.
First, visit ide.cloud.google.com
to launch the Cloud Shell Editor.
On the status bar at the bottom of your screen,
click Cloud Code.
From the Cloud Code menu, click New Application,
and then select Kubernetes Application
for the type of sample app that we want to create.
After that, we'll get a list of Google Kubernetes Engine
samples to choose from.
Let's go with the Go Hello, World option.
Next, select a folder in your Cloud Shell environment
to save your application to and give it a name.
If that looks good, click Create New Application.
Cloud Shell Editor loads the files for your sample app
into a new workspace.
You can see the list of files in the Explorer panel located
on the left side of the screen.
Now let's go ahead and test our app locally.
For this next section, you will run your application
on a local Kubernetes cluster in Cloud Shell.
In the top menu, click Terminal, and then New Terminal.
This opens up a new Cloud Shell Terminal window
at the bottom of your screen.
In your Terminal, run Mini Cube Start
to start your local mini cube cluster.
Once your cluster is set up, you will
see a confirmation message.
From the Cloud Code menu, select Run on Kubernetes,
and confirm that you want to use the mini cube context.
The Output panel displays the progress
as your app is built and deployed
to the local mini cube cluster.
Once your app is built, you can launch it
by hovering over the URL link displayed in the Output panel
and clicking Open Web Preview.
Congratulations.
If you see this page, that means you've successfully
run your first app on Kubernetes using Cloud Code.
Now let's go ahead and modify the app.
To learn more about this Hello World app,
you can browse the files in the Explorer tab.
At a high level, it includes a Go Hello World web
app in main.go that returns a templated It's Running response
to all received requests.
There's also a load balancer service
called Go Hello, World External in hello.service.YAML
that exposes the app by describing a Kubernetes
service.
Now let's go ahead and modify the app.
Select the main.go file and replace It's
Running with It's Redeploying.
The file saves and rebuilds automatically.
You can monitor your app's progress in the Output panel.
This is Cloud Code's Watch mode.
But it's something you can turn off if you want.
Once your app finishes building and deploying,
refresh your open tab to see the updated app.
To analyze your app while it's running,
use the log viewer to monitor its logs.
Open the Command Palette by selecting View, Find Command.
Type Cloud Code View Logs and click on it.
This opens up the Log Viewer, which
allows you to filter and navigate the logs for your app.
In the Deployment section, select Go Hello, World.
Now refresh your app in the browser.
Come back to the Log Viewer and click the Logs Refresh
button to see new logs.
You should see a new message for the latest Get request.
So far, you've been running your app locally.
Now it's time to push your app to a remote cluster.
First, you'll need to create a new Google Kubernetes Engine
cluster to deploy your app to.
Click on the Cloud Code Kubernetes
icon in the Navigation bar.
This Kubernetes Explorer makes Kubernetes development
easier by simplifying cluster creation and management.
Hover over the Kubernetes Explorer bar,
and click on the plus sign.
Select Create GKE Cluster.
In the Create Cluster Wizard, select your Google Cloud
project.
You'll need to select some properties for the cluster
you're going to launch, such as the zone or region, cluster
name, and any other selections.
Click Create Cluster.
Cluster creation may take a few minutes.
But once it's created, your cluster
is listed within the Kubernetes Explorer view.
Finally, let's deploy your app to the new GKE cluster.
From the Cloud Code menu, select Run on Kubernetes.
Confirm your newly created cluster
as the context for your deployment.
Confirm the default option for your image registry.
Once your app is successfully deployed,
you can launch it via the link displayed in your Output panel.
Congratulations.
You've just created and run your first Kubernetes app on GKE.
Don't forget to delete your cluster using the GKE Explorer
to avoid any unwanted charges.
Just right click your cluster and select Delete Cluster.
Want to try this out yourself?
Check out the interactive tutorial linked
in the description below.
Make sure to subscribe to the channel,
and stay tuned for more Cloud Shell Editor videos.