3-shake SRE Tech Talk #7のLT枠で発表した内容の資料です https://3-shake.connpass.com/event/293432/
LTでは以下の二点を扱っています 1. PostgreSQL Operatorの一つであるZalando PostgreSQL Operatorの紹介 2. GKEで動かしたZalando PostgreSQL OperatorとCloud SQLと見比べる
Copyright © 3-shake, Inc. All Rights Reserved.KubernetesでDBを動かしたいSRETT#7株式会社スリーシェイク 中楯 直希
View Slide
\du2株式会社スリーシェイク Sreake事業部業務内容- DBRE兼SRE見習い- クラウドもオンプレも分からない- Kubernetesも分からない- データベースも分からない- 自称データ雑用係- DBAでもDBREでもデータエンジニアでも興味あること- データベース関連ならなんでも中楯 直希@nnaka2992@nnaka2992.bsky.social
“GKEでクリティカルなデータを用いるアプリを運用する顧客が増加している。GKEクラスタで動くステートフルなアプリは2019年以来指数関数的に増えている。”Akshay Ram背景3Google Joins Data on Kubernetes Communityhttps://dok.community/newsroom/google-joins-data-on-kubernetes-community/
データベースをKubernetes上で動かすことが当たり前な世界になりつつある- MySQL- PostgreSQL- Oracle Database- NewSQL- MongoDB- Redis- etc…背景4
今回はZalando PostgreSQL Operatorで試す- PostgreSQLクラスタの作成やフェイルオーバー、スケーリングなどDB運用に必要なことは大抵やってくれる- 性能監視にはGrafana/Prometheusなどを自前で準備する必要がある- Quickstartをなぞれば最低限動くZalando PostgreSQL Operator5
実際のManifestZalando PostgreSQL Operator6kind: "postgresql"apiVersion: "acid.zalan.do/v1"metadata:name: "nnaka2992-performance-comparison-cluster"namespace: "default"labels:team: nnaka2992spec:teamId: "nnaka2992"postgresql:version: "15"numberOfInstances: 1volume:size: "5Gi"users:test: []databases:test: testenableMasterLoadBalancer: trueresources:requests:cpu: 4000m # 4vCPUmemory: 15258Mi # 16GBlimits:cpu: 4000mmemory: 15258Mi
動作確認Zalando PostgreSQL Operator72023-10-12 01:06:21 ⌚ nnaka2992-Dev in ~/Dev/gcloud/nnaka2992-kube-poc/manifests○ → kubectl get podsNAME READY STATUS RESTARTS AGEnnaka2992-performance-comparison-cluster-0 1/1 Running 0 176mpostgres-operator-77f6d658c-wwrc6 1/1 Running 0 14hpostgres-operator-ui-7bf9676b84-gb7fh 1/1 Running 0 14h# ここより下はProxyサーバ$ export PGPASSWORD=$(kubectl get secret test.nnaka2992-performance-comparison-cluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)$ host=$(kubectl get node -ojson | jq -r '.items[0].status.addresses[0].address')$ port=$(kubectl get svc nnaka2992-performance-comparison-cluster -ojson | jq -r '.spec.ports[0].nodePort')$ export PGSSLMODE=require$ psql -U test -h $host -p $portpsql -U test -h $host -p $portpsql (15.4 (Debian 15.4-2.pgdg110+1), server 15.2 (Ubuntu 15.2-1.pgdg22.04+1))SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)Type "help" for help.test=> select schemaname as schema, viewname as name, 'view' as type from pg_views limit 3;schema | name | type----------------+-------------------------+------public | pg_stat_statements_info | viewpublic | pg_stat_statements | viewpublic | pg_stat_kcache_detail | view
ただ動かすだけでは芸がないのでCloud SQL(VM)と比較Cloud SQL for PostgreSQLとの比較8Kubernetes(GKE)のスペック- IOPS <=4000(2000x2)- Throughput <= 26MB- CPU 4000m- Memory 15258MiBIOPSとThroughputはiostatからの推定値Cloud SQLのスペック- IOPS <=4500(2250x2)- Throughput <= 36MB- CPU 4vCPU- Memory 16GB
注意- 完璧な対象実験ではありません- 特にストレージ周りはとても適当です- 実行タイミングでそれぞれのパフォーマンスは変わります- なのでどちらのパフォーマンスが優れているかといったことを結論づけるものではありませんCloud SQL for PostgreSQLとの比較9
ベンチマークにはpgbench TPC-Bを利用DB on Kubernetesの利用にパフォーマンス面での問題は少なそうCloud SQL for PostgreSQLとの比較10
- DBをKubernetesで動かすのは難しくない- パフォーマンス劣化も少なさそう- EKSならストレージのIOPSも細かく制御できるからEKSでやるべきだった- ちゃんとpgbenchのコネクション数に合わせたスレッド数を設定してあげるべきだったまとめ11
参考資料12- Google Joins Data on Kubernetes Community | Data on Kubernetes Comunity- https://dok.community/newsroom/google-joins-data-on-kubernetes-community/- Postgres Operator- https://postgres-operator.readthedocs.io/en/latest/- Quickstart | Postgres Operator- https://postgres-operator.readthedocs.io/en/latest/quickstart/- PostgreSQLをKubernetes上で活用するための Operator紹介!(Cloud Native DatabaseMeetup #3 発表資料)- https://www.slideshare.net/nttdata-tech/postgresql-kubernetes-operator-cloud-native-database-meetup-3-nttdata- Zalando Postgres Operatorの紹介 | SRA OSS Tech Blog- https://www.sraoss.co.jp/tech-blog/pgsql/zalando-postgres-operator/- pgbench | PostgreSQL Documentation 16- https://www.postgresql.org/docs/current/pgbench.html