Getting Started with Amazon EKS: Basics and guide to create your first POD
Tags: aws, devops, kubernetes, docker
Published: 2021-08-17 16:55:25

### 1.  What is Amazon EKS? 
Is a managed service to run Kubernetes on AWS without needing to install, operate and maintain the insfrastructure.

>**References**:
- https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html
- https://kubernetes.io/es/docs/home/

---

### 2. Important Concepts
#### 2.1 EKS Control Plane
* Consists of control plane nodes that run the Kubernetes Software, such as `etcd` and the kubernetes API server.
* Control Plane infrastructure is not shared across cluster or AWS accounts
* The control plane exposes a public endpoint so that clients and nodes can communicate with the cluster.

![control plane](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zx0ws6ju2iqbxyd78i77.PNG)

>**References**:
- https://docs.aws.amazon.com/eks/latest/userguide/clusters.html
- https://www.eksworkshop.com/010_introduction/architecture/architecture_control/

#### 2.2 Worker Nodes & Node Groups
* Workers nodes are EC2 intances
 - Run the applications workloads
* Node Groups are groups of EC2 intances that are provisioned as part of an EC2 autoscaling group
* Connect to the control plane via API server endpoint

**Considerations:**
- All EC2 instances must be the same type
- Be running the same AMI
- Use the same EKS worker node IAM role 

>**Reference**: https://docs.aws.amazon.com/eks/latest/userguide/eks-compute.html

#### 2.3 VPC
* Control plane components cannot view or receive communications from other cluster or another AWS accounts, except as authorized with Kubernetes RBAC policies
* VPCs and subnets must be tagged appropriately, so that Kubernetes knows that it can use them for deploying resources, such as load balancers
* Amazon EKS creates and manages network interfaces in your account
* Fargate PODS are deployed to private subnets only

>**Reference**: https://docs.aws.amazon.com/eks/latest/userguide/eks-networking.html

#### 2.4 Fargate Profiles
* The Fargate profile allows an administrator to declare which pods run on Fargate
* Each POD running on Fargate is isolated of the other resources and does not share the underlying kernel, CPU resources, memory or elastic network interface with another POD
* AWS built fargate controller that recognizes the PODS that belong to fargate and schedules the on FARGATE PROFILES

>**Reference**: https://docs.aws.amazon.com/eks/latest/userguide/fargate-profile.html

---
### 3. Creating an EKS cluster
#### PREREQUISITES
Install and configure AWS CLI

>**References**: 
- https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
- https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html


Install `eksctl`

>**Reference**: https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html

Install `kubectl`

>**Reference**: https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html

#### 3.1 Create EKS Cluster with `eksctl`

```
eksctl create cluster --name <my-cluster> \
		      --version <1.21> \
		      --region <region> \
		      -- zones <az1,az2...>\
		      --without-nodegroup
```
 
* Check the cluster in our AWS account
```
eksctl get cluster
```
![get_cluster](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydtdvd8obmvyz9oyrldr.PNG)

#### 3.2 Create and associate IAM OIDC Provider for EKS Cluster

With this feature, you can manage user access to your cluster by leveraging existing identity management life cycle through your OIDC identity provider.

```
eksctl utils associate-iam-oidc-provider --region <region-code> \
                                         --cluster <cluter-name> \
                                         --approve
```

![oidc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ns6st26tkl8o3xf9uaab.PNG)

#### 3.3 Create a EC2 key pair with `AWS Management Console`
* For this step you must use the AWS Management Console in your web browser

> **NOTE**: When we use `eksctl` to create an EKS cluster, automatically are created public and private subnets, NAT Gateways, Cluster service Role, security group and more resources required for our eks cluster are automatically created

![subnets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hltgnxpn05qcaanmx7yg.PNG)

----
### 4. Creating a NODE GROUP

#### 4.1 Create Node Group with additional Add-Ons in Public Subnets

```
eksctl create nodegroup --cluster <CLUSTER_NAME> \
		                --region <REGION> \
		                --name <NAME_NODE_GROUP> \
		                -node-type <TYPE_EC2_INSTANCE> \
		                --nodes <#_EC2_INSTANCES> \
		                --nodes-min <MIN_NODES> \
		                --nodes-max <MAX_NODES> \
		                --node-volume-size <GB>\
		                --ssh-access \
		                --ssh-public-key <PUB_KEY> \
		                --managed \
		                --asg-access \
		                --external-dns-access \
		                --full-ecr-access \
		                --appmesh-access \
                        --alb-ingress-access 
```

![nodes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ig04bhh8byd369yw7kgr.PNG)

#### 4.2 Check the nodes

![nodess](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6mggnulpr2t6vily6wp.PNG)

![ec2instances](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vt96vqemuobo4bab3ihv.PNG)

#### 4.3 Use `kubectl` to managed the EKS cluster

* Check nodes
```
kubectl get nodes
```
![kubectl_nodes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tuffhkwg7t1p6xumhfya.PNG)

* Check Services
```
kubectl get services
```
![svc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ioctg9zt099618uskix.PNG)

---
### 5. Creating the first POD
* Write a `.yaml` manifest to create a POD
* Execute the `.yaml` file to create the POD
```
kubectl apply -f <manifest_name>.yaml
```
![pod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkepf9hw33v3kvqyg8e8.PNG)

* Check the PODS in our EKS cluster with `kubectl`

```
kubectl get po
```

![pods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60894opshovl1j8aykb3.PNG)

* View the POD into a node through the aws management console

![node_pod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3v4h19cuin6cjn2bxtrs.PNG)

----
### 6. DELETE THE EKS CLUSTER

* Delete the NODE GROUP
```
eksctl delete nodegroup --cluster <clusterName> \
                        --name <nodegroupName>
```

* Delete the EKS Cluster

```
eksctl delete cluster <clusterName>
```

>**RESOURCES**: https://github.com/stacksimplify/aws-eks-kubernetes-masterclass