[Music]
hello my name is norm from the dotnet
team at a TBS in this video we are going
to talk about Amazon Elastic container
service or ECS for short with dotnet
core VCS is a container orchestration
service that supports docker containers
before we dive into deploying our Dutton
core applications to ECS let's take a
look at how the easiest resources work
together first there is the cluster
which is a logical grouping of our
containers the cluster then has
container instances which are ec2
instances that provide the compute
resources for our cluster next we have
task definitions which tells these es
how to run our container this is where
we declare how much memory and CPU for
the containers you can also set an item
role to give your container a tubes
credentials to access eight of your
services then you can run tasks for your
task definition running a task on a
cluster is for transitory processes that
means when the process declared in the
docker build file exits the tasks
running the container will terminate
when the task starts up it will download
the docker image from the container
registry whether that is docker hub or
Amazon Elastic container registry or ECR
for short another way to run your
containers is as a service this is for
things like web servers where you want
the test to run indefinitely a service
will run a declared number of tasks for
it and will monitor their health if any
of the tasks fail it will restart new
tasks now if our container is a web
server we probably want to tie all these
tests to a load bouncer to provide one
URL endpoint and spread the traffic
across all of the tasks the service will
register the healthy test to the load
balancer and will deregister them if any
of the text become unhealthy once they
are registered the load balancer will
take care of sending the traffic to the
test running our container
any of this far gate is a new technology
for ECS that you can use to deploy your
containers to easy s with Fargate you
don't have to manage any easy to
instances and the compute capacity will
be auto provision at lunch time when you
launch your containers with Fargate you
reserve the amount of CPU and memory
needed for your container and forget
tasks take care of the rest if you are
not using ec2 instances the cluster
creation is simplified all you need to
do is specify a name for the cluster and
when you launch your Fargate based test
provide the VPC configuration and easy
to security groups if we look back at
the ECS diagram we showed before who is
far gate that means that container and
says disappeared and is no longer our
concern with Visual Studio 2017 and the
ADA we still get for Visual Studio you
can deploy dotnet core applications to
directly to easy s let's go take a look
at how you can do that here we are in
visual studio of 2017 and we have the 8
of 6 bar here again on the left
to get started with deploying let's
create a brand new project I'm gonna
create one on this solution I've already
set up
it's an add new project and I'm gonna
deploy a dotnet core a spinet core web
application we're just gonna call this
our web front-end where I say ok and
this is a web application and we're
gonna take advantage of visual studios
doctor support and let it generate a
docker file for us push ok
and here is our project this is just the
standard project facility to occur it
for us and here we have is a docker file
that Visual Studio set up for us on how
to actually build the docker image with
that docker file on there that triggers
they took it to note you can deploy it
to AWS so if I right click we now have
the option to publish the container to
AWS now here's where we start a wizard
and the deployment targets is where we
can see how different options to deploy
this we could do it as a service as a
task a scheduled task or we could just
push this as a darker image to ECR and
then later push it to a service so this
is a web server we're gonna push this as
a service and I'm going to leave this
checked to save the default settings and
it's also going to set up my project for
command line deployments afterwards next
we have to decide what cluster we want
to launch this to and how we want to
launch it I'm gonna use a brand new
cluster today we're gonna call this demo
cluster and I'm gonna use Fargate to
deploy this so I don't have to think
about any ec2 resources when launching
this I just specify my CPU and memory
which I'm going to leave at the default
and my V PC and security groups that I
want for that compute resources so again
push next and then we have to define the
service for our web server here we can
say how many instances of this service
of people run since we want to make sure
this is highly available we're going to
create three tasks with that so there's
gonna be three instances of my web
application running in Fargo push next
and now we're have three different tasks
we want to have them be using an
application load balancer to spread the
traffic across all of our different
instances I'm going to configure that
we're gonna create a brand-new load
balancer I'm going to leave everything
else with the default where it's gonna
create a target group called web
front-end and it's going to say for all
requests send them to this target group
and our Fargate instances will be
attached to that target group and we
must make sure that the health
check is pointing to a valid URL within
that container because that's how it
knows that the tasks are healthy enough
to be added to our load balancer so
hopeless next next we need to find the
task definition for our application
we're gonna create a brand new one and
this is where we can specify an iamb
role that we want to use for application
our application isn't using any of the
services but right now but you can just
set the easiest demo to have it if we
want to add access database services
later
we could also specify any additional
port mappings or environment of rebels
but the toolkit by default will detect
this is a web application an open port
80 and set the production a spinet core
environment variable that's that will
just push polish and that's going to
begin our deployment process so it's
going to create our application load
balancer it's then going to use the
docker CLI to go and build our docker
image once that docker image is complete
it's going to log on to ECR
and then push our docker image to ECR
and with that it'll then create our
service on our cluster now that will
take it about a minute so we're going to
fast forward the video while that
happens
once the deployment is finished the EECS
cluster view comes up which is available
from the 80s Explorer and if we can see
here will refresh we have three tests
pending these are our far gate tests
that are currently being pending and
it's the compute resources are being
provisioned for those tasks so this will
take about a minute for those far gate
tests to come online so again we're
going too fast for the video for those
tests to come on now we can see we have
three running tests all running serving
our application and we have one URL
pointing to it you can click on that and
we can see here is our web application
that has been deployed now this was an
example how we could deploy a front-end
application but what if we also want to
serve is a second app project for our
Web API projects we can do that by
creating a new project
camels licked page my core application
will call this our Web API this time
looks like webby I project template and
again we're gonna have the Dockers port
enabled and we can then just deploy it
to our same cluster into our same
application load balancer I do that we
right click publish continue to us again
we're doing a service we're gonna select
the cluster we just created we're gonna
do it again as a far gate and leave
everything else of the defaults we're
going to create a brand new service
though so let's do the second service
running in our cluster and maybe for
this we don't need as many tasks maybe
for this one really need two tasks for
it go ahead push next and we'll
configure that load balancer for it
we're going to select the same existing
load balancer and this time we're going
to get a new target group for our Web
API and the path pattern is going to be
slash API so this means all requests
that come in to our load balancer that
start with slash API will go to this
target group which will be these Fargate
tasks anything else is going to go back
to our original web front-end so this is
how we can reuse the same cluster and
same load balancer with different
projects
but we must make sure that the health
check is pointing to a valid place
within the container so we're gonna use
the default one in there a API slash
values great again a new tax definition
for it and we can set a role for it
we're gonna leave everything else here
at the defaults and go ahead and publish
that and this is gonna go run that same
deployment logic that we saw before
using the doctor CLI to build a docker
image and push it to ECR well go ahead
and fast for this video while that
happens
and now we can see back on our cluster
view we have our second task and here we
have those two tests currently in the
pending state so we'll go ahead and fast
forward the video while those tests go
into the running state now our Web API
has its two tasks up and running and we
can see we have our euros down here
let's go ahead and click that and you
can see that our web api was calls on
the same a load balancer that our web
front-ends if i go back and remove this
part i can see here we have both our web
front-end and the web api going to the
same load balancer and using the same
cluster now so far we've shown how you
deploy web applications to ACS but
another feature that you can use is you
can also deploy just console
applications this is a good way to do
service applications things that run in
the background let's go ahead and create
a new DynCorp console application so on
this we're going to say add new project
just select a console application from
the dotnet core section and we're going
to create a console application it's
gonna go and list all of my as three
buckets
let's call it bucket Lister and this is
using s3 so I'm going to pull on the s3
nuga package give this sdk s3
okay now we have that package now
I already have this code written so
let's go ahead and copy that out here's
the code very simple code of using our
s3 client to go list our buckets and
print them out to the console and let's
now deploy this to VCS I'm going to
right click on that and we need to
enable docker support for this and we
can do that in Visual Studio by setting
add dr support once will generate our
docker build file you can see in that
docker build file is where it's gonna
say this is the process we were on a run
let's select publish container to AWS
now in this case this is not a process
that we want to run forever we just want
to run this process for the link it
takes to list our ester buckets and
that's when we would on deployed as a
task now so far we've shown deployments
using Fargate but let's go ahead and use
a cluster that I already have that has
some ec2 instances on there so that
we're gonna select that cluster and
choose the launch type of ec2 and so the
VP CL is gonna be used by the instances
that it's gonna be deployed to click
Next and here we can specify it to tasks
configurations we could specify to spend
up multiple versions of this task but
for this case we just want one task
that's gonna print out our three buckets
I move define our task definition and we
need to give it some memory that we want
for this a minimum amount of memory
we're gonna say this is pretty small it
just needs 128 Meg's of memory and we
need to give it a task role to be able
to access s3 so we'll use our existing
role there we're not gonna be exposing
any ports I don't even remember apples
to set so there's nothing in you dear
I'm just gonna go ahead and push publish
and that's gonna get and run our darker
build process to push that and then push
this image to ECR
so this will take that minute so we're
going too fast for the video while that
happens
so here's our ec2 cluster view let's go
look here is our task that we just
launched it's currently pending this
will launch pretty quickly because it
compute resources are already available
it's the ec2 instance in fact if i
refresh this it's already run to
completion and we can see that if we go
to stopped we can see if that task is
already run now to go see the actual
buckets here I can actually go look at
the console and let's go to cloud wash
logs rid of the logs view in cloud watch
and you can see for every one of our ECS
tasks out there a log group was created
and all of the console right lines are
automatically written to that so here's
our bucket list ER and then look at the
stream here's all of my s 3 buckets
there so that's how you can get logging
information from your cluster from your
containers by these and cloud which logs
in writing to the console now one last
thing I wanted to show you is in every
one of our deployments we always had the
easiest tools defaults file that saved
our deployment settings and it also
configured our application deployed to
the COI
in fact if we go look at the cs proj
file when we had that checked this was
added to each of our projects and that
means now if I go to the command line
will make that little bigger I can now
type to hotnet ACS help and there's
those same deployment commands so the
same thing we did in Visual Studio we
can also do from the command line so I
could rerun the same deployment they
saying dot net you see us deploy tasks
and I don't need to specify any
parameters because everything was saved
in that defaults file and that will run
and when we run the same deployment
logic that we did in Visual Studio in
this video we learn how to use dotnet
core with ECS to deploy container
applications thanks for watching
[Music]