관리 메뉴

피터의 개발이야기

[Helm] MySQL 설치하기 본문

Kubernetes/Helm

[Helm] MySQL 설치하기

기록하는 백앤드개발자 2023. 6. 2. 07:42
반응형

 

ㅁ 들어가며

 데이터 마이그레이션 작업 시 임시적으로 MySql이 필요하여 helm으로 빠르게 설치하게 되었다. 그 과정에서 추가적으로 알아두면 좋은 점이 있어서 정리해 보았다.

 

 

ㅁ Helm repo 추가

$ helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories

 ㅇ 차트 리포지토리 추가가 되었다.

 

 

$ helm search repo bitnami

 ㅇ 리포지토리를 통해 설치가능 헬름 차트들의 목록과 설명을 확인 할 수 있다.

 

ㅁ helm install

$ helm install mysql-temp --set auth.rootPassword=tempopassword bitnami/mysql

 ㅇ 문법구조: helm install {릴리스 이름} {옵션} {저장소 이름}/{차트 이름}

 ㅇ root Password를 옵션으로 지정하였다.

 

NAME: mysql-temp
LAST DEPLOYED: Thu Jun  1 23:34:44 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 9.10.1
APP VERSION: 8.0.33

** Please be patient while the chart is being deployed **

Tip:
  Watch the deployment status using the command: kubectl get pods -w --namespace default

Services:
  echo Primary: mysql-temp.default.svc.cluster.local:3306

Execute the following to get the administrator credentials:
  echo Username: root
  MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-temp -o jsonpath="{.data.mysql-root-password}" | base64 -d)

To connect to your database:
  1. Run a pod that you can use as a client:
      kubectl run mysql-temp-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.33-debian-11-r12 --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash
  2. To connect to primary service (read/write):
      mysql -h mysql-temp.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"

 

 

ㅁ mkdir: cannot create directory '/bitnami/mysql/data': Permission denied

$ kubectl logs mysql-temp-0
mysql 15:06:52.40
mysql 15:06:52.40 Welcome to the Bitnami mysql container
mysql 15:06:52.40 Subscribe to project updates by watching https://github.com/bitnami/containers
mysql 15:06:52.41 Submit issues and feature requests at https://github.com/bitnami/containers/issues
mysql 15:06:52.41
mysql 15:06:52.41 INFO  ==> ** Starting MySQL setup **
mysql 15:06:52.42 INFO  ==> Validating settings in MYSQL_*/MARIADB_* env vars
mysql 15:06:52.42 INFO  ==> Initializing mysql database
mkdir: cannot create directory '/bitnami/mysql/data': Permission denied

 ㅇ Pod가 생성되지 않아 log를 확인한 결과 data 폴더를 만드는 과정에서 permision denied가 발생하였다.

 

 

 

ㅇ 문제가 되었던 permission을 해결하기 위해 volumePermission을 true로 수정하였다.

 

ㅇ rootPassword도기존 옵션형태로 설정한 부분을 선언형으로 함께 설정하였다.

 

 

ㅁ helm uninstall

$ helm uninstall mysql-temp
release "mysql-temp" uninstalled

 ㅇ 기존 설치된 mysql을 삭제하였다.

 

 

 

ㅁ reinstall

$ helm install mysql-temp -f values-mysql.yaml  bitnami/mysql
NAME: mysql-temp
LAST DEPLOYED: Fri Jun  2 07:11:15 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 9.10.1
APP VERSION: 8.0.33

** Please be patient while the chart is being deployed **

Tip:

  Watch the deployment status using the command: kubectl get pods -w --namespace default

Services:

  echo Primary: mysql-temp.default.svc.cluster.local:3306

Execute the following to get the administrator credentials:

  echo Username: root
  MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-temp -o jsonpath="{.data.mysql-root-password}" | base64 -d)

To connect to your database:

  1. Run a pod that you can use as a client:

      kubectl run mysql-temp-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.33-debian-11-r12 --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash

  2. To connect to primary service (read/write):

      mysql -h mysql-temp.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"

 

 

ㅁ Pod 기동 확인

$ kubectl get po
NAME           READY   STATUS    RESTARTS   AGE
mysql-temp-0   1/1     Running   0          71s

