Showing posts with label Kubernetes. Show all posts
Showing posts with label Kubernetes. Show all posts

Tuesday, September 12, 2023

Deploying a application in Kubernetes Cluster with Amazon EKS

 Description: Here I have explained, what is Amazon EKS? How to deploy Kubernetes Cluster with Amazon EKS

What is Amazon EKS?
Amazon EKS [Elastic Container Service for Kubernetes] is the managed Kubernetes service which allows you to run Kubernetes on AWS. In the cloud, Amazon EKS automatically manages the availability and scalability of the Kubernetes control plane nodes responsible for scheduling containers, managing application availability, storing cluster data, and other key tasks.

Prerequisites 
Below are the prerequisites to setup Amazon EKS

  • AWS CLI: You will need version 1.16 at least. Follow the URL for setup and version details
  • Kubectl: This command is used for communicating with the cluster API server. Refer URL to setup and version details
  • AWS IAM Authenticator: To allow authentication with kubernetes cluster need to setup IAM user for kubernetes 


AWS EKS ROLE: First we need to setup EKS role in IAM. To create the IAM role perform the below steps

  • Open IAM service in AWS and navigate to Roles 
  • Click on Create role 


  • Filled all the required details in form, Select AWS Service,  in service use case select EKS and select EKS-cluster in specified service as in screenshot


  • You will get the permission list in the review page

  •  Give name the cluster "eksClusterRole" and validate the trust entities as screenshot and create the  role




AWS IAM User: After creating AWS EKS role with eksClusterRole name now we need to create and setup IAM user in the local machine to run the AWS commands 

  • To create the user navigate to IAM --> Users --> Create User 
  • Fill all the required details and create the user with Administrator access privileges and EKS service privileges


     
  • In the example I create user with the name AWSEKSUSER
  • After create the user I am going to add access key to access the AWS APIs using CLI. So navigate to the user properties and click on create Access Keys. Make sure to download the csv file of credentials 
  • Once the user created setup user in local instance AWS CLI using aws configure command line utility 




Kubectl: Kubectl utility is command line utility that used to communicate with Kubernetes API server.  Here is the URL to setup Kubectl utility

You can verify the version of kubectl using kubectl version command 


IAM Role for EKS Node: We also need IAM role for EKS worker node. So to create the role again navigate to IAM and create the role with required permission.

Rolename: AmazonEKSNodeRole




Setup Amazon EKS cluster: After full filled all the prerequisites we are going to setup AWS EKS cluster.

  • Navigate to EKS service in AWS and click on Add Cluster
  • It will pop-up form to create the cluster filled all the required details and select eksClusterRole which we have created previously





  • Need to select VPC and subnets, So in this example we used default VPC in us-east-1 region 



  • Select public interface for cluster



  • Now select the element which you want to enable the logs. But in the example I am not going to enabled anything 



  • Select the add-ons which need to add with the setup. So I am taking the default add-ons 



  • Select the version for each add-ons. In this example I used the default versions



  • Review the details and click on create. It will take around 20 minutes so wait until the process completed. 


  • Once the process completed you will find active status in cluster


Node Group
  • To create the node group navigate to newly created cluster --> Compute tab
  • Under Compute tab option to create "Add node group"


  • Once you click on Add node group you will find form for the node. You need to fill node-group name and IAM role which created for node and click on next 



  • Next step to Set configuration for node group. Fill all required details like AMI, instance type, scaling configuration etc. In this example I used Amazon EC2 AMI, t3.Medium instance type, disk size 20 GB and scaling group 2 for each




  • Next select the sub nets included in node. It will automatically selected the required sub nets. 
  • Review all the details and click on create. It also took few minutes to create it 



  • Once the node group created it shows in active status 



You will get the nodes under the cluster as follow



Configure EKS cluster in AWS CLI: After performing all the above steps now need to configure and manage EKS cluster in AWS CLI. In previous steps we configured AWS cli in the local linux machine. So we used same IAM user to manage the EKS cluster.

First step to configure EKS cluster using AWS Cli, below is the command to configure same

$ aws eks --region us-east-1 update-kubeconfig  --name example-cluster

Note: In above command need to change the region and the name of the cluster. In this example we created cluster with the name example-cluster. Once the command executed the configuration exported to .kube/config file 


Once account configured you can get nodes details from the cluster using command line

$ kubectl get nodes



Setup K8-Application

Once all the configuration done need to checkout the K8 application from the GitHub repository. To checkout the application create one folder and checkout the master branch from the give GitHub repository

https://github.com/harpal1990/k8-application.git

once repository checkout navigate to k8s-specifications directory under repo. You will find different files relevant to kubernetes application 


Now I am going to run each yaml file one by one in a sequence as follow


$ kubectl create -f voting-app-deploy.yaml
$ kubectl create -f voting-app-service.yaml
$ kubectl create -f redis-deploy.yaml
$ kubectl create -f redis-service.yaml
$ kubectl create -f postgres-deploy.yaml
$ kubectl create -f postgres-service.yaml
$ kubectl create -f worker-app-deploy.yaml
$ kubectl create -f result-app-deploy.yaml
$ kubectl create -f result-app-service.yaml





You will get the result of deployment and service using below command

$ kubectl get deployments,svc


In the above screenshot we can see all the services pod up and running with 2 load balancer type service 

First I am opening the voting-service public url for voting application and select the cats for vote

http://a25ca28a3348a407e8bdd3f912145b48-1964993370.us-east-1.elb.amazonaws.com/




Now after vote open the result application for result using below url

http://a8a7f7a6a4e4044dd89c1f08ecb5707c-548992896.us-east-1.elb.amazonaws.com/






So in this way we can deploy kubernetes application to Amazon EKS



Sunday, August 9, 2020

Introduction of Kubernetes

Description: Here I have explained, What is Kubernetes and Architecture of Kubernetes

What is Kubernetes: Kubernetes open source  and popular container orchestration developed by Google and then hand over this project to Cloud Native Computing Foundation. Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. 

Architecture:  Kubernetes follows (master) Server client architecture First Master server need to configure then need to install client (node) on separate Linux server.

Master Components:  Following are the components use in Kubernetes Master Machine

  1. etcd: It store configuration information which use by each of the nodes in the cluster. It is highly available key vale store that can be distributed among multiple hosts
  2. API Server: Kubernetes is an API server which provides all the operation on cluster using the API. API server implements an interface, which means different tools and libraries can readily communicate with it.
  3. Controller Manager: This component is responsible for most of the collectors that regulates the state of cluster and performs a task. In general, it can be considered as a daemon which runs in non terminating loop and is responsible for collecting and sending information to API server
  4. Scheduler: This is one of the key components of Kubernetes master. It is a service in master responsible for distributing the workload. It is responsible for tracking utilization of working load on cluster nodes and then placing the workload on which resources are available and accept the workload
Node Components:  Following are the components use in Kubernetes Node Machine
  1. Docker:  Docker is use to run and manage  application container. Container is light version of operating system
  2. Kubelet Service:  This service is responsible for relaying information to and from control plane service. It interacts with etcd store to read configuration details and wright value.This communicate with master and receive commands to work. It manage network rule, port forwarding. 
  3. Proxy Service: Proxy service run on each node and help in making service available to the external host. It manage pods on node, volume and container's health checkup