Let’s Deploy Joomla-MySQL Infrastructure on Amazon EKS

Ayush Garg
10 min readJul 12, 2020

In this article, I am going to show how we can deploy Joomla-MySQL Infrastructure just in a single click on cloud.

For a better understanding of this article you should know a little bit about container technology. If you want to do practical along with me you should have AWS account(AWS educate account won’t work because AWS EKS is a paid service), Install AWS CLI, eksctl, and kubectl which you will find in AWS official documentation.

So let’s begin.

What is Joomla?

Joomla is a free and open-source content management system like WordPress, Drupal. It is developed by Open Source Matters, Inc.

What is AWS EKS(Elastic Kubernetes Service)?

AWS EKS is Kubernetes As A Service provided by AWS. Kubernetes is a container orchestration tool that monitor pods (container), automate application deployment, autoscaling, etc. With AWS EKS we can create a multi-node cluster on the cloud.

In this article, I am going to do everything from the command line So I recommend you that First create an Admin power IAM by following the step given below.

  1. Go to service and under Security, Identity, & Compliance you will find IAM → click on it.
  2. Go to users → click on Add user.
  3. Give some name and password to the user and don’t forget to check on both Programmatic access and AWS Management Console access → click on next: permission.
  4. Click “Use a permissions boundary to control the maximum user permissions” → search for AdministratorAccess Check on it → click on add tag (if you want to add tag you but it isn’t compulsory) →click on review → click on create user.
  5. Please don’t forget to download Access Key ID and secret key ID file else you won’t be able to login via a command line.

Now let’s login via a CLI. Open terminal and type aws configure. Give access key and secret key from downloaded CSV file.

AWS CLI login

Now as some of you know that we can create multi-node Kubernetes cluster in the local machine too so why we go for cloud and if that is the question in your mind let me answer it.

In AWS users or clients don’t have to worry about the master. EKS creates a master for us by following all the best practices. If our master fails in any case EKS will create another one for us. EKS also follows the disaster recovery measure. With EKS we can have the unlimited computing power and we can leverage the power of AWS services like EC2, EBS, EFS, ELB, farget, subnet, etc.
If you understand all the above theory let’s move to the practical part. I hope you have downloaded Kubectl, eksctl, and AWS CLI if you are doing practical along.

AWS CLI is the AWS native command-line tool that also has EKS related commands but We are going to use eksctl develop by Weave Community which is now official command for EKS hence we can found it in official documentation too. We are using eksctl tool instead of native AWS CLI because eksctl provides us better customization, flexibility and it is easy to use.

Let’s create a Key-pair

We creating key-pair because we have to login to the ec2 Instance (Nodes) later to install an utility.

  1. To create go to service → select EC2.
  2. Scroll down → inside Network & security → select Key Pairs.
  3. Click Create Key Pairs → enter key name whatever you like → select ppk.
  4. Click Create Key Pairs → download the key.

Let’s create Cluster

To create a cluster write a YMAL file as shown below. Name the file whatever you like and save it with the extension .yml.

Cluster file

Hear the name of the cluster is “myclusternew” which will lunch in us-east-1 means N.virginia region.

Node Group is the collection of node of similar computing power.

Now run following command. “eksctl.exe create cluster -f nameOfFile.yml”. For reference look below.

IMPORTANT :- Cluster creation may take 20–30 minute.

AWS ESK is a paid service if you have any trouble with creation of a cluster or you want to leave practical in middle please delete all the the service you created or use. I write detail description of how to delete cluster and other services at end of this article.

Cluster Creation.

Eksctl tool internally use CloudFormation which lunch all the EC2-instances, EBS , VPC, security, ELB, etc for us. Also, define role.

Cloud Formation.

Now we have created a cluster we have to configure our kubectl tool. We are configuring kubectl so that our kubectl will point to our created cluster. To configure you just needed to type “aws eks update-kubeconfig --name NameOFCluster”. To test whether kubectl is configured or not we type “ kubectl get nodes”. This command will show the number nodes (EC2 Instances) running in cloud. I also recommend that you should created a separate namespace. For this use command, “kubectl create namespace NameOFSpace”. We also have to made a change in kubeconfig file so that whatever we do or lunch will be in our newly created namespace. For this we use command “kubectl config set-context --current --namespace=NameOfSpace”. For reference look image below.

cluster detail
Instance details

Now we have created cluster , we can deploy our infrastructure but there is an very big issue. What the issue is?

When we create a cluster by using yml (describe above) it creates both master and worker nodes (slave node). Nodes are nothing but an ec2 instance which can be created in any of the subnets. In above image you see there are some instances which are running in us-east-1c and some instances are in us-east-1a. Now consider if Joomla pod lunched inside us-east-1c and mysql pod lunched inside us-east-1a So how we can conned both Joomla and MySQL pod because for the connection both pods must be in same subnet. Hence to connect both of them we have to go for EFS (Amazon Elastic File System).

Let’s install amazon-efs-utils to enable efs in worker nodes

Before I show how to can create EFS we have to download an utility in all the Nodes (EC2 instances) and here the key we created at first step come into play. This utility enables our instances for efs.

  1. Go to service → select EC2 → select any of the instance which are part of cluster.
  2. In Description tab copy IPv4 Public IP.
  3. If have PuTTY open it or download it from here
