본문 바로가기
Infra System

mariadb cluster install on kubernetes

by kellis 2020. 10. 13.

helm으로 설치하였으며, 따라서 helm이 설치되어 있어야 합니다. 

 

1. 설치 방법

1. helm으로 mariadb 설치

helm install --name air-mariadb --namespace persistence --set rootUser.password=root#,db.user=air,password=air# -f values.yaml stable/mariadb

이때 사용한 values.yaml은 아래와 같으며, 여기에서 가장 중요한 것은 외부 포트 오픈을 위해 service: NodePort를 지정해주었다는 것입니다. 

더보기

## Global Docker image parameters

## Please, note that this will override the image parameters, including dependencies, configured to use the global value

## Current available global Docker image parameters: imageRegistry and imagePullSecrets

##

# global:

#   imageRegistry: myRegistryName

#   imagePullSecrets:

#     - myRegistryKeySecretName

#   storageClass: myStorageClass

 

## Use an alternate scheduler, e.g. "stork".

## ref: https://kubernetes.io/docs/tasks/administer-cluster/configure-multiple-schedulers/

##

# schedulerName:

 

## Bitnami MariaDB image

## ref: https://hub.docker.com/r/bitnami/mariadb/tags/

##

image:

  registry: docker.io

  repository: bitnami/mariadb

  tag: 10.3.20-debian-9-r0

  ## Specify a imagePullPolicy

  ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'

  ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images

  ##

  pullPolicy: IfNotPresent

  ## Optionally specify an array of imagePullSecrets.

  ## Secrets must be manually created in the namespace.

  ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

  ##

  # pullSecrets:

  #   - myRegistryKeySecretName

 

  ## Set to true if you would like to see extra information on logs

  ## It turns BASH and NAMI debugging in minideb

  ## ref:  https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging

  debug: false

 

## String to partially override mariadb.fullname template (will maintain the release name)

##

# nameOverride:

 

## String to fully override mariadb.fullname template

##

# fullnameOverride:

 

## Init containers parameters:

## volumePermissions: Change the owner and group of the persistent volume mountpoint to runAsUser:fsGroup values from the securityContext section.

##

volumePermissions:

  enabled: false

  image:

    registry: docker.io

    repository: bitnami/minideb

    tag: stretch

    pullPolicy: Always

    ## Optionally specify an array of imagePullSecrets.

    ## Secrets must be manually created in the namespace.

    ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

    ##

    # pullSecrets:

    #   - myRegistryKeySecretName

  resources: {}

 

service:

  ## Kubernetes service type, ClusterIP and NodePort are supported at present

  type: NodePort

  # clusterIp:

  #   master: xx.xx.xx.xx

  #   slave: xx.xx.xx.xx

  port: 3306

  ## Specify the nodePort value for the LoadBalancer and NodePort service types.

  ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport

  ##

  nodePort:

    master: 30001

    slave: 30002

 

## Pods Service Account

## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

serviceAccount:

  ## Specifies whether a ServiceAccount should be created

  ##

  create: false

  ## The name of the ServiceAccount to use.

  ## If not set and create is true, a name is generated using the mariadb.fullname template

  # name:

 

## Role Based Access

## Ref: https://kubernetes.io/docs/admin/authorization/rbac/

##

 

rbac:

  create: false

 

## Pod Security Context

## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

##

securityContext:

  enabled: true

  fsGroup: 1001

  runAsUser: 1001

 

# # Use existing secret (ignores root, db and replication passwords)

# existingSecret:

 

rootUser:

  ## MariaDB admin password

  ## ref: https://github.com/bitnami/bitnami-docker-mariadb#setting-the-root-password-on-first-run

  ##

  password: root#

  ##

  ## Option to force users to specify a password. That is required for 'helm upgrade' to work properly.

  ## If it is not force, a random password will be generated.

  forcePassword: false

 

db:

  ## MariaDB username and password

  ## ref: https://github.com/bitnami/bitnami-docker-mariadb#creating-a-database-user-on-first-run

  ##

  user: air

  password: air#

  ## Password is ignored if existingSecret is specified.

  ## Database to create

  ## ref: https://github.com/bitnami/bitnami-docker-mariadb#creating-a-database-on-first-run

  ##

  name: air_test

  ## Option to force users to specify a password. That is required for 'helm upgrade' to work properly.

  ## If it is not force, a random password will be generated.

  forcePassword: false

 

replication:

  ## Enable replication. This enables the creation of replicas of MariaDB. If false, only a

  ## master deployment would be created

  enabled: true

  ##

  ## MariaDB replication user

  ## ref: https://github.com/bitnami/bitnami-docker-mariadb#setting-up-a-replication-cluster

  ##

  user: replicator

  ## MariaDB replication user password

  ## ref: https://github.com/bitnami/bitnami-docker-mariadb#setting-up-a-replication-cluster

  ##

  password:

  ## Password is ignored if existingSecret is specified.

  ##

  ## Option to force users to specify a password. That is required for 'helm upgrade' to work properly.

  ## If it is not force, a random password will be generated.

  forcePassword: false

 

