Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres operator #678

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/postgres-operator/demo-with-expose-trait.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: postgres-operator-sample-with-postgres-expose-trait
spec:
components:
- type: "postgres-cluster"
name: "postgres"
namespace: "default"
properties:
replicas: 3
traits:
- type: postgres-expose
properties:
type: NodePort
port: 5432
targetPort: 5432
32 changes: 27 additions & 5 deletions experimental/addons/postgres-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ spec:
replicas: 3
```

If you want to create a service to access Postgres, So apply below YAML:

```yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: postgres-operator-sample
spec:
components:
- type: "postgres-cluster"
name: "postgres"
namespace: "default"
properties:
replicas: 3 # By default it's set to 2.
traits:
- type: postgres-expose
properties:
type: NodePort # Change this field if you want diffrent type of service.
port: 5432
targetPort: 5432
```

```shell
$ kubectl get po -n prod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
Expand All @@ -65,16 +87,16 @@ With a port-forward on one of the database pods (e.g. the master) you can connec

```shell
# get name of master pod of acid-minimal-cluster
export PGMASTER=$(kubectl get pods -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=postgres,spilo-role=master -n prod)
$ export PGMASTER=$(kubectl get pods -n prod -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=postgres,spilo-role=master -n prod)

# set up port forward
kubectl port-forward $PGMASTER 6432:5432 -n default
kubectl port-forward $PGMASTER -n prod 5432:5432 -n prod
```

Open another CLI and connect to the database using e.g. the psql client. When connecting with a manifest role like foo_user user, read its password from the K8s secret which was generated when creating acid-minimal-cluster. As non-encrypted connections are rejected by default set SSL mode to require:

```shell
export PGPASSWORD=$(kubectl get secret postgres.postgres.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)
export PGSSLMODE=require
psql -U postgres -h localhost -p 6432
$ export PGPASSWORD=$(kubectl get secret -n prod postgres.postgres.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)
$ export PGSSLMODE=require
$ psql -U postgres -h localhost -p 5432
```
Loading