??Multi-Node Cluster & Stateful Apps Like MySql and Wordpress??
What is Kubernetes exactly?
Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.
There are hardly many people who have not heard of WordPress — arguably the most popular CMS for websites and blogs. It is available as a docker image (over 10 million pulls on DockerHub), and by running it on Kubernetes you can build a reliable and scalable website platform.
What are they??PersistentVolume (PV) resources are used to manage durable storage in a cluster. PersistentVolumes can also be used with other storage types like NFS. A PersistentVolumeClaim (PVC) is a request for storage by a user.
What exactly is WordPress and MySql?
MySQL is a database management system that is used by WordPress to store and retrieve all your blog information. If your database is a filing cabinet that WordPress uses to organize and store all the important data from your website (posts, pages, images, etc), then MySQL is the company that created this special type of filing cabinet.
WordPress requires MySQL to store and retrieve all of its data including post content, user profiles, and custom post types. Most?web hosting providers?already have MySQL installed on their web servers as it is widely used in many open source web applications such as WordPress.
Let's start with by creating Multi-Node Cluster on AWS:-
Launch 3 instances: 1- master nodes and 2 - slave nodes.
REMEMBER:- To configure security groups for allowing all traffic.
After successful launch of the instances. Now Let's Configure 1st node for being a master node and other two for being slave nodes.
Let's start with installing Docker on Master Node by using command:
yum install docker -y
Now, enable docker services by using command:-
systemctl enable docker --now
Now let's check if we have kubernetes.repo file in /etc/yum.repos.d/ . If its not present, create a file named kubernetes.repo and write the following in the repo file.
Now, let's install kubelet, kubectl and kubeadm using command:-
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Now, enable kubelet by using command:-
systemctl enable --now kubelet
Now, pull the images used by kubeadm by using command:-
kubeadm config images pull
Now, run the command kubeadm init --pod-network-cidr=10.240.0.0/16 and you'll come across some errors.... Resolve those errors using following commands:-
After running the above commands, we are ready to run the command:-
kubeadm init --pod-network-cidr=10.240.0.0/16 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem
Now to start using your cluster, you need to run the following as a regular user:
Now, print the token that can be used to join the worker nodes using following command:-
kubeadm token create?--print-join-command
Now, let's configure both the worker nodes.
Install the docker and write the kubernetes.repo file and install the kubeadm, kubectl and kubelet. Then, enable the kubelet.
Change the Cgroup Driver from cgroupfs to systemd as we did it for the master node.
Install iproute-tc using command yum install iproute-tc.
Then run the following:-
Now, use the token to join the master node and form the cluster.
领英推荐
Now when we run the command kubectl get nodes and we'll see that the slave nodes are in the NOT READY state.
Now, let's setup the flannel by using the following command:-
kubectl apply?-f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Now run the command:- kubectl get nodes and we'll see that all the nodes are in Ready States.
Now, let's launch WordPress and MySQL database connected to it. In this, we'll go through many steps:-
Create a Secret for MySQL Password.
A?Secret?is an object that stores a piece of sensitive data like a password or key. Each item in a secret must be base64 encoded. Let’s create a secret for admin use. Encode the password (in our case —?admin):
echo -n 'admin' | base64
You will get the encoded password:?YWRtaW4=
Create a?secret.yml?file for MySQL and Wordpress that will be mapped as an Environment Variable as follows:
Then run:
kubectl create -f secret.yml
Deploy Persistent Volume for WordPress & MySQL:-
Create PV files :-
Now run the following command to create a PV:
kubectl create -f pv-wordpress-mysql.yml
Deploy PersistentVolumeClaim(PVC):-
PVC is a request for storage that can at some point become available, bound to some actual PV.
Create a PVC for wordpress by using creating yaml file as follows:
Now, run the command:-
kubectl create -f pvc-wordpress.yml
Do the same for MySQL:-
Create the yaml file:-
Now, run the command:-
kubectl create -f pvc-mysql.yml
Now we are ready to deploy the apps:-
Create both deployment and service yaml files for MySQL and WordPress and launch them.
Launch WordPress
To access WordPress list the services and navigate to the?External IP:Port?, in our case that would be EXTERNAL_IP:port.
You'll see the following:-
Fill up the details as follows:-
Conclusion:
We have deployed a wordpress with MySQL, Persistent volumes, and NFS on Kubernetes. The main benefit of this stack is flexibility since it allows you to implement practically any type of workflow. This workflow can be extended or complexified depending on your development needs.
MY_GITHUB_URL:- https://github.com/Vrush-cmd/Multinode__WP__SQL.git
SSE II at Bosch || Ex GLOBAL EDGIE
3 年Tqs buddy this one helped me for creating kubernetes cluster in Google ??