## initdb scripts

## Specify dictionary of scripts to be run at first boot

## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory

##

# initdbScripts:

#   my_init_script.sh: |

#      #!/bin/sh

#      echo "Do something."

#

## ConfigMap with scripts to be run at first boot

## Note: This will override initdbScripts

# initdbScriptsConfigMap:

 

master:

  ## Mariadb Master additional pod annotations

  ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/

  # annotations:

  #   key: value

  #   another-key: another-value

 

  ## MariaDB additional command line flags

  ## Can be used to specify command line flags, for example:

  ##

  ## extraFlags: "--max-connect-errors=1000 --max_connections=155"

 

  ## Affinity for pod assignment

  ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity

  ##

  affinity: {}

 

  ## Kept for backwards compatibility. You can now disable it by removing it.

  ## if you wish to set it through master.affinity.podAntiAffinity instead.

  ##

  antiAffinity: soft

 

  ## Node labels for pod assignment

  ## Ref: https://kubernetes.io/docs/user-guide/node-selection/

  ##

  nodeSelector: {}

 

  ## Tolerations for pod assignment

  ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/

  ##

  tolerations: []

 

  ## updateStrategy for MariaDB Master StatefulSet

  ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies

  updateStrategy:

    type: RollingUpdate

 

  ## Enable persistence using Persistent Volume Claims

  ## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/

  ##

  persistence:

    ## If true, use a Persistent Volume Claim, If false, use emptyDir

    ##

    enabled: true

    # Enable persistence using an existing PVC

    # existingClaim:

    # Subdirectory of the volume to mount

    # subPath:

    mountPath: /bitnami/mariadb

    ## Persistent Volume Storage Class

    ## If defined, storageClassName: <storageClass>

    ## If set to "-", storageClassName: "", which disables dynamic provisioning

    ## If undefined (the default) or set to null, no storageClassName spec is

    ##   set, choosing the default provisioner.  (gp2 on AWS, standard on

    ##   GKE, AWS & OpenStack)

    ##

    # storageClass: "-"

    ## Persistent Volume Claim annotations

    ##

    annotations: {}

    ## Persistent Volume Access Mode

    ##

    accessModes:

    - ReadWriteOnce

    ## Persistent Volume size

    ##

    size: 8Gi

 

  extraInitContainers: |

  # - name: do-something

  #   image: busybox

  #   command: ['do', 'something']

 

  ## An array to add extra environment variables

  ## For example:

  ## extraEnvVars:

  ##  - name: TZ

  ##    value: "Europe/Paris"

  ##

  # extraEnvVars:

 

  ## Configure MySQL with a custom my.cnf file

  ## ref: https://mysql.com/kb/en/mysql/configuring-mysql-with-mycnf/#example-of-configuration-file

  ##

  config: |-

    [mysqld]

    skip-name-resolve

    explicit_defaults_for_timestamp

    basedir=/opt/bitnami/mariadb

    plugin_dir=/opt/bitnami/mariadb/plugin

    port=3306

    socket=/opt/bitnami/mariadb/tmp/mysql.sock

    tmpdir=/opt/bitnami/mariadb/tmp

    max_allowed_packet=16M

    bind-address=0.0.0.0

    pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid

    log-error=/opt/bitnami/mariadb/logs/mysqld.log

    character-set-server=UTF8

    collation-server=utf8_general_ci

    [client]

    port=3306

    socket=/opt/bitnami/mariadb/tmp/mysql.sock

    default-character-set=UTF8

    plugin_dir=/opt/bitnami/mariadb/plugin

    [manager]

    port=3306

    socket=/opt/bitnami/mariadb/tmp/mysql.sock

    pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid

  ## Configure master resource requests and limits

  ## ref: http://kubernetes.io/docs/user-guide/compute-resources/

  ##

  resources: {}

  livenessProbe:

    enabled: true

    ##

    ## Initializing the database could take some time

    initialDelaySeconds: 120

    ##

    ## Default Kubernetes values

    periodSeconds: 10

    timeoutSeconds: 1

    successThreshold: 1

    failureThreshold: 3

  readinessProbe:

    enabled: true

    initialDelaySeconds: 30

    ##

    ## Default Kubernetes values

    periodSeconds: 10

    timeoutSeconds: 1

    successThreshold: 1

    failureThreshold: 3

 

  podDisruptionBudget:

    enabled: false

    minAvailable: 1

    # maxUnavailable: 1

 

  ## Allow customization of the service resource

  ##

  service:

    ## Add custom annotations to the service

    ##

    annotations: {}

      # external-dns.alpha.kubernetes.io/hostname: db.example.com

 

