Helm/MariaDB

From Chorke Wiki
Jump to navigation Jump to search
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update && helm repo list
kubectl config get-contexts

Config

export KUBECONFIG="${HOME}/.kube/dev-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/gcp-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/config"

Install

kubectl get ns|grep mariadb
kubectl delete ns   mariadb

kubectl get ns|grep mariadb
kubectl create ns   mariadb
cat <<ENV | kubectl -n mariadb create secret generic mariadb --from-env-file=/dev/stdin
mariadb-replication-password=sadaqah!
mariadb-root-password=sadaqah!
mariadb-password=sadaqah!
ENV

cat <<YML | helm -n mariadb install    mariadb bitnami/mariadb --version=19.0.5 -f -
---
global:
  defaultStorageClass: standard
architecture: standalone
auth:
  database: academia
  username: academia
  existingSecret: mariadb
initdbScripts:
  init-chorke.sql: |
     -- create database
     CREATE DATABASE IF NOT EXISTS academia_flair_staging;
     CREATE DATABASE IF NOT EXISTS academia_audit_staging;
     CREATE DATABASE IF NOT EXISTS academia_quote_staging;
     CREATE DATABASE IF NOT EXISTS academia_users_staging;
     CREATE DATABASE IF NOT EXISTS chorke;
     
     -- create user
     CREATE USER 'chorke'@'%' IDENTIFIED BY 'sadaqah!';
     
     -- grant access
     GRANT ALL PRIVILEGES ON academia_flair_staging.* TO 'chorke'@'%';
     GRANT ALL PRIVILEGES ON academia_audit_staging.* TO 'chorke'@'%';
     GRANT ALL PRIVILEGES ON academia_quote_staging.* TO 'chorke'@'%';
     GRANT ALL PRIVILEGES ON academia_users_staging.* TO 'chorke'@'%';
     GRANT ALL PRIVILEGES ON chorke.* TO 'chorke'@'%';
YML

echo -n password: ;read -s MYSQL_PWD;export MYSQL_PWD;echo
mariadb -hmariadb.k8s.local -p3306 -uacademia academia
mariadb -hmariadb.k8s.local -p3306 -uroot mysql
echo -n password: ;read -s MYSQL_PWD;export MYSQL_PWD;echo
mariadb 'mariadb://[email protected]:3306/academia'
mariadb 'mariadb://[email protected]:3306/mysql'

Uninstall

helm uninstall -n mariadb mariadb
kubectl delete namespace mariadb

Swiss Knife

kubectl -n mariadb run -i --tty --rm mariadb-client --image=alpine --restart=Never -- sh
echo -n password: ;read -s MYSQL_PWD;export MYSQL_PWD; echo
apk --update add --no-cache mariadb-client inetutils-telnet

mariadb -hmariadb.mariadb.svc.cluster.local -uroot academia
mariadb -hmariadb.mariadb.svc -uroot academia
mariadb -hmariadb.mariadb -uroot academia
mariadb -hmariadb -uroot academia

AWS » EKS

AWS » EKS » EBS

cat << YML | kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mariadb-pv
spec:
  accessModes:
  - ReadWriteOnce
  awsElasticBlockStore:
    fsType: ext4
    volumeID: aws://ap-southeast-1/vol-0bbbd80804f1ae62a
  capacity:
    storage: 10Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: "gp2"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app.kubernetes.io/name: mariadb
  name: mariadb-pvc
  namespace: mariadb
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: "gp2"
  volumeName: mariadb-pv
YML

AWS » EKS » Patch

kubectl -n mariadb get sts/mariadb -ojson|jq -r '.spec.template.spec.nodeSelector'

cat <<YML | kubectl -n mariadb patch sts/mariadb --patch-file=/dev/stdin
---
spec:
  template:
    spec:
      nodeSelector:
        topology.kubernetes.io/zone: minikube
YML
cat <<YML | kubectl -n mariadb patch sts/mariadb --patch-file=/dev/stdin
---
spec:
  template:
    spec:
      nodeSelector:
        topology.kubernetes.io/zone: ap-southeast-1a
YML

kubectl -n mariadb get sts/mariadb -ojson|jq -r '.spec.template.spec.nodeSelector'
kubectl -n mariadb delete pods --all

Playground

helm -n mariadb install    mariadb bitnami/mariadb --version=19.0.0
helm -n mariadb upgrade -i mariadb bitnami/mariadb --version=19.0.5
helm show values bitnami/mariadb --version=19.0.5|less

kubectl -n mariadb get secret mariadb -o json|jq -r '.data."mariadb-replication-password"'|base64 -d;echo
kubectl -n mariadb get secret mariadb -o json|jq -r '.data."mariadb-root-password"'|base64 -d;echo
kubectl -n mariadb get secret mariadb -o json|jq -r '.data."mariadb-password"'|base64 -d;echo

kubectl -n mariadb exec -it svc/mariadb -c mariadb -- mariadb -uacademia academia -p
kubectl -n mariadb exec -it svc/mariadb -c mariadb -- bash
kubectl -n mariadb exec -it svc/mariadb -- mysql -uroot -p

kubectl config --kubeconfig=${HOME}/.kube/aws-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/dev-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/gcp-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/config view --flatten

kubectl -n mariadb delete all --all
kubectl -n mariadb delete ing --all
kubectl -n mariadb delete sts --all
kubectl -n mariadb delete svc --all
kubectl -n mariadb delete pvc --all
kubectl -n mariadb delete pv  --all

kubectl -n mariadb rollout history sts mariadb
kubectl -n mariadb rollout restart sts mariadb
kubectl -n mariadb rollout status  sts mariadb
kubectl -n mariadb exec -it mariadb-0  -- mariadb -uroot -p
kubectl -n mariadb logs -f svc/mariadb -c mariadb
kubectl -n mariadb logs -f svc/mariadb

References