MySQL Operator for Kubernetes

JM·2021년 6월 30일
0

MySQL

목록 보기
9/10

📌 MySQL Operator for Kubernetes는 현재 Preivew 상태입니다.

MySQL Operator for Kubernetes

  • Kubernetes 클러스터 내에서 MySQL InnoDB 클러스터 설정을 관리
  • 업그레이드 및 백업 자동화를 포함하여 설정 및 유지 관리를 통해 전체 수명주기를 관리

Installation of the MySQL Operator

  • kubectl을 사용하여 설치

1. Docker 설치

https://docs.docker.com/engine/install/centos/

-- yum-utils 패키지 설치 (yum-config-manager 유틸리티 제공)
# yum install -y yum-utils

-- 저장소 설정
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

-- 최신 버전의 Docker Engine 및 containerd 설치
# yum install -y docker-ce docker-ce-cli containerd.io

-- Start Docker
# systemctl start docker

2. Kubernetes 설치 (minikube)

  • minikube는 Kubernetes 용으로 쉽게 배우고 개발할 수 있도록하는 데 초점을 맞춘 로컬 Kubernetes

https://minikube.sigs.k8s.io/docs/start/

-- rpm 파일 다운로드 
# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm

-- rpm 파일 설치
# rpm -Uvh minikube-latest.x86_64.rpm

-- Start Cluster
# minikube start
  
  ※ root 계정으로 실행하여 아래 에러 발생
   -> X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
   
  ※ 일반 사용자로 (group docker 추가) 실행 or '--force' 옵션으로 기동
   -> # usermod -aG docker $user
   -> # minikube start --force --driver=docker

-- kubectl 설치
# minikube kubectl -- get po -A
 > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
 > kubectl: 38.36 MiB / 38.36 MiB [-----------] 100.00% 240.51 MiB p/s 400ms

NAMESPACE     NAME                               READY   STATUS    RESTARTS   AGE
kube-system   coredns-74ff55c5b-j4n7t            1/1     Running   0          12m
kube-system   etcd-minikube                      1/1     Running   0          12m
kube-system   kube-apiserver-minikube            1/1     Running   0          12m
kube-system   kube-controller-manager-minikube   1/1     Running   0          12m
kube-system   kube-proxy-k59xx                   1/1     Running   0          12m
kube-system   kube-scheduler-minikube            1/1     Running   0          12m
kube-system   storage-provisioner                1/1     Running   0          12m

3. MySQL Operator 설치

https://github.com/mysql/mysql-operator

-- kubectl 사용
# minikube kubectl -- apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-crds.yaml
# minikube kubectl -- apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-operator.yaml

-- mysql-operator 실행 확인
# minikube kubectl -- get deployment -n mysql-operator mysql-operator
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
mysql-operator   1/1     1            1           95s

  ※ CRD 배포는 Kubernetes 클러스터의 크기에 따라 몇 초 정도 걸릴 수 있음

-- MySQL root 계정 생성
# minikube kubectl -- create secret generic mypwds --from-literal=rootUser=root --from-literal=rootHost=% --from-literal=rootPassword="PASSWORD"
secret/mypwds created

-- InnoDB 클러스터 생성
# minikube kubectl -- apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/samples/sample-cluster.yaml
innodbcluster.mysql.oracle.com/mycluster created

-- InnoDB 클러스터 생성 모니터링 (MySQL 인스턴스 3개, MySQL Router 인스턴스 1)
# minikube kubectl -- get innodbcluster
NAME        STATUS   ONLINE   INSTANCES   ROUTERS   AGE
mycluster   ONLINE   3        3           1         3m3s

-- Service 생성 확인
# minikube kubectl -- get service mycluster
NAME        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                               AGE
mycluster   ClusterIP   10.104.222.167   <none>        6446/TCP,6448/TCP,6447/TCP,6449/TCP   4m9s

-- Service 세부 정보 확인
# minikube kubectl -- describe service mycluster
Name:              mycluster
Namespace:         default
Labels:            mysql.oracle.com/cluster=mycluster
                   tier=mysql
Annotations:       <none>
Selector:          component=mysqlrouter,mysql.oracle.com/cluster=mycluster,tier=mysql
Type:              ClusterIP
IP Families:       <none>
IP:                10.104.222.167
IPs:               10.104.222.167
Port:              mysql  6446/TCP
TargetPort:        6446/TCP
Endpoints:         172.18.0.5:6446
Port:              mysqlx  6448/TCP
TargetPort:        6448/TCP
Endpoints:         172.18.0.5:6448
Port:              mysql-ro  6447/TCP
TargetPort:        6447/TCP
Endpoints:         172.18.0.5:6447
Port:              mysqlx-ro  6449/TCP
TargetPort:        6449/TCP
Endpoints:         172.18.0.5:6449
Session Affinity:  None
Events:            <none>

-- 외부 접속을 위한 포트 포워딩
 - Read-Write Port
# minikube kubectl -- port-forward --address 0.0.0.0 service/mycluster mysql &
Forwarding from 0.0.0.0:6446 -> 6446

 - Read-Only Port
# minikube kubectl -- port-forward --address 0.0.0.0 service/mycluster mysql-ro &
Forwarding from 0.0.0.0:6447 -> 6447

-- MySQL InnoDB Cluster 접속
 - Primary Node (Read-Write)
# mysql -u root -p -h $ip -P6446

 - Secondary Node (Read-Only)
# mysql -u root -p -h $ip -P6447

Kubernetes Dashboard

-- 대시보드 실행
# minikube dashboard &
* Enabling dashboard ...
  - Using image kubernetesui/dashboard:v2.1.0
  - Using image kubernetesui/metrics-scraper:v1.0.4
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
http://127.0.0.1:38428/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

-- 대시보드 pod 확인
# minikube kubectl -- get pod --namespace=kubernetes-dashboard
NAME                                        READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-f6647bd8c-fckr2   1/1     Running   0          21m
kubernetes-dashboard-968bcb79-qfvhj         1/1     Running   0          21m

-- 외부 접속을 위한 포트 포워딩
# minikube kubectl -- proxy --address 0.0.0.0 kubernetes-dashboard-968bcb79-qfvhj 8001:80 --namespace=kubernetes-dashboard --disable-filter=true &
Starting to serve on [::]:8001

-- 대시보드 접속
http://server_ip:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
profile
오픈소스 DB엔지니어

0개의 댓글