Amazon Elastic Kubernetes Service

Amazon Elastic Kubernetes Service

So, hey guys, in this tutorial, I will be teaching you some practical on Amazon Elastic Kubernetes Services, popularly known as EKS.

So we will be using CLI version of AWS, so let's set it up first.

Setting CLI of AWS:

No alt text provided for this image

Download the software depending upon your base O.S, mine is Windows so it downloaded .msi file, double click and click on next, until it installs, to verify it, type this in cmd:

No alt text provided for this image

The above output would be identical, just the version number might change.

Creating IAM user:

Now to use AWS from CLI, you need to have login and password, for that let's create an IAM in AWS, first, create an account on AWS, and then follow these steps:

No alt text provided for this image

Click on Users:

No alt text provided for this image

In your case the number of users might be different.

Then go on add user:

No alt text provided for this image
No alt text provided for this image

Put any name you want.

Click on next

And select first option on the next page:

No alt text provided for this image

Click on next two times, then click Create User and then on the next page, don't forget to Download .csv file, or else you won't be able to login using CLI.

In command line type:

C:\Users\Naitik>aws configure

AWS Access Key ID [None]: xxxxxxxxxxxxxxX3

AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxxxxxxxxx

Default region name [None]: ap-south-1

Default output format [None]:

Get the access key and secret access key from the csv file you downloaded earlier.

To get more help on what is EKS, run the below command:

No alt text provided for this image

To list all the clusters:

No alt text provided for this image

You will see the above output as there are no clusters.

Although you can get launch cluster using the normal commands of AWS, but it is a huge topic, and for that, I will be using a specific command with which, a single command will launch whole cluster.

So to setup eksctl, it is an easy topic, any YouTube video or an article with help you with that.

To check whether eksctl command was installed properly, run this command:

No alt text provided for this image

To check if any clusters are active or not using eksctl command, run the below command, if there are no clusters, the below output will be identical to yours:

No alt text provided for this image

But, before running the above command, make sure you have executed the aws configure command, which shown in the start of the article.

No alt text provided for this image

The above command will create a cluster.yml file in the directory you will choose.

This is the format of cluster.yml file:

No alt text provided for this image

eksctl command is powerful, that a single command will launch whole cluster within minutes, to create a cluster, run the below command:

No alt text provided for this image

It will look like this when you hit enter:

No alt text provided for this image

Put the same file name in the command, which you have given to the config file. It might take a few minutes to launch(15-20 Minutes to be accurate).

To download kubectl command, follow the steps in the below:

No alt text provided for this image

Click on the first link, and then scroll down, until you find your base O.S, in my case it is windows.

Click on this link and it will download an .exe file.

No alt text provided for this image

Then set an path of the folder which is containing the downloaded .exe file.

I suggest you to keep all downloaded files which needs to have specified path in one folder, so that you need to edit path only once, in my case:

No alt text provided for this image

For checking whether your cluster was deployed properly, run the following command, the output should be similar, just the name of the cluster will be different, depending upon what you named it.

No alt text provided for this image

To verify your cluster in WebUI, Sign in to your AWS console and then:

No alt text provided for this image
No alt text provided for this image

Then to delete the cluster, as you are charged on hourly basis, and if you are working on new account of AWS, then t2.micro is free, but t2.small is paid, although the charge is less, but it is paid, run the following command:

No alt text provided for this image

It will take a little bit of time to delete, and then even crosscheck using WebUI as I explained earlier. After deleting the cluster is successful, you will get this type of output:

No alt text provided for this image

If the deletion is Successful, in WebUI, you will be redirected to Creating a cluster.

No alt text provided for this image

Ok, so let's see how to connect to the Kubernetes cluster, and for that we need the kubectl command and to set it up, I have added the screenshots above.

First Navigate to the folder path in the image below:

No alt text provided for this image

If you don't have the config file, chill, I will show you how to make it.

For the ones who don't have config file from before, follow the steps below:

Open command line and type:

No alt text provided for this image

The above output means that you don't have the config file, now run the below command:

No alt text provided for this image

Remember that your cluster should be running at that the time when you run the above command, and in my case, my cluster name is naitik-cluster, so my command will contain my cluster name, in yours it will be different.

To crosscheck how many nodes have been launched, type the below command:

No alt text provided for this image

To describe a specific nodes, run this command:

No alt text provided for this image

