연재 시리즈

쿠버네티스 오퍼레이터 스터디 2주차 - mysql operator설치

악분 2022. 6. 4. 16:06
반응형

이 글은 mysql operator설치 방법에 대해 소개합니다.

 

1. mysql operator 소개

oracle기업이 22.5월에 mysql operator을 공식 릴리즈했습니다. mysql은 oracle기업이 관리하고 있어 공식 operator라는 점이 가장 눈에 띕니다.

 

mysql operator는 InnoDB cluster 관리를 자동화합니다.

mysql operator 소개

그래서 msyql-operator를 설치과정에 InnoDB클러스터 구성이 있습니다. mysql-operator를 설치하면 아래 그림과 같은 아키텍처를 가지고 있습니다.

자세한 내용(https://blogs.oracle.com/mysql/post/mysql-operator-for-kubernetes-reaches-general-availability)에서 볼 수 있습니다.

mysql-operator 구조

 

2. mysql operator 설치

mysql operator설치는 helm 차트로 쉽게 설치할 수 있습니다. 총 2개의 helm 차트를 설치해야 합니다.

  1. mysql operator helm 차트
  2. InnobDB cluster helm 차트

 

2.1 operator helm 차트 설치

참고자료: https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-installation-helm.html

mysql 공식 홈페이지에 방문하면 helm 차트 설치 가이드가 있습니다. 저는 2.0.4버전 차트를 설치했습니다.

helm repo add mysql-operator https://mysql.github.io/mysql-operator/
helm repo update
helm install \
mysql-operator mysql-operator/mysql-operator \
--namespace mysql-operator \
--create-namespace \
--version 2.0.4

 

helm 차트를 설치하면 InnoDB 설치 가이드 메세지가 출력됩니다.

 

operator는 deployment로 관리됩니다.

kubectl -n mysql-operator get all

 

CRD 4개도 생성되었습니다.

kuebctl get crd | grep -v calico

 

2.2 mysql operator-innodb cluster

참고자료: https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-innodbcluster-simple-helm.html

mysql 공식 홈페이지에 방문하면 helm 차트 설치 가이드가 있습니다. 저는 2.0.4버전 차트를 설치했습니다.

helm install mycluster \
mysql-operator/mysql-innodbcluster \
--set credentials.root.password='sakila' \
--set tls.useSelfSigned=true \
--namespace mysql-cluster \
--create-namespace --version 2.0.4

 

InnoDB 클러스터는 statefulset으로 설치됩니다.

kubectl get innodbcluster,sts,pod,pvc,svc -n mysql-cluster

 

CRD Innodb클러스터 상태를 조회할 수 있습니다.

kubectl get InnoDBCluster -n mysql-cluster

 

statefulset으로 배포된 mysql databse pod는 라벨로 필터링 할 수 있습니다.

kubectl get pod -n mysql-cluster -l app.kubernetes.io/component=database -owide

 

Innodb cluster는 group replication이 설정되어 있습니다. 해당 설정은 configmap에 있습니다.

kubectl describe cm -n mysql-cluster mycluster-initconf | grep "01-group_replication.cnf" -A 10

 

3. mysql endpoint 접근

3.1 접근방법

mysql endpoint는 router와 database가 존재합니다. 비지니스 로직은 router을 이용하여 mysql에 접근하는게 좋습니다. 특정 데이터베이스를 조회가 필요할 때는 headless서비스를 이용하여 접근해야 합니다. 이 글에서는 router을 이용한 endpoint접근 방법을 소개합니다.

 

router는 사용자 요청을 적절하게 로드밸런싱 하여 부하를 분산시킵니다. 부하 분산설정은 이 글에서 다루지 않고 다음 글에 다룰 예정입니다.

 

router접근은 kubernetes router service를 이용하여 접근할 수 있습니다.

 

router service이름은 mycluter입니다. 그리고 endpoint주소는 mycluster.mysql-cluster.svc.cluster.local입니다.

kubectl get svc -n mysql-cluster mycluster

 

3.2 router 접근

service 쿠버네티스 도메인을 이용해서 router로 접근해볼건데요. mysql-operator pod안에 mysql shell이 설치되어 있어 별도로 mysql client를 설치하지 않아도 됩니다.

kubectl exec -it -n mysql-operator deploy/mysql-operator -- mysqlsh

 

router endpoint접속방법은 \connect [user]@[endpoint]입니다. 중간에 패스워드 입력이 필요합니다.

\connect root@mycluster.mysql-cluster.svc.cluster.local

 

\status명령어로 connection상태를 확인할 수 있습니다.

\status

 

3.3 쿼리 실행

쿼리를 실행하기 위해 sql모드로 전환해야 합니다. \sql명령어를 입력하면 전환할 수 있습니다.

\sql

 

테스트로 mysql버전을 확인하는 쿼리를 실행했습니다.

SELECT VERSION();

 

4. 삭제

삭제는 설치했던 helm차트 2개를 역순으로 삭제하면 됩니다.

# InnoDB helm 차트 삭제
helm uninstall mycluster -n mysql-cluster && kubectl delete ns mysql-cluster

# operator helm 차트 삭제
helm uninstall mysql-operator -n mysql-operator && kubectl delete ns mysql-operator

 

5. 참고자료

반응형