AWS EKS(fully managed K8s master) cluster with AWS EFS dynamic provisioning and AWS Fargate for serverless deploying Pods.

Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service. EKS runs upstream Kubernetes and is certified Kubernetes conformant so you can leverage all benefits of open source tooling from the community. You can also easily migrate any standard Kubernetes application to EKS without needing to refactor your code. Current EKS supports K8s v 1.14, 1.15, 1.16(default).

Prerequisite:- A station is required where aws cli v2, eksctl, and kubectl commands preconfigured. An IAM user with enough policies so that it can create an AWS EKS cluster and AWS EFS file system in the same VPC.
Also, choose the region for deploying eks cluster wisely and be aware of aws billing for these services.

eksctl is a simple CLI tool for creating clusters on EKS - Amazon's new managed Kubernetes service for EC2. It is written in Go, uses CloudFormation, was created by Weaveworks and it welcomes contributions from the community. Create a basic cluster in minutes with just one command: # eksctl create cluster

So, here we start creating our EKS cluster using eksctl command.

Customize your cluster by using a config file. Just run

[root@server ~]# eksctl get cluster
No clusters found
[root@server ~]# eksctl create cluster -f fargatecluster.yaml

to apply a fargatecluster.yaml file:

kind: ClusterConfig
name: fargate-cluster
region: us-east-1
- name: ng-1
minSize: 2
maxSize: 3
desiredCapacity: 2
maxPrice: 0.5
instanceTypes: [ "t2.medium" ]
publicKeyName: yourkey
- name: fp-default
# All workloads in the "default" Kubernetes namespace will be
# scheduled onto Fargate:
- namespace: default
# All workloads in the "kube-system" Kubernetes namespace will be
# scheduled onto Fargate:
- namespace: kube-system
- name: fp-dev
# All workloads in the "dev" Kubernetes namespace matching the following
# label selectors will be scheduled onto Fargate:
- namespace: dev
env: dev
checks: passed

It takes time according to our capacity planning since, behind eksctl, it uses cloud formation stacks.

[root@server ~]# aws eks list-clusters
"clusters": [
root@server ~]# eksctl get cluster
fargate-cluster us-east-1
[root@server ~]# aws eks update-kubeconfig --name fargate-cluster
Added new context arn:aws:eks:us-east-1:<ID>:cluster/fargate-cluster to ~/.kube/config

We can check our worker nodes after completely configured as K8s worker node using a public key for ssh we used in the fargatecluster.yml file.

[root@server ~]# ssh -i yourkey -l ec2-user  <workernode-ip>

Now, we can create our EFS file system in the same region and on the same VPC which our EKS cluster is using currently.

After the successful creation of our EFS File System, now we can configure our worker nodes/minions so that they are able to mount the EFS filesystem automatically on EFS dynamic provisioning for the Persistent Volume Claims.

[root@server ~]# ssh -i mykey1234.pem  ec2-user@<worker-nodes> "sudo yum install -y amazon-efs-utils"

Create an EFS dynamic provisioner in the current namespace(default) and our PVs, and PVCs.

[root@server ~]# kubectl create -f create-rbac.yaml created
[root@server ~]# kubectl create -f create-efs-provisioner.yaml
deployment.apps/efs-provisioner created
[root@server ~]# kubectl create -f create-storageclass.yaml created
[root@server ~]# kubectl create -f create-wordpress-pvc.yaml
persistentvolumeclaim/efs-wordpress created
[root@server ~]# kubectl create -f create-mysql-pvc.yaml
persistentvolumeclaim/efs-mysql created
[root@server ~]# kubectl get pvc
efs-mysql Bound pvc-8002c07d-1cda-47f4-9cbd-a7bfed00e77e 1Gi RWX aws-efs 10m
efs-wordpress Bound pvc-aa261ca3-c8d6-4022-8a1c-57e7eede8df4 1Gi RWX aws-efs 10m
[root@server ~]# kubectl get pv
pvc-8002c07d-1cda-47f4-9cbd-a7bfed00e77e 1Gi RWX Delete Bound default/efs-mysql aws-efs 9m51s
pvc-aa261ca3-c8d6-4022-8a1c-57e7eede8df4 1Gi RWX Delete Bound default/efs-wordpress aws-efs 9m51s

Now, we can create our resources like services, deployments.

[root@server ~]# kubectl create -f secrets.yaml
secret/mysql-pass created
[root@server ~]# kubectl create -f deploy-mysql.yaml
service/wordpress-mysql created
deployment.apps/wordpress-mysql created
[root@server ~]# kubectl create -f deploy-wordpress.yaml
service/wordpress created
deployment.apps/wordpress created
[root@server ~]# kubectl get svc
kubernetes ClusterIP <none> 443/TCP 90m
wordpress LoadBalancer 80:31847/TCP 52s
wordpress-mysql ClusterIP None <none> 3306/TCP 62s
[root@server ~]# kubectl get pods
efs-provisioner-864ddccb7-2qczt 1/1 Running 0 74s
wordpress-d46cfd788-gcjmk 1/1 Running 0 21s
wordpress-mysql-689fcd5cd4-67mzs 1/1 Running 0 31s

Finally, we can access our Stateful applications e.g. WordPress using the domain name provided by AWS ELB( classical load balancer) services.

So, finally, we have created a stateful application on the top of EKS cluster.

Also, Stateful applications are not recommended for pods running on Fargate. Instead, we recommend that you use AWS solutions such as Amazon S3 or DynamoDB for pod data storage.
So, our pods of this stateful app are currently working on user-managed worker nodes and not on the serverless architecture of the AWS Fargate.

For further discussions and improvements, follow our Github repo.




I'm a CS graduate and my primary area of work is under Linux, CloudComputing, DevOps culture, and various open-source tools and technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Your Unconventional (Dev) Journey

Two Awesome Days at JAMstack Conf 2018!

App Development: Speed vs. Quality — Can you have both?

How to organize an excellent tickets categorization in Zendesk

Easily Setup a Production Ready Kubernetes Cluster with Kubespray

Easily Setup a Production Ready Kubernetes Cluster with Kubespray

How switching from Java to Kotlin will make your life easier?

2021, Year in Review

Scala: Useful User Information + Why you should consider the Language

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


I'm a CS graduate and my primary area of work is under Linux, CloudComputing, DevOps culture, and various open-source tools and technologies

More from Medium

[AWS API Gateway, EKS] Access an Amazon EKS Cluster with an API Gateway!!

AWS Backup Plan for EBS Volumes With Terraform

Running Containers on AWS using Amazon ECS and AWS Fargate

Create & Add Custom Image to AWS ECR Using Docker & Nginx!