Deploy Inventory Service to EKS

Purpose & Background

Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service. EKS is the best place to run Kubernetes for several reasons. First, you can choose to run your EKS clusters using AWS Fargate, which is serverless compute for containers. Fargate removes the need to provision and manage servers. Second, EKS is deeply integrated with services such as Amazon CloudWatch, AWS Auto Scaling, AWS Identity and Access Management (IAM), and Amazon Virtual Private Cloud (VPC), providing you a seamless experience to monitor, scale, and load-balance your applications. Third, EKS integrates with AWS App Mesh and provides a Kubernetes native experience to consume service mesh features and bring rich observability, traffic controls and security features to applications.

In this part, you will learn to create an EKS cluster and deploy the inventory service to that EKS cluster.

Prerequisites

  • Environment Setup
  • Facade Configuration
  • Containerized Inventory Service

Install eksctl on Windows using Chocolatey

Before you create an EKS cluster, you need to install a command line tool named eksctl on your developer desktop.

  1. Install eksctl using the following command in the PowerShell.

    chocolatey install -y eksctl 
    
  2. Test that your installation was successful with the following command.

    eksctl version
    

Create an EKS cluster using eksctl

  1. Create your Amazon EKS cluster with 3 Linux nodes with the following command:

    eksctl create cluster --name UnishopCluster --version 1.17 --region $(aws configure get region) --nodegroup-name unicorn-workers --node-type t3.medium --nodes 3 --nodes-min 1 --nodes-max 4 --managed
    

    If you encounter an error saying “Cannot create cluster ‘UnishopCluster’ because xx-xxxx-xx, the targeted availability zone, does not currently have sufficient capacity to support the cluster…", please go to the AWS Management Console, navigate to CloudFormation and delete the stack named “eksctl-UnishopCluster-cluster”. Then, retry the command above.

  2. While the command above is running, you will see several lines of output. It usually takes you around 20 minutes to create an EKS cluster. When your cluster is ready, the last line of output is similar to the following example line:

    [✓]  EKS cluster "UnishopCluster" in "YOUR_REGION_NAME" region is ready
    

    successfullly create cluster

  3. Once your cluster is ready, use the following line to test that your kubectl configuration is correct.

    kubectl get svc
    

    Here is the SAMPLE output of the command above:

    NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
    kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   1m
    

Get the URI of your ECR repository

  1. In your AWS Management Console, navigate to Elastic Container Registry.

    search ecr

  2. In the Elastic Container Registry Console, you will see a repository named “unishoprepository”. Please click the copy button besides the URI to copy the URI of that repository. Note down this URI in your cheat sheet (You should paste it under “URI of ECR repository”).

    copy URI

Deploy the service using kubectl

  1. Open the kubernetes config file named “deployment.yaml” under the following path:

    C:\Users\Administrator\AWS-workshop-assets\net-modernization\InventoryService\build\
    
  2. In the “deployment.yaml” file, you will find a comment “# Input Image URI from ECR” in the line 37. Right before that comment, enter the value of “URI of ECR repository” in your cheat sheet. (If you forget to copy this value to your cheat sheat, please refer to this section.)

    change URI in deployment.yaml

    Kubernetes objects can be created, updated, and deleted using declarative configuration files and kubectl apply to update those objects as needed. The yaml file above defines a deployment. You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.

  3. Use the following command to apply that kubernetes config file:

    kubectl apply -f C:\Users\Administrator\AWS-workshop-assets\net-modernization\InventoryService\build\deployment.yaml
    
  4. Since you specified a service resource with type “LoadBalancer” in the configuration file, an application load balancer will be set up. After the inventory service is deployed to EKS, let’s get the URL of the load balancer with the following command:

    kubectl get svc
    

    The result looks like this:

    URL of lb

    Please copy the EXTERNAL-IP value of the “inventory-service-service”, paste it into the address bar of your browser and append /api/unicorn. Visit that endpoint and you will see the info of all the unicorns.

    The deployment may take several minutes. You may not be able to access the endpoint immediately.

    Info of unicorns

    You may notice that new Unicorns uploaded to the Aurora database in prior labs are not displayed. EKS requires a specific network configuration and will not deploy in the default VPC you have been using throught the workshop. Therefore, the deployment configuration applied above is using an in memory database. You can configure VPC Peering to access the Aurora database, but it outide the scope of this lab.

  5. One of the advantages of EKS is that you can use kubectl to do a range of things. Let’s scale out the inventory service using “kubectl scale” command.

    5.1 Check the number of pods before scaling out the service and you will see 1 running pod.

    kubectl get pods
    

    The output will look similar to this:

    NAME                                            READY   STATUS    RESTARTS   AGE
    inventory-service-deployment-5744f9f6b6-xhsms   1/1     Running   0          29m
    

    5.2 Scale out the service using the following kubectl command:

    kubectl scale --replicas=5 deployment/inventory-service-deployment
    

    Check the number of pods using the command below and you will see 5 pods are running.

    kubectl get pods
    

    The output will look similar to this:

    NAME                                            READY   STATUS    RESTARTS   AGE
    inventory-service-deployment-5744f9f6b6-28xfx   1/1     Running   0          6m48s
    inventory-service-deployment-5744f9f6b6-8v7zf   1/1     Running   0          4s
    inventory-service-deployment-5744f9f6b6-g4qml   1/1     Running   0          4s
    inventory-service-deployment-5744f9f6b6-w8dbt   1/1     Running   0          6m48s
    inventory-service-deployment-5744f9f6b6-xhsms   1/1     Running   0          41m