# log 확인
$ kubectl logs pods/mysql-temp-0
Defaulted container "mysql" out of: mysql, volume-permissions (init)
mysql 22:25:16.84
mysql 22:25:16.84 Welcome to the Bitnami mysql container
mysql 22:25:16.84 Subscribe to project updates by watching https://github.com/bitnami/containers
mysql 22:25:16.85 Submit issues and feature requests at https://github.com/bitnami/containers/issues
mysql 22:25:16.85
mysql 22:25:16.85 INFO  ==> ** Starting MySQL setup **
mysql 22:25:16.86 INFO  ==> Validating settings in MYSQL_*/MARIADB_* env vars
mysql 22:25:16.86 INFO  ==> Initializing mysql database
mysql 22:25:16.88 WARN  ==> The mysql configuration file '/opt/bitnami/mysql/conf/my.cnf' is not writable. Configurations based on environment variables will not be applied for this file.
mysql 22:25:16.88 INFO  ==> Using persisted data
mysql 22:25:16.90 INFO  ==> Running mysql_upgrade
mysql 22:25:16.90 INFO  ==> Starting mysql in background
find: '/docker-entrypoint-startdb.d/': No such file or directory
mysql 22:25:20.94 INFO  ==> Stopping mysql
mysql 22:25:22.99 INFO  ==> ** MySQL setup finished! **

mysql 22:25:23.02 INFO  ==> ** Starting MySQL **
2023-06-01T22:25:23.249120Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2023-06-01T22:25:23.249135Z 0 [System] [MY-010116] [Server] /opt/bitnami/mysql/bin/mysqld (mysqld 8.0.33) starting as process 1
2023-06-01T22:25:23.251197Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2023-06-01T22:25:23.251201Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8mb3_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2023-06-01T22:25:23.254940Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-06-01T22:25:23.337188Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-06-01T22:25:23.426665Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-06-01T22:25:23.426688Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-06-01T22:25:23.434589Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2023-06-01T22:25:23.434660Z 0 [System] [MY-010931] [Server] /opt/bitnami/mysql/bin/mysqld: ready for connections. Version: '8.0.33'  socket: '/opt/bitnami/mysql/tmp/mysql.sock'  port: 3306  Source distribution.

 

 

ㅁ 접속 확인

# 루트 비밀번호 환경변수 선언
$ MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-temp -o jsonpath="{.data.mysql-root-password}" | base64 -d)

# Client pod 생성 및 비밀번호 환경변수 전달
$ kubectl run mysql-temp-client --rm --tty -i --restart='Never' \
  --image  docker.io/bitnami/mysql:8.0.33-debian-11-r12 \
  --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
  --command -- bash

# mysql 접속
$ mysql -h mysql-temp.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"

# Error 발생
ERROR 2005 (HY000): Unknown MySQL server host 'mysql-temp.default.svc.cluster.local' (-3)

ㅇ ERROR 2005가 발생하였다.

 

 

ㅁ Port-forward로 접속 확인

# 서비스 확인
$ kubectl get svc
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
kubernetes            ClusterIP   10.96.0.1        <none>        443/TCP    12d
mysql-temp            ClusterIP   10.102.237.215   <none>        3306/TCP   3m22s
mysql-temp-headless   ClusterIP   None             <none>        3306/TCP   3m22s

# port-forward 구문 실행
❯ kubectl port-forward services/mysql-temp 3306
Forwarding from 127.0.0.1:3306 -> 3306
Forwarding from [::1]:3306 -> 3306
Handling connection for 3306

 ㅇ 일단 자체 DNS 접속에 문제가 있어서 port-forward를 통해 접속을 확인해 보았다.

 

 ㅇ 로컬에서 port-forward로 접속이 잘 되는 것을 확인할 수 있었다.

 

 

 

ㅁ 함께 보면 좋은 사이트

 

 

mysql 9.10.1 · bitnami/bitnami

MySQL is a fast, reliable, scalable, and easy to use open source relational database system. Designed to handle mission-critical, heavy-load production applications.

artifacthub.io

 

mkdir: cannot create directory '/bitnami/mariadb': Permission denied · Issue #8565 · bitnami/charts

Which chart: bitnami/mariab Describe the bug mariadb 12:47:08.65 mariadb 12:47:08.65 Welcome to the Bitnami mariadb container mariadb 12:47:08.65 Subscribe to project updates by watching https://gi...

github.com

 

반응형
Comments