>> Hey everyone, I'm very
excited today to talk to you about Kubernetes,
KEDA, and Azure Functions. I'm Jeff Hollan.
We're going to walk you through what Kubernetes is,
how you can bring a new serverless capabilities
to Kubernetes using things like Virtual Nodes and
the brand new open source KEDA project which unlock
running things like Azure Functions
directly on any Kubernetes cluster.
So let's jump into it.
I know some of you here might be newer to Kubernetes,
you might be newer to Azure Functions,
so we're going to spend a little bit just covering
both and then I'll show you
a quick demo of using it all in action.
So to start with let's talk about Kubernetes,
let's think about building an application.
So I want to build an App,
maybe it's a shopping App.
I'm going to have something like a shopping cart,
maybe I'll have a database on the back-end,
and I'm going to have some logic that needs to run
like whenever somebody tries to process an order.
That's not going to make up my App,
each of those individual components.
There's that might think about how do I take this App,
make it Cloud-native, have it run at scale in the Cloud.
It's very likely that I'm going to be running
across a number of different servers,
a lot of different infrastructure in the Cloud.
So that if I have a peak in demand,
my website's getting a lot of traffic,
I might need more resources,
more machines that are powering that aspect of my App.
Now, what Kubernetes is in
a very simple way is this nice interface,
a set of APIs where I can take my App,
I can containerize it,
publish it to Kubernetes,
and Kubernetes is going to take care of
managing to make sure that my App and
the resources that it needs are distributed
cleanly across my available infrastructure.
So here you'll see we have this concept of nodes,
this is often like a server running in the Cloud,
maybe even on-premises, and I'm going
to have my App running and Kubernetes is saying,
"Hey, there's a lot of people hitting your website right now.
We might need to scale this how to
replicate it across a few more of instances."
Now one nice thing about Azure Kubernetes service
is that in just a few clicks,
anybody can get a fully powered Kubernetes service up and
running and for things like
this master that are doing some of the orchestration,
that's actually fully managed for you.
So you don't even have to worry about it.
But it's not quite serverless.
There's still a lot here that your teams and
organization need to be aware of.
First and foremost, I'm running on these nodes.
I need to make sure I have enough of these nodes available.
If it's something like Black Friday and I get
a massive burst in traffic on my website,
what if I need more than these in this case
six nodes to keep scaling out?
So that's where concepts like Virtual Nodes come in.
Now, Virtual Nodes, our Serverless nodes,
this is a capability that you can build and
add to any Azure Kubernetes cluster.
This is generally available today,
we're very excited to announce,
and what this enables is that now as my App needs to run in scale,
let's say it needs to go beyond my allocated nodes.
It can actually run on Virtual Serverless Containers.
So if my website's getting a lot of traffic
and it needs more resources that are available on my node,
rather than having to spin up and instantiate
an entire Virtual Machine and add that to the cluster,
it's just going to spin up these Serverless Containers,
all powered by Azure Container Instances,
so that my cluster really has unlimited scale,
and it can scale just for those containers that need it.
So this is a really powerful capability and It
brings this concept of Serverless Infrastructure,
"Hey, I'm only getting these containers when I need them,
I only pay for them while they're running.
Once I'm done, once that traffic slows down,
we're going to throw away those Serverless Containers,
your bill for those Serverless Container
stops and you're back and running in your steady-state."
So this is a really powerful feature,
it brings some of the capabilities of some Serverless.
But there are some pieces still that this is missing,
when we look at the full Serverless story.
So let's think about something like Azure Functions,
which is a fully managed Serverless service.
Well, with Azure Functions,
it works a little bit differently.
Instead of giving it necessarily your container,
you can give it your code written in
the Azure Functions run-time with
the Azure Functions Programming Model.
You publish that bit of code to the Cloud,
and it's run and scaled and managed all for you.
Now, the way that that scale works in
Azure Functions is that it's fully event-driven.
That means that I might run a little bit of code and say "Hey,
run this code whenever somebody drops
an item in my shopping cart."
You publish that to Azure Functions,
the Azure Function service is listening
and looking at your shopping cart events.
If an event pops up,
it's going to scale up something in
your App to run that little bit of code,
then it scales back down to zero.
In Azure Functions, you only
pay when your code is actually running.
So there's this nice fully managed service offering.
So the one aspect we talked about before that's kind of
Serverless Infrastructure that you can bring into
Kubernetes with Virtual Nodes is nice,
what about the event-driven aspect?
What if I want to write these powerful event-driven apps
where really I just want to write simple bits of code like "Hey,
run this whenever somebody drops something in my shopping cart."
How can I bring that to Kubernetes?
Because one of the aspects of
Virtual Nodes and Kubernetes in general is,
the generally it's scaling just based on
things like CPU and memory.
It has no knowledge of your event source.
It doesn't really know if there's a lot of
people adding things in their shopping cart or not,
it's just trying to guess based on CPU and memory.
Now that's where this new project KEDA comes in.
KEDA is a Kubernetes-based, event-driven,
auto-scaling component that can
be installed to any Kubernetes cluster.
The Azure Kubernetes service,
your own on-premises service.
We've even partner with Red Hat,
so that you can run this on Red Hat OpenShift.
Now, what KEDA brings is the knowledge
of your events and the ability to write
event-driven containers and scale
them the same way that your Azure Function scale in the Cloud.
Meaning that you can write a container and say "Hey,
run this whenever somebody drops something on my shopping cart."
KEDA is actively monitoring that shopping cart.
If a million people drop a million stuff in their shopping cart,
it's going to be able to proactively
scale even before CPU and memory are impacted.
So this is a powerful new capability that really brings the power
and richness of event-driven more cleanly into Kubernetes.
So this works seamlessly with Azure Function Apps today.
You can take any Azure Function App
written in any tool that we provide.
You can now publish it to Kubernetes and those functions will
scale and behave the
same way they do in the Azure Function service.
So this gives Developers, teams,
and organizations the productivity of Azure Functions,
but they get the flexibility and
the freedom to choose exactly where and how they host it.
Maybe you want to take advantage of
the full power of the Azure Function service.
I don't want to worry about any of this, that's great.
You can publish to the Azure Function service,
or maybe you're running some of these functions on-premises,
on the edge, or you want them to run their alongside
your existing service mesh or Kubernetes investments.
You can do that now too without changing the code at all.
So let's take a look at this, I'm going to do
a demo of using Azure Functions,
running them in Kubernetes,
leveraging the powerful new capabilities that KEDA brings.
So to start with, let's switch over here,
I've got Visual Studio Code open.
In just a second, we're going to create a function.
Actually we'll go ahead and do that now.
So using the Visual Studio Code extension for Azure Functions,
have this nice interface where I can go ahead and
create a brand new function project.
We'll call this my-queue-function,
and I have a number of
different languages that I could choose here.
I'm just going to go ahead and choose
Python and a number of
different events sources that we support as well.
Now, today KEDA supports Azure Queues,
also supports Azure Service Bus and HTTP,
as well as Event Grid, Cloud Events, and [inaudible].
I'm going to choose a queue trigger
right here just to keep it simple.
We'll call it our queue triggered function.
I'm going to create a setting for my connection string.
So I'm going to use this storage account.
This is the storage account that it's going
to be listening to saying "Hey,
watch for new items."
I've got a queue here called queue,
and we'll just open it in the current window.
So I just set up a simple function here,
a few clicks to say "Hey,
listen on the storage account to this queue called queue," and
now Azure Functions in this tooling and
VS Code have set everything up for me.
So let's go ahead and select a storage account to
keep our function App, code, and data.
I'll just use the same one for simplicity sake.
This is it. This is all the code that I need to get started with.
This is event-driven, I've said "Hey,
the event I care about as a queue message."
Right now it's only eight lines of
code because I haven't written much
here but I could now write whatever Python script I want to,
to say "Hey, do this whenever
a message gets dropped in the queue."
Visual Studio Code already set up for me
things like the function at JSON file,
letting me know that queue name,
telling me where I can find the connection string for that queue.
I even got similar stuff set up in my local settings
JSON that have the actual connection string and keys here.
Now, one of the great things about Azure Functions is
that I get powerful capabilities like local debugging.
I can take advantage of that to
even when I'm running these functions in Kubernetes.
So let's go ahead and set a break-point here.
I'm going to choose to run this function.
This is going to spin up on my machine,
the Azure Functions run-time.
This is completely open source all on GitHub,
and now it's running on my actual box so that I can
Debug and see exactly how this is going to
pave even when I publish it to the Cloud.
So it's listing now to the queue message.
This is that storage account that I have been listening to.
This is actually the same queue.
Just right here on the Azure Portal,
let's just add a queue message.
Let's say "hello.'' That's okay.
As soon as I do that,
switch back over here to Visual Code,
you'll see my breakpoint got hit.
I could step through debug and see exactly what's happening here.
That same rich Azure Functions development experience
that I wanted now working here.
Now, moving forward, I could go ahead.
Let's stop this session.
I could take this function right now and
publish it directly to the Azure Function Service.
It's going to listen on to that queue
and scale dynamically for me.
But with Keda, I can now actually run this in Kubernetes as well.
So how this works, let me open up the terminal.
The first thing I need to do is I need to make sure that I have
Keda installed on my Kubernetes Cluster.
So in the Azure Function CLI Tooling,
we actually gave you this new option called Func Kubernetes.
There's an option here, just install,
where I can install Keda and it's
supporting components into my Kubernetes Cluster.
So when I click "Okay" to install
that here, it's going to go install.
Keda makes sure that that's all running on my Cluster already.
So now on my Cluster, let's actually go ahead and look that out.
Now, I have running in my Keda namespace.
Here is that Service Controller.
It's going to be listening. It has
knowledge of those events sources.
I set some other components here that enable HTTP scaling to zero.
So that's how ready to go for us now.
Now, coming back to my function project
now that my cluster is ready to go,
and to do that it's actually pretty easy.
Let's come back over here to this project,
and let's make sure that we have a Docker file because each one of
these Containers is going to be in a Docker file.
Now, I don't have one right now,
but it's actually really easy to set up.
Yet just using the Command tools,
I can just come in here and say,
Func init docker only.
It's going to ask me the language that I'm using.
So I'll say Python because this is a Python app.
In here, just automatically for me
it's gone ahead and created a Docker file.
This is pre-provision.
It's everything I need to get up and running.
So now that I've got the Docker file,
I can run the command to deploy it.
So let's do Func Kubernetes deploy.
I'm going to give it the name that I want it to have.
I will call this my Queue Function.
This is my Docker Hub Registry name.
I could also use an Azure Registry if I wanted to.
This is Python.
I'm actually going to do a try run
right now because I want to show
you what it's generating behind the scenes.
So I have now this Deployment file.
This is what the CLI generated
for me because I want to tell you what it's done.
First thing it took things like my connection Strings and it's
converted them into Kubernetes Secrets automatically for me.
It set up the deployment in Kubernetes.
It's told it, hey this is
the Container that we're going to build for it.
It's telling it things about the trigger.
I have this special property here for Keda that lets it know,
"hey I want you to go listen to a queue trigger.
It's called queue and there's
a secret here that has the connection String."
This is what Keda uses to monitor and drive scaling for us.
So that's what it's going to run for us.
Now I'll actually show you just to run
the command so that you can see it work.
So I'm going to say Func Kubernetes deploy.
This is now building my Container for me.
It's going to push that up to Docker Hub,
and once it's up in Docker Hub,
segment is going to run that deployment on my Kubernetes Cluster.
In just a second here,
you should be able to see in Kubernetes
that that function is now there ready to go.
Now, what's great here is you've noticed I've just been using
the regular Azure Functions Tooling in Visual Studio Code.
I could open an existing project,
I could be doing the same thing with
a project that I created in Visual Studio,
Intelligent, Eclipse, and the CLI
is just going to work with it for us.
So now that that's been pushed into Docker,
you can see it's created this stuff in
Kubernetes. Let's look at it.
One of the things I want to call out
here is that this is now deployed my queue function.
It's running right now in my
Kubernetes cluster and it's actually set up
some auto-scaling rules for us as well so that it
can monitor our function for us automatically.
So now what I want to show is I'm going to
come back over here to the Portal.
Let's make sure this queue is empty which it is right now.
Let's go ahead and add a message.
So we'll say, "Hello Keda" and click "Okay".
Keda should be aware that there is now a Queue message available.
If I click to get my pods,
it's now spun up for me a queue function.
So it's scaled this up from zero,
it's given me a queue function.
It's running, and if I actually refresh this you can see it
actually it's getting eaten by Keda maybe.
Yes, there we go. The refreshing caching scared me a little bit.
So I can say "hello Keda too" click "Okay".
Kubernetes is eating it right away.
So my Kubernetes cluster has been scaled for me automatically.
So that's how easy I can get up and running.
This is now listening to my cluster now.
Let's do one more quick change.
I'm going to change something.
I want to show you how this can
scale based on queue messages as well.
So let's just add a little line of code here.
I'm going to have this sleep whenever it processes
a queue message so that I can replicate some high work happening.
Let's sleep for five seconds.
I'm going to come in here to the Host file
and I'm going to tell it, "hey,
for each one of these instances,
actually I want you to eat one message at a time.
So consume them solely from the queue and when you consume them,
I want you to sleep for a while."
So let's redeploy this to our cluster.
While we do that,
I'm going to come over here to
a simple Console app that I have and I'm going to push
10,000 messages to this queue that I'm now pushing to my cluster.
So let's go ahead here. I want to wait to make sure I
have my updated properties before I do it.
What I want you to watch when I do this, I'll get you ready.
If I come here to Kube deploy,
you'll see right now it says," hey you only need one instance."
As soon as I go and push a very high load and
that event source starts getting more and more events,
before the CPU and memory even pick up,
Keda is going to enable this to scale out
infinitely based on that event source.
So that's now been updated here.
Let's just run this simple little test that's going to
push 10,000 queue messages to this queue.
So we make sure that this spins up for us.
It's now pushing all of those queue messages.
So now that's there,
let's take a look at this happening in real-time.
So it's coming ahead here and say,
"Get All" and you'll notice right now it's going to look at,
we can actually look at the scaling rules.
So here's the scalar that it set up.
Let's take a look at it.
It's not yet detected the scale. That's okay.
Oh here we go. Now it's seeing it.
So we have 256 messages here.
So if I come here and say," get deploy now",
because there's so many messages you'll notice now I'm at eight.
This is going to keep going up and up and up.
So I'm an eight right now.
Now it's saying "oh I actually need 16 because
my app behind the scenes is pushing more and more messages."
So very quickly, before I even have to wait for CPU
and memory to pop up because Keda knows about the event source,
it's quickly adding more and more instances
to help out to drain that queue.
So this is all managed automatically for
me with Keda, with Azure Functions,
and with Kubernetes, and
joining it with things like the Virtual Node,
I can get Serverless Infrastructure as well.
All right. So now that we've seen this in action,
how can each of you get started?
If you want to run a similar QuickStart like what I just ran,
you can go to aka.ms/kedaquickstart,
and it will give you a step-by-step tutorial
to set up the test just like I ran.
If you want to learn more about AKS Virtual Nodes,
you can learn more by following the link here.
Get it set up for any of your Kubernetes deployments.
If you're interested to learn more about Keda
even how to contribute and make it better to
bring event-driven compute to any Kubernetes cluster,
you can follow the link to GitHub here as well.
So thank you so much everyone for watching and have
a fantastic Microsoft Build 2019.