So, as you can notice, the above command is kubectl describe nodes (name of the node you want to describe, in your case it will be different, you can get the name from kubectl get nodes.

Let's see how to create your own name space using kubectl command, for that, follow the steps below:

No alt text provided for this image

In the above command, in the place of nspace, put a name of your choice.

To check whether the namespace was created, run the following command:

No alt text provided for this image

So, let's see the output of kubectl get pods:

No alt text provided for this image

But why, we just created a namespace, so the nspace I launched is not the default namespace, let's see how we can change that:

No alt text provided for this image

To check whether the namespace was changed:

No alt text provided for this image

As you can see above, the namespace is now nspace, the name of my namespace, in your case it will be different.

To check the cluster connectivity:

No alt text provided for this image

The command is kubectl cluster-info

To launch any docker image on Kubernetes:

No alt text provided for this image

For this I have used Vimal sir's apache image from docker.

To verify the same:

No alt text provided for this image

For some extra details about the pod:

No alt text provided for this image

The command is kubectl get pods -o wide

To scale your deployment, run the following command:

No alt text provided for this image

In the above example, the number of pods will be scaled to 3.

To check number of pods:

No alt text provided for this image

How to expose your deployment:

No alt text provided for this image

The above command will use LoadBalancer service.

The get a list of all services you are using, the command is:

No alt text provided for this image

To delete all the services:

No alt text provided for this image

To get pvc storage:

No alt text provided for this image

This is how the code in notepad should be:

No alt text provided for this image


The above code means:

10GB data, the PVC name would be nspvc1, and the access type would be ReadWriteOnce.

To create the pvc:

No alt text provided for this image

To check whether your pvc was successfully launched:

No alt text provided for this image

Let's use the feature of auto scaling of AWS, first head to this website below and copy the code below node groups:

No alt text provided for this image

And paste the code below in your clusters.yml file, you may make some changes. Your yml should look like this, it may be different depending upon the choices you have made, but the basic outline should be the same:

No alt text provided for this image

Let's launch this cluster, I have given the code above to launch the cluster, but here it is again:

No alt text provided for this image

To see the nodegroup:

No alt text provided for this image

To check the same in WebUI:

Got to EC2

No alt text provided for this image
No alt text provided for this image

In the left column, you will find spot instances, click it and verify the same.

Okay, so re launch your cluster using the updated yml file, which contains your ssh key, which willbe different for everyone.

No alt text provided for this image

Navigate to the folder (in the command prompt) where you have downloaded the ssh key, and then:

No alt text provided for this image

Voila, you have logged in to the slave and now run:

sudo yum install amazon-efs-utils -y

So, now go to AWS WebUI, and under the services section, search efs:

No alt text provided for this image

And then, click on create file system:

No alt text provided for this image

And then:

No alt text provided for this image

Click next:

No alt text provided for this image

Click next:

No alt text provided for this image

Click Create:

No alt text provided for this image

You will be greeted with Success:

No alt text provided for this image
No alt text provided for this image

efs.yml file:

No alt text provided for this image

Your values won't match, so it won't be same, if you copy paste from this, you will get some error.

In the first place, select the equivalent vpc as that of the bunch made by the eksctl. You can affirm the vpc from the VPC Dashboard. At that point we have to connect the security bunch ( which resembles a firewall) to the Instances which would be running as the NFS server. So it is mandatory that the Security bunch u append to the Efs examples ought to be equivalent to that of the cases in which all hubs can interface with one another and all ports are permitted inside that security gathering/s as we need the NFS administration port number to be permitted in all the occasion where the EFS should have been mounted.

No alt text provided for this image

Creating a RBAC(Role based access control) file:

No alt text provided for this image

Now time for mysql.yml:

No alt text provided for this image
apiVersion: v1
kind: Service
metadata:
 name: joomla-mysql
 labels:
   app: joomla
spec:
 ports:
   - port: 3306
 selector:
   app: joomla
   tier: mysql
 clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
 name: joomla-mysql
 labels:
   app: joomla
spec:
 selector:
   matchLabels:
     app: joomla
     tier: mysql
 strategy:
   type: Recreate
 template:
   metadata:
     labels:
       app: joomla
       tier: mysql
   spec:
     containers:
     - image: mysql:5.7
       name: mysql
       env:
       - name: MYSQL_ROOT_PASSWORD
         valueFrom:
           secretKeyRef:
             name: mysql-ns
             key: naitik1234
       ports:
       - containerPort: 3306
         name: mysql
       volumeMounts:
       - name: mysql-pvc
         mountPath: /var/lib/mysql
     volumes:
     - name: mysql-pvc
       persistentVolumeClaim:
         claimName: mysql-efs

Now time for joomla.yml:

No alt text provided for this image
apiVersion: v1
kind: Service
metadata:
 name: joomla
 labels:
   app: joomla
spec:
 ports:
   - port: 80
 selector:
   app: joomla
   tier: frontend
 type: LoadBalancer
---
apiVersion: apps/v1 
kind: Deployment
metadata:
 name: joomla
 labels:
   app: joomla
spec:
 selector:
   matchLabels:
     app: joomla
     tier: frontend
 strategy:
   type: Recreate
 template:
   metadata:
     labels:
       app: joomla
       tier: frontend
   spec:
     containers:
     - image: joomla
       name: joomla
       env:
       - name: JOOMLA_DB_HOST
         value: joomla-mysql
       - name: JOOMLA_DB_PASSWORD
         valueFrom:
           secretKeyRef:
             name: mysql-ns
             key: naitik1234
       ports:
       - containerPort: 80
         name: joomla
       volumeMounts:
       - name: joomla-pvc
         mountPath: /var/www/html
     volumes:
     - name: joomla-pvc
       persistentVolumeClaim:
         claimName: joomla-efs

Now time to run all yml file:

No alt text provided for this image
No alt text provided for this image

Now you all know how to run a yml file.

Open Joomla installation page from external IP

No alt text provided for this image

Now install it and voila, you just learnt Amazon EKS.

Now let's clear out the running tasks, first let's delete EFS, head to EFS and click on Actions:

No alt text provided for this image

Then click Delete file system, now it will ask to enter the file system number which will be provided in the above text, just copy and paste:

No alt text provided for this image

Remember to delete EFS, or else you will be charged $0.080 every hour.

Now let's get rid of the cluster, if possible, please delete the cluster from CLI using the below command as in some cases, deleting the cluster from WebUI didn't completely delete the cluster, and it kept on charging.

No alt text provided for this image
No alt text provided for this image

Thank you guys for bearing with me till end, I know this article is too long, sorry for that, but I tried to explain each and every command.

要查看或添加评论,请登录

Naitik Shah的更多文章

  • JavaScript - Journey from Zero to Hero with Vimal Daga Sir

    JavaScript - Journey from Zero to Hero with Vimal Daga Sir

    I have seen a lot of "Free" courses on YouTube, which assure you to take your basic level in JavaScript to next level…

  • Hybrid Computing Task 1

    Hybrid Computing Task 1

    Why Cloud? Many companies have a hard time maintaining their data centers. It's also inconvenient for new startups to…

    2 条评论
  • Chest X-Ray Medical Diagnosis with Deep Learning

    Chest X-Ray Medical Diagnosis with Deep Learning

    Project Name: Chest X-Ray Medical Diagnosis with Deep Learning Team Members: Naitik Shah Ashutosh Kumar Sah This…

    2 条评论
  • Top 5 Billion Dollar Companies Using AWS Cloud

    Top 5 Billion Dollar Companies Using AWS Cloud

    Hello Readers, AWS has captured a whopping 51% of the total cloud computing service providers, and their competitors…

    2 条评论
  • Multi-Cloud Project

    Multi-Cloud Project

    A quick summary of the project: The purpose is to deploy a WordPress framework using Terraform on Kubernetes. For this,…

    2 条评论
  • Data Problem of Big Tech Companies

    Data Problem of Big Tech Companies

    Every hour, 30,000 hours of videos are uploaded to YouTube, crazy isn't it? and that data is of March 2019, so, I am…

    2 条评论
  • Hybrid Cloud Computing Task 4

    Hybrid Cloud Computing Task 4

    Hey fellas, presenting you my Hybrid Cloud Computing Task 4, which I am doing under the mentorship of Vimal Daga Sir…

  • Hybrid Cloud Computing Task 3

    Hybrid Cloud Computing Task 3

    Hey fellas, I bring you the Hybrid Cloud Computing task 3. What is this task all about? The motive is for our company…

  • Automating AWS Service(EC2, EFS, S3, Cloud Front) using Terraform

    Automating AWS Service(EC2, EFS, S3, Cloud Front) using Terraform

    So let me take you through the steps: First of all, create an IAM user by going to AWS GUI, and don't forget to…

  • Deploying Prometheus and Grafana on top of Kubernetes

    Deploying Prometheus and Grafana on top of Kubernetes

    Hello readers, this is my DevOps Task 5, and the problem statement is: Integrate Prometheus and Grafana and perform in…

社区洞察

其他会员也浏览了