??Multi-Node Cluster & Stateful Apps Like MySql and Wordpress??

??Multi-Node Cluster & Stateful Apps Like MySql and Wordpress??


No alt text provided for this image


No alt text provided for this image


No alt text provided for this image

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.

No alt text provided for this image

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

No alt text provided for this image

Now, enable docker services by using command:-

systemctl enable docker --now

No alt text provided for this image

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.

No alt text provided for this image

Now, let's install kubelet, kubectl and kubeadm using command:-

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

No alt text provided for this image

Now, enable kubelet by using command:-

systemctl enable --now kubelet

Now, pull the images used by kubeadm by using command:-

kubeadm config images pull

No alt text provided for this image

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:-

No alt text provided for this image

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

No alt text provided for this image

Now to start using your cluster, you need to run the following as a regular user:

No alt text provided for this image

Now, print the token that can be used to join the worker nodes using following command:-

kubeadm token create?--print-join-command

No alt text provided for this image

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:-

No alt text provided for this image

Now, use the token to join the master node and form the cluster.

No alt text provided for this image

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

No alt text provided for this image

Now run the command:- kubectl get nodes and we'll see that all the nodes are in Ready States.

No alt text provided for this image

Now, let's launch WordPress and MySQL database connected to it. In this, we'll go through many steps:-

  1. Create PersistentVolumeClaims and PersistentVolumes
  2. Create a Secret for MySQL
  3. Deploy MySQL
  4. Deploy WordPress

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:

No alt text provided for this image

Then run:

kubectl create -f secret.yml

No alt text provided for this image

Deploy Persistent Volume for WordPress & MySQL:-

Create PV files :-

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

Now run the following command to create a PV:

kubectl create -f pv-wordpress-mysql.yml

No alt text provided for this image

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:

No alt text provided for this image

Now, run the command:-

kubectl create -f pvc-wordpress.yml

Do the same for MySQL:-

Create the yaml file:-

No alt text provided for this image

Now, run the command:-

kubectl create -f pvc-mysql.yml

No alt text provided for this image

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:-

No alt text provided for this image

Fill up the details as follows:-

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

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


Sava Srikanth

SSE II at Bosch || Ex GLOBAL EDGIE

3 年

Tqs buddy this one helped me for creating kubernetes cluster in Google ??

回复

要查看或添加评论,请登录

Vrushali Mahajan的更多文章

  • ??AMAZON SQS AND NASA??

    ??AMAZON SQS AND NASA??

    Amazon provides SDKs in several programming languages including Java, Ruby, Python, .NET, PHP, Go and JavaScript.

  • ??AWS CLI COMMANDS??

    ??AWS CLI COMMANDS??

    Task Description ?? Create a key pair. ?? Create a security group.

    1 条评论
  • ??K-mean clustering and its real usecase in the security domain??

    ??K-mean clustering and its real usecase in the security domain??

    Let's first understand, what exactly is K-mean clustering in machine learning? K-means clustering is one of the…

  • ??HELM CHARTS??

    ??HELM CHARTS??

    Before we start let us know what are Helm Charts and why do Kubernetes use them? Helm uses a packaging format called…

  • ??USE CASES OF JAVASCRIPT??

    ??USE CASES OF JAVASCRIPT??

    Let's start with What exactly is Javascript? JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled…

  • IBM AND ITS USE CASES SOLVED BY KUBERNETES

    IBM AND ITS USE CASES SOLVED BY KUBERNETES

    Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of…

  • IMAGE PROCESSING WITH OPENCV USING PYTHON

    IMAGE PROCESSING WITH OPENCV USING PYTHON

    What is Image Processing? Image processing aims to transform an image into digital form and performs some process on…

  • ??CYBER CRIMES AND CONFUSION MATRIX??

    ??CYBER CRIMES AND CONFUSION MATRIX??

    Let's start with knowing, what exactly is cyber crime? Cybercrime is criminal activity that either targets or uses a…

  • RUNNING GUI APPS IN A DOCKER CONTAINER

    RUNNING GUI APPS IN A DOCKER CONTAINER

    What is GUI? Graphical user interface (GUI), a computer program that enables a person to communicate with a computer…

  • Running Machine Learning model in Docker Container

    Running Machine Learning model in Docker Container

    Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers…

社区洞察

其他会员也浏览了