fbpx

What is the Kubernetes Operator For Database?

A Kubernetes operator is a software extension to Kubernetes that helps manage complex applications or infrastructure. Operators use custom resources and controllers to automate tasks such as deploying, scaling, and backing up applications.

One of the main benefits of using Kubernetes operators is that they allow you to use the same API and tooling as Kubernetes to manage your applications, rather than having to use custom scripts or processes. This can make it easier to deploy and manage applications in a Kubernetes cluster.

Operators can be developed for a wide range of applications and infrastructure, including databases, messaging systems, and machine learning frameworks. They can be used to automate tasks such as creating and managing database clusters, deploying message brokers, and training and deploying machine learning models.

I hope this helps! Let me know if you have any questions.

There are several Kubernetes operators available for managing databases, including operators for MySQL, PostgreSQL, and MongoDB.

Here is an example of how you can use the MySQL Operator to deploy a MySQL cluster on Kubernetes:

  1. Install the MySQL Operator on your Kubernetes cluster. You can do this using the Kubernetes command-line tool kubectl.

  2. Create a configuration file for the MySQL cluster. This file should specify the number of MySQL instances you want to deploy, the size of the instances, and any other desired configuration options.

  3. Use kubectl to apply the configuration file and create the MySQL cluster. The MySQL Operator will handle the process of deploying the MySQL instances and setting up the cluster.

  4. Use kubectl to create a Kubernetes service for the MySQL cluster. This will allow other applications in the cluster to access the MySQL instances.

  5. Use the MySQL command-line client or another MySQL client to connect to the MySQL cluster and create databases and tables as needed.

I hope this gives you an idea of how you can use a Kubernetes operator to manage a database in a Kubernetes cluster. There are many other operators available for different types of databases, so you may want to research the specific operator that is best suited for your needs.

I hope this helps! Let me know if you have

How to ssh a Remote Linux Server?

To connect to a remote Linux server using Secure Shell (SSH), you will need to do the following:

  1. Install an SSH client on your local machine. If you are using a Unix-like operating system (e.g., Linux, macOS), you can use the built-in ssh command. If you are using Windows, you can use a program like PuTTY or MobaXterm.

  2. Determine the hostname or IP address of the remote server. This is the address that you will use to connect to the server. You can usually find the hostname or IP address in the server’s documentation or by contacting the server’s administrator.

  3. Open a terminal window on your local machine and enter the following command:

				
					ssh username@hostname

				
			

Replace username with your username on the remote server and hostname with the hostname or IP address of the server. For example:

				
					ssh john@server.example.com

				
			
  1. If this is the first time you have connected to the server, you may see a message asking you to confirm the authenticity of the server’s host key. Type yes and press Enter to continue.

  2. Enter your password when prompted. If you have entered the correct username and password, you should be logged into the remote server.

I hope this helps! Let me know if you have any questions.

Create AWS EC2 From AWS CLI with Public IP

This article will explain creating an ec2 instance with the AWS CLI option from the command line interface. AWS CLI is an easy and fast option for creating single or multiple ec2 instances. Using AWS CLI, you can automate total AWS infrastructure build and also, and you can query the existing infrastructure.

Create EC2

				
					aws ec2 run-instances --image-id  ami-090fa75af13c156b4 --count 1 --instance-type t2.micro --key-name awscli --security-group-ids sg-8f6dc695 --subnet-id subnet-88e3ea86
				
			

Create EC2 with Public IP

				
					aws ec2 run-instances --image-id  ami-090fa75af13c156b4 --count 5 --instance-type t2.micro --key-name awscli --security-group-ids sg-8f6dc695 --subnet-id subnet-88e3ea86 --associate-public-ip-address
				
			

List Runing EC2 instances

				
					aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicDNS:PublicDnsName,PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --output table
				
			

How to Take PostgreSQL Schema Backup

In some cases, we have to take PostgreSQL schema level backup. it’s like a logical backup where it just backup the schema objects like tables, indexes, and procedures. These backups are used in the condition where you need to restore just one schema backup, not the whole database. For daily backup, you can create a shell or bash script and schedule it using crontab or windows scheduler.

Script For Schema Backup

				
					#!/bin/bash
mv /tmp/db_list.log /tmp/db_list.log_old
psql -t -c "SELECT datname FROM pg_database WHERE datistemplate = false;" > /tmp/db_list.log ; sed -i '/^$/d' /tmp/db_list.log
file=/tmp/db_list.log
#schema_name
#DB
date=$(date '+%Y-%m-%d')
bkp_path=/var/lib/pgsql

