Wordpress & Mysql - Multinode kubernetes Cluster setup on AWS

Wordpress & Mysql - Multinode kubernetes Cluster setup on AWS


Here, in this article you will see step by step  setup of Multi-Node Kubernetes cluster, which includes:

🔅Launch ec2-instances on AWS Cloud for 1 master and 2 worker nodes.

🔅 Configuration of nodes.

🔅 Launch - wordpress and mysql database connected to it in the respective slave nodes. 

🔅Exposing the wordpress pod so that client is able hit the wordpress ip with its respective port.

*Using 'Black' background for master node and 'White' for worker nodes*

Step 1- Create 3 ec2 instances on AWS Cloud, 1 for master 2 for slave nodes.

No alt text provided for this image

Step 2- To start the configuration, login into the master node using its Public IP Address.

Minimum requirement for a master or slave node here to work properly is to have a container engine installed i.e. Docker, that I am using here. So firstly we will install docker and enable it:

# yum install docker -y

# systemctl enable docker --now

Step 3- Now to set-up k8s we will install kubeadm:

--> First Reconfigure yum in " /etc/yum.repos.d/kubernetes.repo " this file and add the below mentioned data.

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

Then start the kubelet services:

# systemctl enable kubelet --now

Step 4- Pull all the images that are required by the master, through this command:

#kubeadm config images pull

No alt text provided for this image

Step 5- Specify the range of ip address that pods will get. But before we do that we need to resolve few warnings and errors that we can get if done directly.

-->Hence, firstly change the cgroup driver to systemd with the following commands then restart the docker after these changes :

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

-->K8s needs software internally to do routing , install iproute-tc:

No alt text provided for this image

Now run the kubeadm init command to specify ip range. As we are using t2.micro instance type, we only have 1 CPU and 1 GiB RAM available to us which is less than the preffered minimun requirements of k8s.

Hence we will also remove that restriction for our purposes:

No alt text provided for this image

To use this cluster as a regular user run these commands, where admin.conf file contains information like ip address, port no, username, etc of master which is copied to $HOME location.

No alt text provided for this image

Step 6- Configure the worker nodes, login using its public ip address.

Initial configuration is almost similar as that of master node, which is:

-->Installing docker ( From Step 2)

-->Installing kubeadm

-->Till installing iproute-tc (In step 5)

Next, join the worker nodes to master node. But before that we need to resolve an error that can come up if we do it directly. This error is related to iptables content not set to 1. Hence, run this command for it:

No alt text provided for this image

Now to join worker nodes with master we need to run kubeadm join command in which a token is given by master for this connection. We can retrive this token in 2 ways:

  • With command, to see tokens: # kubeadm token list

Then creating a token by: # kubeadm token create --print-join-command

  • Or while kubeadm init command in the end we can see this whole command mentioned there with the tokens as well.

Now, run this command in the worker node-

No alt text provided for this image

*Do the same procedure to create more worker nodes.( I have created 2).

Step 7- Using Flannel to make the status of all the nodes from NOT READY to READY state.

No alt text provided for this image

We need to run Container Network Interface (CNI) i.e. Flannel, command in the master node for proper communication between the pods for networking in this cluster.

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

Step 8- Create a wordpress.yml file in the master node giving nodeName as worker node 1 name:

# kubectl create -f wordpress.yml

No alt text provided for this image

Step 9- Create mydb.yml file in the master node giving nodeName as worker node 2 name:

kubectl create -f mydb.yml

No alt text provided for this image

Step 10- Now expose these pods to external world for other users to access it as well.

No alt text provided for this image

🔅OPEN THE SITE NOW!!

*Here are the screenshots of same if running it with public ip address of the node having wordpress:

Format- http://ip:port_no

Example- http://13.234.186.34:30814/multinode-cluster/

No alt text provided for this image


No alt text provided for this image


To view or add a comment, sign in

More articles by Harshaa Dhawan

  • Integration of Jenkins-GitHub-Docker

    USE CASE DESCRIPTION: 🔅 JOB #1 If Developer push to dev branch then Jenkins will fetch from dev and deploy on the…

    2 Comments
  • How to create Helm Chart for Jenkins

    What is Helm?? Helm is the package manager for Kubernetes, which is used for automating creation, packaging…

    5 Comments

Insights from the community

Others also viewed

Explore topics