slave:

  replicas: 1

 

  ## Mariadb Slave additional pod annotations

  ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/

  # annotations:

  #   key: value

  #   another-key: another-value

 

  ## MariaDB additional command line flags

  ## Can be used to specify command line flags, for example:

  ##

  ## extraFlags: "--max-connect-errors=1000 --max_connections=155"

 

  ## Affinity for pod assignment

  ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity

  ##

  affinity: {}

 

  ## Kept for backwards compatibility. You can now disable it by removing it.

  ## if you wish to set it through slave.affinity.podAntiAffinity instead.

  ##

  antiAffinity: soft

 

  ## Node labels for pod assignment

  ## Ref: https://kubernetes.io/docs/user-guide/node-selection/

  ##

  nodeSelector: {}

 

  ## Tolerations for pod assignment

  ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/

  ##

  tolerations: []

 

  ## updateStrategy for MariaDB Slave StatefulSet

  ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies

  updateStrategy:

    type: RollingUpdate

 

  persistence:

    ## If true, use a Persistent Volume Claim, If false, use emptyDir

    ##

    enabled: true

    # storageClass: "-"

    annotations:

    accessModes:

    - ReadWriteOnce

    ## Persistent Volume size

    ##

    size: 8Gi

 

  extraInitContainers: |

  # - name: do-something

  #   image: busybox

  #   command: ['do', 'something']

 

  ## An array to add extra environment variables

  ## For example:

  ## extraEnvVars:

  ##  - name: TZ

  ##    value: "Europe/Paris"

  ##

  # extraEnvVars:

 

  ## Configure MySQL slave with a custom my.cnf file

  ## ref: https://mysql.com/kb/en/mysql/configuring-mysql-with-mycnf/#example-of-configuration-file

  ##

  config: |-

    [mysqld]

    skip-name-resolve

    explicit_defaults_for_timestamp

    basedir=/opt/bitnami/mariadb

    port=3306

    socket=/opt/bitnami/mariadb/tmp/mysql.sock

    tmpdir=/opt/bitnami/mariadb/tmp

    max_allowed_packet=16M

    bind-address=0.0.0.0

    pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid

    log-error=/opt/bitnami/mariadb/logs/mysqld.log

    character-set-server=UTF8

    collation-server=utf8_general_ci

    [client]

    port=3306

    socket=/opt/bitnami/mariadb/tmp/mysql.sock

    default-character-set=UTF8

    [manager]

    port=3306

    socket=/opt/bitnami/mariadb/tmp/mysql.sock

    pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid

  ##

  ## Configure slave resource requests and limits

  ## ref: http://kubernetes.io/docs/user-guide/compute-resources/

  ##

  resources: {}

  livenessProbe:

    enabled: true

    ##

    ## Initializing the database could take some time

    initialDelaySeconds: 120

    ##

    ## Default Kubernetes values

    periodSeconds: 10

    timeoutSeconds: 1

    successThreshold: 1

    failureThreshold: 3

  readinessProbe:

    enabled: true

    initialDelaySeconds: 45

    ##

    ## Default Kubernetes values

    periodSeconds: 10

    timeoutSeconds: 1

    successThreshold: 1

    failureThreshold: 3

 

  podDisruptionBudget:

    enabled: false

    minAvailable: 1

    # maxUnavailable: 1

 

  ## Allow customization of the service resource

  ##

  service:

    ## Add custom annotations to the service

    ##

    annotations: {}

      # external-dns.alpha.kubernetes.io/hostname: rodb.example.com

 

