CARTER MORGAN: It's time to look at the Kubernetes API
and how it makes modeling the application lifecycle easier.
With a whole universe of things to learn,
it's important to start with the essentials.
Let's go over the concepts that make
Kubernetes usable, scalable, and just downright awesome.
Are you ready?
Kaslin, when it comes to what scalable applications need,
we've talked about containers and nodes,
but that's just the tip of the iceberg.
There's plenty more we need in order to run a full scalable
application.
KASLIN FIELDS: Exactly, and that's
where the Kubernetes API comes in.
It offers some really convenient primitives
that make managing cloud native applications a lot easier.
We've already talked about a few API objects,
like pods and nodes, but there's also services, deployments,
secrets, and many more.
CARTER MORGAN: That's a lot.
Why don't we start simple and use an example application?
We said that containers are the first step to using Kubernetes,
so let's start with this container
I built to run my Hello app.
This app is really simple.
It just returns "Hello" whenever I ping it
on its local IP in port 8080.
So what next?
KASLIN FIELDS: Well, the first thing we have to do
is to create some machines, or nodes,
to run your application on.
CARTER MORGAN: Got you.
OK, I'll use Google Kubernetes Engine to quickly get started.
I can just use the gcloud command line tool
to provision a Kubernetes cluster.
After a few minutes, we'll have a cluster
that's all ready to go, and by default comes with three nodes.
This is a great starting point, but now we
need to actually run my app.
So how do we do that?
KASLIN FIELDS: Since we're using the command line,
we can use a handy tool called kubectl to help interact
with the Kubernetes API.
Don't worry, we'll go into kubectl in more detail later.
But we're keeping it simple, remember?
CARTER MORGAN: But what about all these other tools
I've heard of, kubecontrol, kubecuddle, kube-ectl?
KASLIN FIELDS: There are a lot of different ways
to pronounce the name of this tool,
so whatever works for you.
Anyway, this command is actually going
to create a Kubernetes API object called a deployment.
CARTER MORGAN: A deployment is an abstraction
that manages the life cycle of an application.
I can set the desired number of app instances
for the deployment to manage, and then it
will make sure the correct number of instances,
or replicas, are running.
KASLIN FIELDS: Exactly.
So if we increase the number of replicas that we want,
the deployment will see that there's currently not
enough replicas and spin up another one.
CARTER MORGAN: That even works when a node crashes.
If the node goes down, the current state
is once again different from the desired state,
and Kubernetes will schedule another replica for us.
Awesome.
Now I know my app is running on these nodes.
How do I access it?
KASLIN FIELDS: For that, we'll have to create a service.
This creates an endpoint that we can
use to access the running app instances.
In this case, we have multiple app instances.
So this service will load balance incoming requests
between the two running pods.
CARTER MORGAN: That's right.
For any container inside of the cluster,
they can connect to my service using the service's name.
Either way, the service keeps track
of wherever the pod is running.
KASLIN FIELDS: That's another example
of how Kubernetes removes the need
to manually keep track of where your containers are running.
Even if a pod were to go down, once a new one comes back
online, the service will automatically
update its list of endpoints to target the new pod.
CARTER MORGAN: So Kubernetes objects, like deployments
and services, automatically ensure
that we have the right number of app instances running
through pods, and that we can always reach them.
This seems like it would allow for some really cool features.
KASLIN FIELDS: Yes.
Features that used to have to be manually coded
just become afterthoughts when using Kubernetes.
For example, deployments make things like rolling updates
really simple.
CARTER MORGAN: Whoa, you're saying
that we can edit the deployment and watch
the version of the applications gradually change?
So let's say we have three replicas,
and I want to put out a new version of my application
that returns "Bye" instead of "Hello."
You're saying I can update my application container,
watch as the new version is gradually rolled out,
and the deployment will bring up new application instances
and start rerouting traffic to them?
Then once the desired number of new instances are online,
the old application instances are taken offline?
This would mean this approach has zero downtime,
since Kubernetes is incrementally updating old pod
instances with new ones.
KASLIN FIELDS: Exactly right.
And a feature like that, plus the ability
to quickly roll back if necessary,
and keeping track of deployment histories and more, all of that
is just built into Kubernetes.
That's a large part of what makes it such a great tool
to build other systems and applications on top of.
CARTER MORGAN: The Kubernetes API really
does make it easy to manage the application lifecycle.
The basic primitives-- podds, service, deployments,
plus a few more we'll talk about soon--
allow sysadmins and developers to focus on the app
without having to worry about managing it at scale.
But one thing I noticed is that we used an imperative approach.
We made manual commands, instead of using
a declarative approach, which is one
of the big appeals of Kubernetes.
KASLIN FIELDS: Great catch.
Next episode, let's dig into that.
We'll use Kubernetes the way it was intended to be used,
by updating config files.
Starting with an example monolith,
we'll break it up into a microservices style
architecture.
This will also let introduce some
of the other core primitives that we didn't talk about,
like labels and secrets.
CARTER MORGAN: We're going to pair code
up a microservice version of this?
Hm.
OK, stay tuned, everybody.
Next time, we'll be exploring building a basic Kubernetes
app from scratch.
In the meantime, if you want to get hands-on,
check out the link in the description.
And if you enjoyed the episode, subscribe for more.
[MUSIC PLAYING]