PostgreSQL 学习笔记(3):高可用 Kubernetes Operator

前言:Kubernetes 部署服务如果不熟悉的情况尽量使用 Helm 或者 Operator 。

https://github.com/zalando/postgres-operator

# First, clone the repository and change to the directory
git clone https://github.com/zalando/postgres-operator.git
cd postgres-operator

# apply the manifests in the following order
kubectl create -f manifests/configmap.yaml  # configuration
kubectl create -f manifests/operator-service-account-rbac.yaml  # identity and permissions
kubectl create -f manifests/postgres-operator.yaml  # deployment
kubectl create -f manifests/api-service.yaml  # operator API to be used by UI
# if you've created the operator using yaml manifests
kubectl get pod -l name=postgres-operator

# if you've created the operator using helm chart
kubectl get pod -l app.kubernetes.io/name=postgres-operator
# manual deployment
kubectl apply -f ui/manifests/
# create a Postgres cluster
kubectl create -f manifests/minimal-postgres-manifest.yaml
# check the deployed cluster
kubectl get postgresql

# check created database pods
kubectl get pods -l application=spilo -L spilo-role

# check created service resources
kubectl get svc -l application=spilo -L spilo-role

测试

export PGPASSWORD=$(kubectl get secret postgres.acid-minimal-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
# Mac 用户使用 -D
# export PGPASSWORD=$(kubectl get secret postgres.acid-minimal-cluster.credentials -o 'jsonpath={.data.password}' | base64 -D)
kubectl exec -it acid-minimal-cluster-0 sh
export PGPASSWORD=dtP3mIHOmrztiLoWrqlYXqwLEX9ctFzmLWSZwLbB90LFW2kl9jFzmEoD6myY9ObJ
psql -h acid-minimal-cluster -p 5432 -U postgres

注:这里我是在 pod 容器里连接的,因为在 Mac 宿主机上连接时会报 SSL 连接异常。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容