[MUSIC].
>> Today we're going to be focusing
on deploying a Kubernetes cluster to the Cloud.
With any infrastructure as code,
we probably want to start by creating repository. Let's do that.
I'm going to actually go to the Alt-F4-LLC
org example-aks-cluster,
example, Azure, Kubernetes, that is service cluster.
We're going to make it public because
we are going to do it in terraform.
We'll give this a good old-fashioned
Apache license because that's the one
I like and we'll add a read-me file to share.
Why not. As I said,
with any infrastructure as code,
you always got to start with code.
The reality of it is, is you should have some type
of repository or something like that.
In this case, we're going to have an example, aks-cluster.
Let's go to our terminal git clone like that,
and we're going to clone our repository.
What do we want to do next? Well, there's
a couple of things we want to do.
We want to first make sure that we can communicate with Azure.
If I go here and then I do az--help,
I should be able to see my Azure command works there it is.
So you can see here I have a whole bunch of Azure output.
I already have mine installed.
If I do az-login and hit "Enter",
it's going to kick open a new browser window for me.
If I go over here, there I am.
If I click on this,
I can click my account and then you'll see,
hey, you have logged into Microsoft Azure.
Now if I close this,
and I go back here, well, there you go.
Now, if you'll notice I'm logged in.
It says the Cloud name is Azure Cloud.
We've got my home tenant id,
and then we've got my username,
which is my e-mail and then my type.
The first thing we need is our example network.
Here's where the fun part comes in.
This is where we get to
click for anyone out there in the click ops world,
this is where we get to have fun.
We're going to go into Azure and
we're going to say, all right, well,
I need to figure out how I create a network.
Let's go to the click ops. We're going to say virtual networks.
There we go, virtual network.
Now you'll see I've already got one here because we've
got one for our company already set up,
but maybe I don't know and I'm curious, so I hit "Create".
We want to create a resource group and we want to create
a resource group for our main objects of concerns,
our main separations of concerns.
Those main separations of concerns
are going to be the networking layer,
the virtual machine,
and then the Kubernetes stuff.
We're going to say that this is all going to
be in a individual resource group.
We're then going to say that everything
related to the VMs is going to be
related to a resource group besides the client
then everything related to Kubernetes will be,
so West US 3.
Let's just see this, let's see if this works.
I'm going to just right click and I'll say
Terraform plan, Terraform Apply.
We get asked if we want to apply it, we say yes.
We should have a resource group created now in Azure.
We've got the resource group that we
now need for all of our networking and all that stuff.
Let's create the rest of the resources that we need.
What we are going to want to do is we're going to
want to create the network now.
Then we're going to look at virtual network.
They say we need a resource group. We've already done that.
We're going to do this, we're going to go back to our main file,
then we're just going to go under
here and we're going to paste this.
We can say that this is
example network here. We're just going to save that.
This is our resource group and actually what's really
nice is if we click on example resource group here,
we can see that in it is all of
its resources or if we click on Overview,
we can see all of the resources that are in it.
If we look at the example network resource group, what do we have?
Our example network, virtual network.
If we go into Lucid Chart,
we then say that we need a VM subnet and a Kubernetes subnet.
We actually just saw how we can add subnets
by simply adding them here, subnet, subnet.
Look at what we've got resource group,
virtual network, and then subnet.
We've already created these two so
let's go ahead and create this next one.
We'll go back to our Terraform, paste in this.
This is one of our subnets. Here we go.
This is the module we want to use.
As a matter of fact,
I can just copy and paste this whole block.
We're going to go right underneath provider,
since this is like a value.
Then we're going to say we want to base cidr blocks.
We're going to actually create a Var as well.
We say locals, because this is a local variable.
We say base_cidr_block and
we're going to move what's down here on Line 28,
our base cidr, put it right there.
We're going to follow 10.0.0.0/16 as our base cidr.
Then we're going to use the subnet adders module
in the HashiCorp subnet cidr source,
to generate the specific subnets for us.
For this one, we'll change this to example virtual machine.
It will have four bits.
Then example Kubernetes.
What's happening with our Terraform if we start from the top,
is we're importing our Azure provider
and then we're configuring it optionally if we need to,
we're then setting some local variables up.
We're setting up a base cidr block of 10.0.0.0/16.
Then within that, we say we want to be able
to generate a list of subnet addresses,
essentially from a base cidr block that we
pre-determined in our local values here.
Then we want to generate this array of network.
The first network we're going to generate is
our example Virtual Machine network
and we're going to give it four new bits.
For now, we're going to say example Kubernetes,
and we're going to give it four new bits as well.
Let's give this a shot. Let's see if this works.
Might work, might not. Let's try a plan. There you go.
You can see it's downloading the subnet cidr.
Let's look here. What do we got?
We're creating two new subnets.
First one, example Kubernetes 10.0.16.0/20.
Look at that just perfectly slices that subnet.
Just perfectly divides it the way we need it to.
Two things we're going to create here.
We're going to create our example
Kubernetes subnet and our example,
Virtual Machine subnet, everything looks good.
Let's apply it and get these created. I'm going to hit "Yes".
As I said, we calculated the subnets using a module in Terraform.
I'm not telling it, you need 10.0.16.
I'm not spending time doing that.
If we go back to our Network and now we go
to subnets, there we go.
We've got an example Virtual Machine subnet and
example Kubernetes subnet 4091 and 251.
As we move forward,
our Terraform is still very simple.
Provider configuration, very simple locals configuration.
We generate our subnets,
we create our resource group,
our virtual networks, and our subnets.
For 59 lines of code,
we have quite a bit here already, which is fantastic.
If we click on "Create",
click on "Virtual Machine".
We give it a virtual machine name,
a region, availability options,
availability zone,
all pretty standard security type and then the size.
In this case, we're not going to call it twingate,
we're just going to call it example bastion server.
We're going t get rid of this and we'll call it the same thing,
example bastion server,
resource group will be example virtual machine,
resource group location and then the admin username for now,
we'll just say is example.
We want to create an Azure network interface now
that we've created the main basic blocks of our virtual machine.
Our virtual machine is
an example bastion server, example username.
We give it the location of the resource group,
the name that we want to give it, the network interface,
which will give it in a second,
as well as the size and again,
we want to give it just a very small burst-able B1S
just to save some money.
We're going to say that our admin SSH key is the one.
We'll put some documentation here,
we'll say created manually in Azure portal and imported above.
What we're going to do is we're going to
take this comment and we're going to put it
right there because I want to make sure that if you guys use this,
you're going to have to create an example bastion server
key right in the resource group and all that stuff essentially.
You're going to have to do the same thing here.
Let's put this here as well and import it below. There we go.
For now we're just going to say
example bastion server resource group name is going to
be our virtual machine.name, example virtual machine.location.
Then here's our IP configuration.
We're going to say that the name of this is going to
be example bastion server.
The subnet we want this to be on is our example,
virtual machine subnet and we need to attach a look at this,
a public IP address.
Now we're not done yet because now we need one more piece.
As a matter of fact, we already knew we needed this piece.
The piece that we actually did not
include that we can add if we want,
is a virtual network interface.
We'll say that this network interface exists right here.
We need a public IP address now as well.
We're going to go back to here.
As I said, I've already got a lot of this written.
So I'm going to just grab this public IP that we already had.
We're going to put this right above it and
uncomment it and then we're going to replace
anything that said twingates with
example bastion server and
then our example virtual machine location,
we want it to be a static IP address
so we're just going to create a standard IP address.
Now we have our public IP address.
Now this chart is really getting a lot
more detailed where we can see, okay,
well the network interface sits basically between
the virtual network and
the public IP address and
the user connects to that public IP address,
which then goes through the virtual interface to the Jumpbox.
We need a way of telling the network interface since
this network is our true firewall right here, guys.
This network interface is
the one true thing that
people could connect over and have access to.
We want to make sure that we have our security group or
our security rules on this set
properly because right now we're not allowing anything.
We're going to want to actually create
a network security group in general.
We're going to use my previous one as example template.
Right underneath network interface
between public IP and network interface,
we're going to paste our new security group rules.
We're going to create
a network interface security group association.
This is what we're going to do to then connect
our network interface on
our bastion server to the security group for it,
network interface example bastion server,
network security group example bastion server.
Right now you can see that we're
actually creating our virtual machine.
Everything else seems to have been created.
Let's go into the Azure portal.
Let's click on "Virtual Machine".
There it is, look, example bastion server,
virtual machine, Alt-F4-LLC example,
virtual machine West US 3
standard and there's our IP address, we got our IP.
As a matter of fact, if I click on it,
look at that, it's starting up,
it's not ready yet, but we can see
that it's running example virtual machine.
It's all here. There we go.
If I refresh, there we go,
green across the board.
It's up and running. It's an Azure.
We've got three nodes.
All done. All created.
[MUSIC]