for DB in `cat $file`
do
echo "#################Starting the backup as on ${date} for ${DB}"
pg_dump -U postgres -v -n '*' -N 'pg_toast' -N 'information_schema' -N 'pg_catalog' $DB -Ft -f ${bkp_path}/${DB}_schema_bkp_${date}.tar > `${bkp_path}/${DB}_schema_bkp_${date}.log)`
echo "#################Backup Complited as on ${date} for ${DB}"
done

echo "listing files older than 15 Days"
find ${bkp_path} -name "*schem*.tar" -type f -mtime +1 > ${bkp_path}/old_file_list.log
find ${bkp_path} -name "*.log" -type f -mtime +1 > ${bkp_path}/old_file_list.log

echo "deleting backup/log file older than 15 Days"
find ${bkp_path} -name "*.tar" -type f -mtime +15 > ${bkp_path}/old_file_list.log -delete

				
			

In this script, we have excluded system schemas like ‘information_schema’ and many more. Please remove ‘-N and schema Name if you need a backup system schema.’ It will start including the schema backup in the tar file.

How to execute the Script ?

				
					chmod 777 backup_schema.sh
./backup_schema.sh

				
			

Read More...

How to Fix Pg_ctl command not found

Sometimes after a fresh PostgreSQL install if we want to start or stop from PostgreSQL rather than controlling the PostgreSQL instance start and stop from the root. And when we run the pg_ctl from the command prompt as a PostgreSQL Linux user we see the error bash: pg_ctl: command not found… 

In this article, lets learn how to fix it

As PostgreSQL check your pg base directory 

 

And now add this PostgreSQL to the Linux path so that it’s always available. I would recommand to create a postgresql env. file so that it more easy to handle rather than messing with other systems runing on linux operating system.

				
					--Step 1 
-bash-4.2$ echo $PGDATA
/var/lib/pgsql/10/data

--Step 2
-bash-4.2$ echo "PATH=/usr/pgsql-10/bin:$PATH">>~/.postgre_10.profile

--Step 3
chmod 777 .postgre_10.profile

--Step 4 
. .postgre_10.profile

--Step 5
Check pg_ctl now

-bash-4.2$ pg_ctl --version
pg_ctl (PostgreSQL) 10.17
-bash-4.2$



				
			

HA Proxy For MySQL Master – Slave

There are scenarios where we have to provide the high ability to MySQL database instances and we use the Master and Slave replication method of MySQL database.

In the same case to segregate the Read and Write database traffic. We widly use HA- Proxy. It is a feature rich open source Load blancing tool with many unique features like reverse proxy but in out case we are going to use it only for Hight aviliblity purpose.

				
					root@haproxy01:~# haproxy -v
HA-Proxy version 2.0.13-2ubuntu0.3 2021/08/27 - https://haproxy.org/

 
				
			

How to Install it?

You simply use yum or apt commands to install it

				
					sudo apt install -y haproxy
				
			

 

Check  the version 

 

 

 

 

Install Mysql Client for HA Proxy Node to communicate with mysql master and slave databases.

 

				
					apt-get install -y mysql-client
cd /etc/haproxy/
cp haproxy.cfg haproxy.cfg_org
vim haproxy.cfg

				
			
				
					root@haproxy01:~# cat /etc/haproxy/haproxy.cfg
global
	log 127.0.0.1 local0 notice
        log /dev/log    local0
  	user haproxy
	group haproxy

	# Default SSL material locations

defaults
	log global
	mode tcp
        option tcplog
	retries 2
	timeout client 30m
	timeout connect 4s
    	timeout server 30m
	timeout check 5s

listen stats
        mode http
        bind *:9201
        stats enable
        stats uri /stats
        stats realm Strictly\ Private
        stats auth admin:admin

listen mysql-cluster
       bind *:3306
       mode tcp
       option mysql-check user haproxy_user
       balance roundrobin
       server master 192.168.56.205:3306 check
       server slave1 192.168.56.206:3306 check

listen mysql-cluster1
    bind 192.168.1.208:3306
    mode tcp
    option mysql-check user haproxy_user
    balance roundrobin
    server mysql-1 192.168.1.205:3306 check
    server mysql-2 192.168.1.206:3306 check

				
			

Create HA proxy user on mysql01/205 on primary node

				
					GRANT ALL PRIVILEGES ON *.* TO 'haproxy_root'@'%' IDENTIFIED BY 'Oracle@123' WITH GRANT OPTION;

flush privileges;
				
			

Test the configuration and it should start without error & Target should come up on GUI

				
					haproxy -f /etc/haproxy/haproxy.cfg -db

systemctl restart haproxy.service
				
			

Check HA proxy GUI and see all the MySQL target is up and running fine using HA Proxy Admin link:

HA Proxy Link Structure:

http://<localhost or IP/HostName/stats

http://192.168.1.208:9201/stats

Default Credentials : 

UserName : admin

Password: admin

Read More...