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.
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.
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
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 :
-->K8s needs software internally to do routing , install iproute-tc:
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:
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.
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:
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-
*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.
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.
Step 8- Create a wordpress.yml file in the master node giving nodeName as worker node 1 name:
# kubectl create -f wordpress.yml
Step 9- Create mydb.yml file in the master node giving nodeName as worker node 2 name:
kubectl create -f mydb.yml
Step 10- Now expose these pods to external world for other users to access it as well.
🔅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/