metrics:

  enabled: false

  image:

    registry: docker.io

    repository: bitnami/mysqld-exporter

    tag: 0.12.1-debian-9-r96

    pullPolicy: IfNotPresent

    ## Optionally specify an array of imagePullSecrets.

    ## Secrets must be manually created in the namespace.

    ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

    ##

    # pullSecrets:

    #   - myRegistryKeySecretName

  resources: {}

  annotations:

    prometheus.io/scrape: "true"

    prometheus.io/port: "9104"

 

  ## Extra args to be passed to mysqld_exporter

  ## ref: https://github.com/prometheus/mysqld_exporter/

  ##

  extraArgs:

    master: []

    slave: []

      # - --collect.auto_increment.columns

      # - --collect.binlog_size

      # - --collect.engine_innodb_status

      # - --collect.engine_tokudb_status

      # - --collect.global_status

      # - --collect.global_variables

      # - --collect.info_schema.clientstats

      # - --collect.info_schema.innodb_metrics

      # - --collect.info_schema.innodb_tablespaces

      # - --collect.info_schema.innodb_cmp

      # - --collect.info_schema.innodb_cmpmem

      # - --collect.info_schema.processlist

      # - --collect.info_schema.processlist.min_time

      # - --collect.info_schema.query_response_time

      # - --collect.info_schema.tables

      # - --collect.info_schema.tables.databases

      # - --collect.info_schema.tablestats

      # - --collect.info_schema.userstats

      # - --collect.perf_schema.eventsstatements

      # - --collect.perf_schema.eventsstatements.digest_text_limit

      # - --collect.perf_schema.eventsstatements.limit

      # - --collect.perf_schema.eventsstatements.timelimit

      # - --collect.perf_schema.eventswaits

      # - --collect.perf_schema.file_events

      # - --collect.perf_schema.file_instances

      # - --collect.perf_schema.indexiowaits

      # - --collect.perf_schema.tableiowaits

      # - --collect.perf_schema.tablelocks

      # - --collect.perf_schema.replication_group_member_stats

      # - --collect.slave_status

      # - --collect.slave_hosts

      # - --collect.heartbeat

      # - --collect.heartbeat.database

      # - --collect.heartbeat.table

 

  livenessProbe:

    enabled: true

    ##

    ## Initializing the database could take some time

    initialDelaySeconds: 120

    ##

    ## Default Kubernetes values

    periodSeconds: 10

    timeoutSeconds: 1

    successThreshold: 1

    failureThreshold: 3

  readinessProbe:

    enabled: true

    initialDelaySeconds: 30

    ##

    ## Default Kubernetes values

    periodSeconds: 10

    timeoutSeconds: 1

    successThreshold: 1

    failureThreshold: 3

 

  # Enable this if you're using https://github.com/coreos/prometheus-operator

  serviceMonitor:

    enabled: false

    ## Specify a namespace if needed

    # namespace: monitoring

    # fallback to the prometheus default unless specified

    # interval: 10s

    # scrapeTimeout: 10s

    ## Defaults to what's used if you follow CoreOS [Prometheus Install Instructions](https://github.com/helm/charts/tree/master/stable/prometheus-operator#tldr)

    ## [Prometheus Selector Label](https://github.com/helm/charts/tree/master/stable/prometheus-operator#prometheus-operator-1)

    ## [Kube Prometheus Selector Label](https://github.com/helm/charts/tree/master/stable/prometheus-operator#exporters)

    selector:

      prometheus: kube-prometheus

 

2. 설치 시 제공되는 데이터

Please be patient while the chart is being deployed
 
Tip:
 
  Watch the deployment status using the command: kubectl get pods -w --namespace persistence -l release=air-maria
 
Services:
 
  echo Master: air-mariadb.persistence.svc.cluster.local:3306
  echo Slave:  air-mariadb-slave.persistence.svc.cluster.local:3306
 
Administrator credentials:
 
  Username: root
  Password : $(kubectl get secret --namespace persistence air-mariadb -o jsonpath="{.data.mariadb-root-password}"
 
To connect to your database:
 
  1. Run a pod that you can use as a client:
 
      kubectl run air-mariadb-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mariadb:10.3.20-deommand -- bash
 
  2. To connect to master service (read/write):
 
      mysql -h air-mariadb.persistence.svc.cluster.local -uroot -p my_database
 
  3. To connect to slave service (read-only):
 
      mysql -h air-mariadb-slave.persistence .svc.cluster.local -uroot -p my_database
 
To upgrade this helm chart:
 
  1. Obtain the password as described on the 'Administrator credentials' section and set the 'rootUser.password' p
 
      ROOT_PASSWORD=$(kubectl get secret --namespace persistence air-mariadb -o jsonpath="{.data.mariadb-root-pas
      helm upgrade air-mariadb stable/mariadb --set rootUser.password=$ROOT_PASSWORD

이를 참고하여 mariadb를 실행하겠습니다. 


2. 설치 확인

 

1. 쿠버네티스 실행 및 mysql 접속

kubectl run air-mariadb-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mariadb:10.3.20-deommand -- bash

2. 외부에서 원격으로 mysql 접속 

mysql -h13.209.8.232 -P30001 -uair -pair#

3. 유저생성 

CREATE USER 'test'@'13.209.8.232' IDENTIFIED BY 'test#';

% 는 localhost를 포함하지 않기 때문에, 쿠버네티스와 파이프라이닝 하려면 localhost를 받아들일 수 있도록 호스트를 현재 ip주소로 주어야 합니다.

 

5. HeidiSQL 접속

'Infra System' 카테고리의 다른 글

mongodb install using docker(standalone)  (0) 2020.10.13
mongodb install on ec2  (0) 2020.10.13
kafka cluster installation on kubernetes  (0) 2020.10.13
jenkins install on kubernetes  (0) 2020.10.13
helm installation  (0) 2020.10.13

댓글