Wednesday, August 12, 2020

Steps to Setup EKS (AWS) & Deploy the application

in order to setup EKS needed AWS account and follow the steps

1. create your Amazon EKS cluster role in the IAM console

  •   Open the IAM console https://console.aws.amazon.com/iam/
  •   Click on Roles, then Create role.
  •   Select EKS from the list of services, then select EKS-Cluster, and then click  on Next: Permissions.
  •   Click on Next: Tags.
  •   Click on Next: Review.
  •   For Role name, enter a unique name for your role, in my case i have choose My-EKS , then click on Create role.

attach the below policies 

2. VPC creation with public and private subnets using cloud formation

  • Open the AWS Cloud Formation console at https://console.aws.amazon.com/cloudformation/
  • Choose a Region that supports Amazon EKS, in my case i choose: US East (N. Virginia)

    us-east-1

  • Choose Create stack.

  • For Choose a template(Template is ready), select Specify an Amazon S3 template URL.

  • Paste the below URL and click on Next

 https://amazon-eks.s3.us-west-2.amazonaws.com/cloudformation/2020-05-08/amazon-eks-vpc-private-subnets.yaml

  • On the Specify Stack Details page, give unique name of your stack name, in my case i choose eks-vpc and click on Next
  • on the  Configure stack options page, Click on Next
  • on Review eks-vpc page, Click on Create stack
  • Note down the below details from created stack outputs , those will help while creating the EKS cluster 
        SecurityGroups, SubnetIds and VpcId


3. Create EKS cluster

            Name  : EKS-Cluster

            Kubernetes version : choose latest one, in my case 1.17

            Cluster Service Role : select the role which was created in IAM role, in my case its MY-EKS

  • On the Specify networking page, provide the below details and click on Next 
                       VpcId ,  SubnetIds , and  SecurityGroups (which are noted down above step 2)

                      Cluster endpoint access , in my case i choose as Public and private

  • On the Configure logging page, for time being skip this step and click on Next
  • On the Review and create page, just review the details and click on Create
EKS-Cluster creation will take some time, so mean time we will create a Ec2 instances to manage the EKS cluster

4. Create ec2 instance with default VPC to connect or manage EKS cluster nodes.

    After crating Ec2 instance and login to the box with root and execute the below steps.

   Configure aws cli  : 

        curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

        unzip awscliv2.zip

        sudo ./aws/install

   Configure kubectl  :

        curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

        chmod +x kubectl

cp -rp kubectl /usr/local/bin/

   Configure aws-iam-authenticator :

          curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.7/2020-07-08/bin/linux/amd64/aws-iam-authenticator

  

5. Create worker node from Cloud formation:

follow the same steps which we done for VPC, create a stack for worker node with below link

https://amazon-eks.s3.us-west-2.amazonaws.com/cloudformation/2020-05-08/amazon-eks-nodegroup.yaml

Output is like below:  note down the NodeInstanceRole from the ourput , it will be use in further steps.

and also please check the EC2 dashboard for the created worker nodes:

6. go to the Ec2-instance of management server (K8S-mgnt-instance) and follow the steps

Execute   aws configure and provide the below details 

(take the Security credentials by the Root user)

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE

AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Default region name [None]: region-code

Default output format [None]: json

Execute aws eks --region us-east-1 update-kubeconfig --name EKS-Cluster (your cluster name which you are created)

create -f auth-cm.yaml with update NodeInstanceRole from worker node stack outputs

in my case NodeInstanceRole as arn:aws:iam::021723903628:role/worker-node-NodeInstanceRole-YDOVWVCF5M2L 

7. Create auth-cm

 echo 'apiVersion: v1

kind: ConfigMap

metadata:

 name: aws-auth

 namespace: kube-system

data:

 mapRoles: |

   - rolearn: arn:aws:iam::021723903628:role/worker-node-NodeInstanceRole-YDOVWVCF5M2L

     username: system:node:{{EC2PrivateDNSName}}

     groups:

       - system:bootstrappers

       - system:nodes' |kubectl create -f -

8.Testing

 Execute kubectl get nodes


so till now we have completed the EKS setup successfully. Now Deploying the Java application on Loadbalencer deployment.

Create a Yaml file as deployment.yaml ( used my Deployment yaml file for the demo)

then deploy as kubectl create -f deployment.yaml

just hit the load balencer url: http://ad5336b2ca0134d8c88a6bd2f70b8105-1222290310.us-east-1.elb.amazonaws.com/


1 comment: