Mariadb in Kubernetes

  • Home
  • / Mariadb in Kubernetes

image

29 Jan 2024

09

35

Introduction

This documentation shows you how you can configure a Minikube Container as kubernetes cluster to deploy 5 replicas of mariadb.

Steps:

Start Ubuntu or any Linux

Install Minikube

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

Start Docker with following command

 sudo systemctl start docker
 or
 sudo service docker start

startwsl

Verify docker status

systemctl status docker

startdocker

Create file called "mariadb.yaml". Enter following

apiVersion: apps/v1
kind: Deployment 
metadata:
  name: mariadb-deployment
spec: 
  replicas: 5 
  selector:
    matchLabels:
      app: mariadb
  template: 
    metadata:
      labels:
        app: mariadb 
    spec:
      containers: 
      - name: mariadb
        image: mariadb
        resources:
          limits:
            memory: 512Mi
            cpu: "1"
          requests:
            memory: 256Mi
            cpu: "0.2"
        ports:
        - containerPort: 3306 
        env:        
        - name: MARIADB_ALLOW_EMPTY_ROOT_PASSWORD
          value: "0" # if it is 1 and root_password is set, root_password takes precedance
        - name: MARIADB_ROOT_PASSWORD
          value: secret

Run the following command to start Minikube cluster:

minikube start
kubectl cluster-info
kubectl apply -f mariadb.yaml

dockerrun

After this you can write various commands for detail info

kubectl get deployments
kubectl get pods -o wide | grep minikube
kubectl get pods

dockerps dockerps

You can start Minikube Dashboard by entering following command:

minikube dashboard

dockerps dockerps

To connect to mariadb enter this command:

you need to forward the port 3306 before that

 kubectl port-forward mariadb-deployment-695d57dc6d-blnns 3306:3306 #(mariadb-deployment-695d57dc6d-blnns is one of the 5 pod)
 kubectl exec -it mariadb-deployment-695d57dc6d-blnns -- mariadb -u root -psecret 

dockerps

Connect from MySql Workbench

start workbench and click on new connection 
use host as 127.0.0.1 and port as forwarded port in this case 3306 enter password and done.

connected

Join our newsletter!

Enter your email to receive our latest newsletter.

Don't worry, we don't spam

image

Related Articles

image
14 Feb 2024

Deploying a FREE Nodejs Serverless API in Vercel with Zenstack, Prisma and Neon's Free PostgreSQL

Explore the process of deploying a serverless API with Vercel, leveraging Zenstack for Prisma integration, TypeScript for enhanced development, and Neon's complimentary PostgreSQL database for your project. -by Evan Dangol

image
07 Feb 2024

Harnessing Machine Learning to Detect Toxic Comments - Using Calibrated Binary Classification Metrics Module

Unveiling Machine Learning's Power- Detecting Toxic Comments with C# -by Evan Dangol

image
06 Feb 2024

Will gRPC ultimately replace REST Api in future? A simple gRPC using nodejs with Nextjs

It's unlikely that gRPC will entirely replace REST (Representational State Transfer) API in the near future, as both technologies have their own strengths and are suitable for different use cases.gRPC (Google Remote Procedure Call) is a high-performance...