What is Infrastructure as Code? - YouTube

Channel: IBM Technology

[0]
Hi everyone, my name is Sai Vennam
[2]
and I'm with the IBM Cloud team.
[3]
Today, let's talk about Infrastructure as Code.
[6]
These days it's increasingly crucial to automate your infrastructure
[10]
as applications can be deployed into production up to hundreds of times per day.
[14]
In addition, infrastructure is fleeting
[16]
and can be provisioned or deprovisioned in response to load.
[19]
Let's start with an example.
[21]
Let's say you're building out an application
[24]
and you've chosen a public cloud.
[26]
Now, the first thing you've decided to do is
[28]
build your application on Kubernetes.
[30]
So, we'll have a Kubernetes application stack.
[35]
Now we don't actually have to dive deeper into Kubernetes
[38]
because it isolates the hardware from the application layer.
[42]
So, we don't actually have to go in deeper,
[44]
it will manage that for us.
[46]
Next, let's say that after a week of development
[49]
we've decided to bring in a VM
[51]
that holds a legacy application that we have not modernized just yet.
[55]
So, we'll bring on a VM
[59]
and now to actually connect up those dots
[62]
we'll need a VPC (Virtual Private Cloud).
[69]
So, there we go, we have a basic infrastructure in place.
[74]
Now, let's say that I've developed this, it's great,
[76]
all the infrastructure details are documented.
[79]
Now I'm ready to move it into a test phase.
[81]
Now, I know that for best practice what I should do is create a whole new environment
[89]
that mimics my development environment.
[93]
To do so, I'll go back to my documentation
[96]
and start following the steps to spin up that infrastructure.
[100]
But let's say that maybe I forgot to document one of the config switches that I've changed,
[105]
or maybe the platform is different in how it handles provisioning infrastructure.
[110]
Regardless, the application and test don't work the same way in the new environment.
[115]
I decide, "OK, we need to fix this problem"
[118]
- and to never have this problem in the future again,
[121]
we need to take advantage of infrastructure as code.
[124]
Let's talk about the first approach to infrastructure automation,
[127]
it's going to be imperative.
[131]
Now, this is kind of intuitive for most people
[135]
because an imperative approach allows you to define step-by-step
[139]
how to get your infrastructure into a certain state.
[141]
So, in general an imperative approach would use something like
[145]
a CLI along with maybe a bash script.
[148]
So, for example, in this case
[151]
we could do something like, "cli create k8s",
[157]
and then we would define some additional commands to
[160]
customize that Kubernetes deployment.
[162]
We'll do the same thing for the VM, as well as the VPC.
[171]
So, an imperative approach has an advantage.
[175]
It allows you to really define step-by-step of how your infrastructure is provisioned
[180]
and that generally comes with more power as well
[183]
because you're using the cloud tools
[185]
and doing it in a step-by-step process.
[189]
But at the same time, this can come with complexity.
[192]
For example, if you wanted to tear down your VMs,
[195]
or your environments rather,
[197]
or let's say you wanted to scale it up or down,
[200]
you'd have to write custom scripts.
[202]
It's not handled for you in an imperative approach,
[204]
so this generally doesn't scale well.
[208]
Another approach to Infrastructure Automation is going to be Declarative,
[213]
and this is actually my favorite approach.
[216]
Now, a declarative approach would be something like Terraform
[221]
and what it basically allows you to do is to define the final state of your infrastructure
[226]
and then it lets the provider handle the rest.
[229]
So, instead of defining every step,
[231]
you just define the final state.
[233]
So, in this example maybe you would do something like
[236]
define a Kubernetes resource
[241]
and a VM resource, as well as a VPC resource.
[249]
Another great thing about this
[252]
is it's generally managed through just simple config maps.
[255]
So, if you wanted to do something like
[257]
define a host you could do that,
[260]
maybe a domain, or maybe even the subnets.
[268]
So, in general a declarative approach
[271]
allows you to more easily manage the configuration
[274]
and is my preferred approach for automating infrastructure.
[278]
Let's take this simple example,
[280]
if you ran the imperative script multiple times
[283]
you would actually end up with a multiple environments
[286]
and, in addition, let's say one of the steps halfway through failed
[290]
then you would have to add error handling
[293]
to tear down the steps that did succeed.
[296]
Now with the declarative approach, no matter how many times you run the script,
[299]
you end up with the exact same infrastructure.
[302]
So, you could do it the first time,
[304]
provision your environment,
[306]
and then maybe run it again
[307]
later on to ensure that your environment hasn't changed.
[311]
So, I'd say this is very important to can understand the different approaches infrastructure as code,
[316]
but, in general, I do prefer a declarative approach.
[320]
Next let's talk about DevOps.
[323]
Now we all understand how important about DevOps is.
[326]
When developing an application, you'll first write some code,
[330]
you'll want test that it actually works,
[334]
and then you want to push it into production.
[340]
And then you want to make sure that all of that is
[344]
always working and you can repeat those processes.
[346]
Now, I know there are teams out there that have a perfect agile DevOps flow,
[351]
but because they're working with legacy infrastructure
[353]
they have to open a ticket every time they want to get a new VM,
[356]
and that's just due to the infrastructure that they're running on.
[360]
Now, that really holds them back.
[363]
Now, with Infrastructure as Code, when it's supported,
[365]
it allows you to treat your infrastructure
[368]
with the same level of quality that you treat your code.
[370]
So, this includes things like versioning.
[372]
So, essentially, you want to make sure that any time infrastructure changes,
[376]
you're tracking that,
[377]
and is generally a best approach for automation.
[382]
The last thing I want to talk about
[384]
is immutable vs mutable infrastructure.
[387]
Now, breaking that down:
[389]
an immutable infrastructure is one that can't be changed,
[394]
it can't be mutated.
[396]
Now, at first impression, that might sound like a bad thing,
[399]
but let's break this down by seeing an example
[402]
with a mutable approach to infrastructure architecture.
[406]
So, we have our example here,
[408]
and let's say that we're building out the app and we decide
[412]
we need a database.
[413]
So, to do so, we'll run a script
[417]
in our development environment.
[419]
This brings up that database within our VPC.
[422]
Now all of this is working great,
[424]
so we say, "Hey, let's just run that script across all of the environments that we have."
[430]
Now, let's say that 99% of the time that works fine,
[433]
but some of the times it fails,
[435]
and you're in a weird limbo state.
[437]
So, let's break that down.
[439]
So, we're going from version one to version two.
[447]
Now, we have infrastructure code
[450]
in place to bring up version one,
[452]
but now we ran this custom script
[454]
to move it from version one to version two.
[459]
What we essentially have right now is something called "configuration drift",
[463]
or "environment drift".
[465]
Our existing environment is no longer matching what we have in our automation.
[471]
Now, the problem is:
[472]
to help debug those problem situations
[475]
you would have to wipe out the entire environment
[479]
and then redeploy version one and then run those scripts.
[482]
Now, that might seem OK the first couple of times you do it,
[485]
but when moving to scale it becomes incredibly hard to maintain.
[489]
So, with an immutable approach
[491]
to infrastructure and infrastructure automation,
[494]
every time you want to make a change to the infrastructure
[497]
you bring up a brand new environment alongside the old one
[501]
and then, once you verify that they're both working,
[503]
you can bring down the older version.
[506]
Now, it's a little expensive because
[508]
you can imagine that you're running both environments at the same time,
[512]
but, in general, it's the best practice
[515]
to ensure that your infrastructure can move to scale.
[518]
Thanks for joining me for this quick overview of infrastructure as code.
[521]
If you want to learn more about this, or DevOps check out the link below.
[525]
Remember you can always get started with a free account on IBM Cloud.
[529]
Thank you.