Thursday, November 22, 2018

Monitor the EKS cluster Infrastructure


This is the GitHub dashboard and  the repository details are mentioned below,

https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

You can run below command to configure the dashboard.

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml


clip_image002

After that you need to get the password for that run the

# kops get secrets kube --type secret -oplaintext

clip_image003

Then go into https://api.cloudwar.xyz/api URL and give the user name and the password. Here username is Admin and the password can be find by running the above command.

Select Kubeconfig and then select skip. You will be forwarded to the dashboard.

clip_image005

In this dashboard you can see the utilization and based on that you can decide whether you want to do the scaling up or down.

There are few other tools as well. you can try them also. But for me this dashboard covers my needs.

How to configure auto scale in EKS cluster


Exit from the master node and run the “kops edit ig --name=cloudwar.xyz nodes”

clip_image002

Change the MaxSize and the MinSize in to 3 instances then save the file. Then run

# kops update cluster cloudwar.xyz –yes

clip_image004

If you go into AWS EC2 console and check now you can see new instance was created

clip_image006

Error Creating the load balancer in EKS cluster


If you get an error like below that means you have a permission issue with the IAM role assigned.

clip_image002

To fix that issue you can first run “kubectl describe services hemalq-nginx” - hemalq-nginx is my the service and you will get actual issue with that.

Go into IAM and create a new policy

Select the JSON and paste the below mentioned policy

------------------------------------------------------------------------------------------------------------------

{

"Version": "2012-10-17",

"Statement": [

{

"Effect": "Allow",

"Action": "iam:CreateServiceLinkedRole",

"Resource": "arn:aws:iam::*:role/aws-service-role/SERVICE-NAME.amazonaws.com/SERVICE-LINKED-ROLE-NAME-PREFIX*",

"Condition": {

"StringLike": {

"iam:AWSServiceName": "SERVICE-NAME.amazonaws.com"

}

}

},

{

"Effect": "Allow",

"Action": [

"iam:AttachRolePolicy",

"iam:PutRolePolicy"

],

"Resource": "arn:aws:iam::*:role/aws-service-role/SERVICE-NAME.amazonaws.com/SERVICE-LINKED-ROLE-NAME-PREFIX*"

}

]

}

------------------------------------------------------------------------------------------------------------------

clip_image004

Then as we done in the initial stage, assigned this newly created poly into the Ubuntu instance and run the create load balancer command

Then once you go into the AWS Loadbalancers, you will see there is a new LB created. Under instances, you can find two instances also added.


image

Load Balancing the cluster

Here what I going to create an AWS load balance and point that to the created Pods. First run the below command

# kubectl expose deployment hemal-nginx --port=80 --type=LoadBalancer

Then run

# kubectl get services -o wide

clip_image002

If you get an error like below that means you have a permission issue with the IAM role assigned.

clip_image002[5]

To fix this you need to add an IAM role with the required permission. The steps can be found here.

Deploy a Pod in to Kubernetes Cluster


First need to SSH into the Master node. The steps were covered in the previous post. Once you ssh into the master node you can run the below command. I have given the name as “hemal-nginx”

# kubectl run hemal-nginx --image=nginx --replicas=2 --port=80

To check the status of the pods you can run the below command

# kubectl get pods

clip_image002

Now the pods are deployed in to the AWS instance.

Net will configure the luster load balancer.

Wednesday, November 21, 2018

Configure EKS cluster

To configure the Kubernetes cluster, you can use the created Ubuntu server. steps are mentioned below,

1. SSH into your Ubuntu server

2. Go into Root

3. Update the kernel and install transport layer

# sudo apt-get update && apt-get install -y apt-transport-https

clip_image002

4. Add the required keys

# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

clip_image004

# cat <<EOF>/etc/apt/sources.list.d/kubernetes.list

>deb http://apt.kubernetes.io/ kubernetes-xenial main

>EOF

clip_image006

5. Update the package

# apt-get update

6. Install Kubectl

# sudo apt-get install -y kubectl

clip_image008

7. Download Kops

# wget https://github.com/kubernetes/kops/releases/download/1.8.0/kops-linux-amd64

clip_image010

clip_image012

1. Add required permission to the Kops folder

# chmod +x kops-linux-amd64

# mv kops-linux-amd64 /usr/local/bin/kops

clip_image002[6]

2. Put the public ssh key on home folder

# ssh-keygen

clip_image004[6]

3. Create the cluster. This will not create the cluster but will create the require configuration which helps to create the cluster. You can change the DNS with your own one. And I’m creating this cluster on Souteastasia region and that details can be found under the instance description.

# kops create cluster --zones=ap-southeast-1a cloudwar.xyz

clip_image006[4]

As you can see in the above print screen, before running the cluster create command you have to introduce the S3 bucket location where can store the cluster configuration details.

4. Set the S3 Bucket location

# export KOPS_STATE_STORE=s3://kuberneteshemalxyz.com

clip_image008[4]

As mentioned this will create only the configuration files. Then you must run “kops update cluster cloudwar.xyz --yes” command to install the cluster.

  • kops get cluster - This will list the configured cluster.
  • kops edit cluster cloudwar.xyz – Can edit this cluster. Min max of the nodes
  • kops edit ig --name=cloudwar.xyz nodes – Can edit the node instance group
  • kops edit ig --name=cloudwar.xyz master-ap-s - Can edit master instance group
  • kops update cluster cloudwar.xyz –yes - Configure the cluster

clip_image010[4]

If you go to the AWS EC3 instance console now you can see New three VMs were automatically added there.

clip_image012[4]

In Autos calling group there are two groups created.

clip_image014

You can validate the cluster by running “kops validate cluster”

The nodes details can be seen by running “kubectl get nodes --show-labels”

To ssh to the master Node you can run “ ssh -i ~/.ssh/id_rsa admin@api.cloudwar.xyz” This DNS need to be change with the DNS that you have configured.

Prerequisites for AKS cluster


DNS configuration on Route53

First need to configure the DNS configuration and if you already have a domain with you, then you can create a record set. But in my case, I have used my NS records in AWS but purchased from some other vendor. Then you can create the record sets. For Kubernetes cluster configuration it will automatically do the configuration and the permission

image


Create a S3 Bucket

You need to create a S3 bucket and this will require to store the artefacts for Kubernetes cluster


image

Create an IAM role

This role will need to grant the permission to EC2 instance to create the instance and permission to view the S3 Bucket.

Go into IAM > Roles > EC2 > Administrator (Admin Permission) > Give a role name and save that.


image

image

Once this is done, you can add the created role and grant the required permission to the Ubuntu VM

image


Now we have configured the prerequisites to intel AKS cluster.