Okay.
So to create our EKS cluster on AWS, we're going to use a command line tool called Eksctl, which is
the official CLI for Amazon EKS and will allow us to easily create and manage our clusters from the
command line.
So to get started, let's click on the introduction page and we are@eksctl.io click on Introduction.
And then on the right here, let's click on installation to find out how we can install Eksctl so you
can see for your operating system.
We have different installation commands here is for Windows and for Unix.
So go ahead and copy and paste these commands into your terminal to make sure you have eksctl properly
installed.
So after you have it installed, you should be able to go to your command line and run eksctl get clusters
and this is going to use the default AWS credentials we set up at the beginning.
We want to go ahead and define a new cluster config file in our project that will define how our cluster
is created.
So if we go back to the documentation and go to the home page, we can scroll down until we find a default
cluster dot yaml file.
Let's go ahead and copy this and then we can go back to our root project and create a new cluster dot
yaml and I'll paste in this cluster config.
Where we can change the name to be called Sleeper.
And I'm going to change the region to be closest to me, which is us East one.
Phil feel free to use whichever region you would like.
And then importantly, we have different node groups defined and this is going to be the nodes we have
available to run our workloads.
In our case, we only want to run one node group so we can call it NG1 and we want to change the instance
type to AT2 micro instance.
This type of instance is available on the free tier, so we won't be charged for its usage if we don't
go above the default CPU limits of 750 burst hours a month.
We can also specify the number of nodes we want to have.
In this case, we can just keep this at three.
So now we have this cluster defined.
We can run eksctl, create cluster and then provide dash dash config and then provide dash F and then
provide the cluster dot YAML file.
And now Eksctl is going to execute tasks through CloudFormation to create our cluster.
So go ahead and let this command finish.
It might take some time to create the cluster.
So after some time we can see that our ECS cluster has finished creating and we can see this note here
that our kube config has been updated automatically.
So now we can run kubectl, get nodes and we can see the three nodes that have been provisioned in our
cluster.
We can run eksctl, get node groups and specify the cluster is sleeper to see the current node groups
in our cluster and we can see the size is at three.
Okay, so now we're ready to actually install our helm chart into our ECS cluster.
Firstly, we need to make an update to our helm chart to point our images at our repository.
So let's open up our build spec and then let's copy the name of the reservation's image and we'll go
into our helm chart and open up our templates folder reservations deployment, and then we'll go ahead
and swap out the image to be pointing to ECR.
Now let's go ahead and do the same thing for Auth.
We'll copy the tag and swap this in for the image.
We'll grab the payments image and do this for the payments deployment as well.
And finally, we will grab the notifications repository.
And swap out this image.
So before we deploy our helm chart into X, we need to provide the secrets needed for our deployments.
The easiest way to do this is to run kubectl config, use context, Docker desktop and switch back to
our local Kubernetes cluster.
We can of course now run Kubectl, get secrets to see our secrets that we've created previously that
needed for our deployment.
So now I'm going to run kubectl, get secrets and output this to YAML and pipe it to a secret yaml file.
Then I'm going to open up the newly created secret dot yaml file which is just going to be a temporary
file and I want to get rid of the GCR json key.
So let's remove this first entry here so that we just have the other secrets that we want to carry over.
So now let's run kubectl config, get context to get all of the contexts in our system and our Kubernetes
clusters.
And I want to copy the context for our ECS cluster.
So copy this one and then we can run again kubectl config, use context and paste in our context.
So now we can again run kubectl, get nodes and see our EC2 instances again.
But now importantly I want to run kubectl, create dash f for file and apply the secret yaml we've created
and now all of our secrets will be created.
Then I'll go ahead and make sure we delete this temporary secret file so we don't expose these secret
credentials.
Now that our images have been updated, we can CD into our folder and then CD into the sleeper directory.
And now we're going to run helm, install sleeper and specify the path.
Is the current directory to the helm chart.
Now you can see that our deployment was successful.
So after giving our helm chart a little bit of time, we can run kubectl, get pods and see that all
of our pods are in a running state.
We can then get the logs of our reservations or any one of the pods and see that it has fully started
up and is listening.
Next, let's look at how we can provision a load balancer to expose an externally available URL that
won't change.
So a quick note.
If you run Kubectl, get pods and you find that some pods aren't starting up because of the fact that
there are not enough nodes available, we can easily scale up our existing node group by running eksctl
get node groups in our cluster of sleeper.
And then we can say Eksctl Scale Node Group Ng1.
And set dash n to five.
You can see that our max size also needs to be updated so we can provide a dash capital M five to increase
the maximum number.
So in order to provision a load balancer in ECS, we're going to use the AWS load balancer controller,
which you can find at Kubernetes.
Dash SIGs dot Github.io Slash AWS load Balancer controller.
Now this load balancer controller is automatically going to provision an application load balancer inside
of AWS.
Anytime we create a service with an ingress resource, so to install this load balancer controller,
we click on the deployment link and then click on configure IAM.
Scroll down to the steps to set up the load balancer controller and we'll copy this first command where
we associate an Iam Oidc provider and go ahead and paste this in.
We just need to change the name of our cluster to be the one that we are using.
In this case I'm using the sleeper cluster and then we'll change the region to whatever region we're
using, in this case US East one.
Next, we're going to download the IAM policy based on the region we're in.
So we have one for the US government cloud China and all other regions.
So I'll copy the all other regions, curl this and download it to the current directory.
And then we create a new policy based on this downloaded file.
So copy this command, paste it in and enter to create a new policy.
Finally, we want to create an IAM service account using this policy so paste this final command in
to have eksctl take care of this for us in creating an IAM service account.
So we need to provide the region like we just did before.
So this would be us East one for me.
And then importantly, we need to provide the AWS account ID associated with our account.
So in order to get this, you can go back to the AWS console, go to the IAM dashboard and copy the
account ID in the right here.
And then go ahead and swap this out in this command.
Finally, we need to provide the name of the cluster we're installing this into.
As we've done before, this will stay the same as Sleeper.
So enter this and let Eksctl roll out a CloudFormation to create this.
So finally we're ready to actually install the load balancer controller.
So scroll down to the summary where we get the first command to add the helm repository and paste this
in.
Now that we have the repository, we're going to go ahead and apply the helm chart with this next command.
Now finally we can actually install the helm chart, so we're going to copy this command for clusters
with RSA, copy this command and now paste it in.
Of course, we'll need to update the cluster name as we've done before, so go ahead and update that
to Sleeper.
So go ahead and swap this out to our cluster name of Sleeper and let this helm chart install.
Now, if we run kubectl, get pods in the KUBE system, we can see to load balancer controller pods
running and we can run kubectl logs in the KUBE system and follow this to get some logs and we can see
that the load balancer controller is up and running and watching our services now.
So back in our helm chart, we can remove this temporary IAM policy we created.
Now finally, in order to tell the load balancer controller about our ingress resources, we need to
include some annotations on our ingress.
So let's add a new annotation section here where we define two new annotations, the first of which
is going to be ALB ingress dot kubernetes.io slash scheme internet facing to make sure that this load
balancer is attached to a public subnet that is externally facing.
And then we provide the Kubernetes ingress class ALB to provision an application load balancer.
So let's go ahead and save this and then we can run helm, upgrade Sleeper and provide the root path
here.
Now we can run Kubectl, get ingress and we can see that a new address has been provisioned for us.
It will take some time for the application load balancer to get provisioned and we can even check the
status in AWS by going to the EC2 dashboard and then scrolling down to load balancers.
And then we can see our application load balancer that is in a provisioning state.
So let's go ahead and let this finish provisioning.
After a little bit of time we can see the status has now switched to active.
So if I copy the DNS name now, we can then open up Postman to test out this load balancer.
So now in Postman, if we enter in our load balancer URL and enter slash reservations with a with a
trailing slash and send off this request, we get a response back from our reservations deployment,
which is great to see because we're not passing in any information, but we are able to reach our application
externally from this URL, which is great to see.
Now we have a way to provision an external load balancer and expose our application externally.