PuTTY

4. past the IP address we copied in earlier step → Go to the Auth and upload a private key → click open

5. It will ask for login id which is “ec2-user”

6. At last type “sudo yum install -y amazon-efs-utils”.

Follow all the six step for every Ec2-Instances (nodes) who are the part of cluster.

Guy’s there are some others way to do the same like using CMD (terminal) but i found this way is more reliable and error free.

Let’s create Amazon Elastic File System (EFS).

Now we have install utilities we are good to go for the creation of EFS.

  1. Go to service → inside storage select EFS → Click on Create file system.
VPC

2. Now select the vpc in which your instances(Nodes) are running if not sure about the vpc go to EC2 Instance. Inside description tab, you will find VPC

3. Now select the security groups same as your your nodes (instances). If not sure again go to EC2 instance inside description tab you will find security groups.

Security Groups.

4. Click next until you find “Create file system”. Hit create a file system. For reference look image below.

EFS console

Now we have created everything we needed to deploy the code of our infrastructure on the cloud. So let’s jump to the deployment part. To deploy infrastructure we can either use prewritten code or can write by ourselves. I am here going to write Joomla-MySQL infrastructure code.

I created eleven file which you will find in my GitHub repository but here i am describing all the file briefly.

  1. create-efs-provisioner.yaml: — This file will create a new provisioner EFS. By default provisioner is EBS. In this file, you have to made two change. First File System ID and another one is DNS name as your created Elastic file system. For reference look EFS console image (above).
  2. create-rbac.yaml:- This file create a new account in kubernetes and define it’s role. The role is like a power of the newly created account.
  3. storageclass.yml:- This file will create new storage class. Storage class is the one which get storage from storage source.
  4. secret.yml:- It will create a vault where we can store our password like sensitive stuff. But don’t consider secret.yml file as an encryption file.

5. mysqlPVC.yml:- It will create a PVC or in simple word a volume (like a drive or disk) to store MySQL data permanently.

6. mysqlPod.yml:- It will created a MySQL Deployment.

7. mysqlService.yml:- It will create a service which is very useful for the outside connectivity and internal pods management.

8. JoomlaPVC.yml:- It will create a PVC to store Joomla data permanently.

9. JoomlaPod.yml:- It will created a Deployment of Joomla.

10. JoomlaService.yml:- It will create a service that is very useful for the outside connectivity. Here I am using load balancer service ( a type of service) by which I am leveraging the power of AWS ELB.

11. kustomization.yml:- It is very new concept of kubernetes where instead of running all the files one by one by using the command “kubectl create -f NameOfFile”. We can run single command that command will run all the file for us.

I recommend that download all these file in a one folder or directory if you do this you just have to run one single command and within a seconds your infrastructure will launch automatically.

command:- kubectl create -k .

For reference look below.

kustomization.yml

Now run Command “kubectl get all ” you will find an URL with Joomla pod copy it and paste it in your browser. For reference look below

Description about cluster, pvc

But you may get error in browser but don’t worry there nothing wrong with pods or code. We are getting error because all of our nodes or instance take around 5 minute to connect with load balancer. If you want to check the connectivity of all the nodes with load balancers go to Elastic Load Balancer Service (ELB) where you have look for status. Look below for the reference.

ELB console

Finally when you run URL in browser after all of your instance connect with Load Balancer you will see the website as shown below.

Final output

Let’s delete cluster.

AWS EKS is the paid service which charges you 10 cent per hour so you might want to save your currency. To delete ESK cluster either type “eksctl delete cluster -f nameOfClusterFile” or my favorite one “eksctl delete cluster --name nameOfCluster --region regionID”. It is a very crucial step so let me give an example too. To delete cluster I will type

“eksctl delete cluster --name myclusternew --region us-east-1”

This command will delete all of the EC2 instances, EBS, ELB, VPC, security group automatically. So we don’t have to worry about any of them.

But we created AWS EFS explicitly so the Above command won’t delete EFS and EFS is also a paid service.

To delete EFS go to EFS → select file system → click action tab. In the action tab you will find delete file system option click it and voila. You are Done!.

IMPORTANT:-

Guy’s it may be possible your pods will show pending status and there could be a two reason for it.

  1. You don’t have enough Nodes(Ec2- instance).Because kubetnetes launch some pods internally inside kube-system namespace to provide some support and services. Which you can view by using command “kubectl get pods -n kub-system”.
  2. There must be some issue with the creation of EFS. You might have given wrong VPC or security group. So check it again.

IMP:- AWS EFS, AWS EKS both are paid services so please don’t forget to terminate them.

If you aren’t albe to understand my code or want to see more and mature IaaC you can go to https://hub.helm.sh/. Helm is an hub where you will file lot of pre-written IaaC follwing all the best practices.

If you like this article please clap and if you think there might be a need for some improvement or I made some mistake or want to give your review please feel free share your valuable feedback.

--

--

Ayush Garg

I am Engineer. I believe in simplicity. Life and stuff are already complicated so Why make it more complicated. I try to make things simple as simple as I can.