其他
IvorySQL Operator | 一键部署IvorySQL集群,高效管理与个性化配置尽在掌控
IvorySQL Operator是在Kubernetes上部署和管理IvorySQL集群的Operator。借助IvorySQL Operator,用户可以在极短时间内迅速部署一个功能完备的IvorySQL集群,同时涵盖TLS通信安全、高可用、备份恢复及全面的监控。
此外,IvorySQL Operator还支持用户根据实际业务需求进行自定义配置,充分满足个性化的使用场景。
01
安装IvorySQL Operator
1.1 环境准备
1.2 安装部署
git clone git@github.com:IvorySQL/ivory-operator.git
export GOPROXY=https://goproxy.cn,direct
go build -o ivory-operator ./cmd/ivory-operator # ivory-operator可自定义
nohup ./ivory-operator > ivyo.log 2>&1 &
kubectl create -f ivory-operator.ivorysql.org_ivoryclusters.yaml
kubectl get crd
02
使用IvorySQL Operator
2.1 创建namespace
kubectl create ns ivory-operator # ivory-operator可自定义
2.2 创建实例
apiVersion: ivory-operator.ivorysql.org/v1beta1
kind: IvoryCluster
metadata:
name: ivy01
namespace: ivory-operator
spec:
image: docker.io/ivorysql/ivorysql:ubi8-3.0-2.0-1
postgresVersion: 16
instances:
- name: instance1
replicas: 2
dataVolumeClaimSpec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: 1Gi
backups:
pgbackrest:
image: docker.io/ivorysql/pgbackrest:ubi8-2.47-2.0-1
repos:
- name: repo1
volume:
volumeClaimSpec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: 1Gi
[root@k8s-master ivory-operator]# kubectl apply -k examples/kustomize/ivory
ivorycluster.ivory-operator.ivorysql.org/ivy01 configured
[root@k8s-master ivory-operator]kubectl -n ivory-operator get pods \
--selector=ivory-operator.ivorysql.org/cluster=ivy01,ivory-operator.ivorysql.org/instance
NAME READY STATUS RESTARTS AGE
ivy01-instance1-llrz-0 4/4 Running 0 3h40m
ivy01-instance1-wbdt-0 4/4 Running 0 3h40m
kubectl -n ivory-operator get pods \
--selector=ivory-operator.ivorysql.org/role=master \
-o jsonpath='{.items[*].metadata.labels.ivory-operator\.ivorysql\.org/instance}'
kubectl exec -it ivy01-instance1-wbdt-0 -c database -n ivory-operator -- /bin/bash
patronictl list
+------------------------+-----------------------------------+--------------+---------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+ Cluster: ivy01-ha (7309663449761415262) -------------------+--------------+---------+----+-----------+
| ivy01-instance1-llrz-0 | ivy01-instance1-llrz-0.ivy01-pods | Sync Standby | running | 4 | 0 |
| ivy01-instance1-wbdt-0 | ivy01-instance1-wbdt-0.ivy01-pods | Leader | running | 4 | |
+------------------------+-----------------------------------+--------------+---------+----+-----------+
2.3 链接实例
[root@k8s-master ivory-operator]# kubectl -n ivory-operator get svc --selector=ivory-operator.ivorysql.org/cluster=ivy01
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ivy01-ha NodePort 10.99.137.135 <none> 5432/TCP 3h42m
ivy01-ha-config ClusterIP None <none> <none> 3h42m
ivy01-pods ClusterIP None <none> <none> 3h42m
ivy01-primary ClusterIP None <none> 5432/TCP 3h42m
ivy01-replicas ClusterIP 10.100.178.96 <none> 5432/TCP 3h42m
spec:
service:
metadata:
annotations:
my-annotation: value1
labels:
my-label: value2
type: NodePort
kubectl -n ivory-operator get svc --selector=ivory-operator.ivorysql.org/cluster=ivy01
ivy01-ha NodePort 10.99.137.135 <none> 5432:31518/TCP 3h42m
ivy01-ha-config ClusterIP None <none> <none> 3h42m
ivy01-pods ClusterIP None <none> <none> 3h42m
ivy01-primary ClusterIP None <none> 5432/TCP 3h42m
ivy01-replicas ClusterIP 10.100.178.96 <none> 5432/TCP 3h42m
psql -h 127.0.0.1 -p 31518 -d postgres -U ivorysql
2.4 用户及数据库管理
spec:
users:
- name: rhino
databases:
- zoo
[root@k8s-master ivory-operator]# kubectl apply -k examples/kustomize/ivory
ivorycluster.ivory-operator.ivorysql.org/ivy01 configured
kubectl exec -it ivy01-ivy-wgp4-0 -n ivory-operator -- /bin/bashs
[ivorysql@ivy01-instance1-llrz-0 /]$ psql -d zoo
psql (16.0)
Type "help" for help.
zoo=# \du
List of roles
Role name | Attributes
------------+------------------------------------------------------------
_ivoryrepl | Replication
ivy01 |
ivorysql | Superuser, Create role, Create DB, Replication, Bypass RLS
rhino |
DROP OWNED BY rhino;
DROP ROLE rhino;
DROP DATABASE zoo;
[root@k8s-master ivory-operator]# kubectl delete -k examples/kustomize/ivory
ivorycluster.ivory-operator.ivorysql.org "ivy01" deleted
2.5 实例管理
kubectl patch IvoryCluster/ivy01 -n ivory-operator --type merge \
--patch '{"spec":{"metadata":{"annotations":{"restarted":"'"$(date)"'"}}}}'
kubectl patch IvoryCluster/ivy01 -n ivory-operator --type merge \
--patch '{"spec":{"shutdown": true}}'
spec:
instances:
resources:
limits:
cpu: 2.0
memory: 4Gi
[root@k8s-master ivory-operator]# kubectl apply -k examples/kustomize/ivory
ivorycluster.ivory-operator.ivorysql.org/ivy01 configured
spec:
patroni:
dynamicConfiguration:
postgresql:
parameters:
max_parallel_workers: 2
max_worker_processes: 2
shared_buffers: 1GB
work_mem: 4MB
2.6 高可用主备切换
spec:
patroni:
switchover:
enabled: true
targetInstance: ivy01-instance1-wm5p
(注意:targetInstance 非必填,ivy01-instance1-wm5p为要切换为主的INSTANCE)
[root@k8s-master ivory-operator]# kubectl apply -k examples/kustomize/ivory
ivorycluster.ivory-operator.ivorysql.org/ivy01 configured
kubectl annotate -n ivory-operator IvoryCluster ivy01 ivory-operator.ivorysql.org/trigger-switchover="$(date)"
kubectl -n ivory-operator get pods \
--selector=ivory-operator.ivorysql.org/role=master \
-o jsonpath='{.items[*].metadata.labels.ivory-operator\.ivorysql\.org/instance}'
kubectl annotate -n ivory-operator IvoryCluster ivy01 ivory-operator.ivorysql.org/trigger-switchover="$(date)" –overwrite
2.7 备份恢复
spec:
backups:
pgbackrest:
image: docker.io/ivorysql/pgbackrest:ubi8-2.47-2.0-1
manual:
options:
- --type=full
repoName: repo1
kubectl annotate -n ivory-operator IvoryCluster ivy01 ivory-operator.ivorysql.org/pgbackrest-backup="$(date)"
spec:
backups:
pgbackrest:
image: docker.io/ivorysql/pgbackrest:ubi8-2.47-2.0-1
restore:
enabled: true
repoName: repo1
options:
- --type=time
- --target="2023-06-25 09:38:00"
[root@k8s-master ivory-operator]# kubectl apply -k examples/kustomize/ivory
ivorycluster.ivory-operator.ivorysql.org/ivy01
kubectl annotate -n ivory-operator IvoryCluster ivy01 ivory-operator.ivorysql.org/pgbackrest-restore=id1
kubectl get all -n ivory-operator
kubectl get all -n ivory-operator
kubectl exec -it ivy01-ivy-wgp4-0 -n ivory-operator -- /bin/bash
关注公众号,了解更多社区动态
- 我们是谁 -
lvorySQL是由浪潮软件集团瀚高股份主导研发的,一款深度兼容Oracle的PostgreSQL开源数据库系统。IvorySQL从底层代码层面深入把握开源技术的发展趋势,基于PostgreSQL 16.2的最新内核进行构建,同时提供了更加全面灵活的Oracle兼容功能,具备高度的SQL和PL/SQL兼容性,能够满足企业对于数据库系统多样化和高兼容性的需求。
IvorySQL 3.2 发版 | 基于PG16.2,新增Oracle XML函数兼容功能 喊话大学生!IvorySQL走进北京大学研究生开源公选课 上周六的南京,近百位南京PG圈爱好者都来啦! 2024 Meetup地区组织者招募,共赴IvorySQL城市行 基于IvorySQL+Patroni+vip-manager构建高可用集群 备份恢复新体验!pgBackRest与IvorySQL的完美融合 初学者指南 | PostgreSQL中的加密机制如何运作? 白鲸开源科技与瀚高股份IvorySQL完成产品兼容性互相认证! 7个维度!PostgreSQL生态展望:2024路向何方? 基于PG16.0最新内核,实现兼容Oracle数据库再升级 IvorySQL的IVY_GUC框架介绍与使用指南 IvorySQL新增命令及有关配置参数介绍 IvorySQL在「兼容oracle」方面做了哪些工作? IvorySQL内核的Serverless数据库——HGNeon适配国内云对象存储 迁移Oracle数据库至IvorySQL(PG兼容模式) PostgreSQL16中的新增功能:双向逻辑复制 Kubernetes上PostgreSQL的存储策略 IvorySQL新增命令及有关配置参数介绍 7个工具!让Oracle 迁移至 PostgreSQL成为可能! 4步上手Meson:让PostgreSQL 16 构建更现代化!
IvorySQL