Reorganize Readme (#142)
removing parts of config. * chaning secret name pattern to make things shorter. * Move section on self building docker image. * Fix typo. * Bump image. * bump version for pdb fix. * Changes in regards to review. * Fix xhyve driver link. * Move to new api, remove service account, not needed for minikube. * Changed minimal manifest and example to use right file. * Added service account for operator again, it is needed in pods anyways later.
This commit is contained in:
parent
7a76be7d3e
commit
a98a7c95c2
3
Makefile
3
Makefile
|
|
@ -11,14 +11,13 @@ endif
|
||||||
LOCAL_BUILD_FLAGS ?= $(BUILD_FLAGS)
|
LOCAL_BUILD_FLAGS ?= $(BUILD_FLAGS)
|
||||||
LDFLAGS ?= -X=main.version=$(VERSION)
|
LDFLAGS ?= -X=main.version=$(VERSION)
|
||||||
DOCKERFILE = docker/Dockerfile
|
DOCKERFILE = docker/Dockerfile
|
||||||
IMAGE ?= pierone.example.com/acid/$(BINARY)
|
IMAGE ?= registry.opensource.zalan.do/acid/$(BINARY)
|
||||||
TAG ?= $(VERSION)
|
TAG ?= $(VERSION)
|
||||||
GITHEAD = $(shell git rev-parse --short HEAD)
|
GITHEAD = $(shell git rev-parse --short HEAD)
|
||||||
GITURL = $(shell git config --get remote.origin.url)
|
GITURL = $(shell git config --get remote.origin.url)
|
||||||
GITSTATUS = $(shell git status --porcelain || echo "no changes")
|
GITSTATUS = $(shell git status --porcelain || echo "no changes")
|
||||||
SOURCES = cmd/main.go
|
SOURCES = cmd/main.go
|
||||||
VERSION ?= $(shell git describe --tags --always --dirty)
|
VERSION ?= $(shell git describe --tags --always --dirty)
|
||||||
IMAGE ?= pierone.example.com/acid/$(BINARY)
|
|
||||||
DIRS := cmd pkg
|
DIRS := cmd pkg
|
||||||
PKG := `go list ./... | grep -v /vendor/`
|
PKG := `go list ./... | grep -v /vendor/`
|
||||||
|
|
||||||
|
|
|
||||||
157
README.md
157
README.md
|
|
@ -27,6 +27,76 @@ it manages and updates them with the new docker images; afterwards, all pods fro
|
||||||
This project is currently in development. It is used internally by Zalando in order to run staging databases on Kubernetes.
|
This project is currently in development. It is used internally by Zalando in order to run staging databases on Kubernetes.
|
||||||
Please, report any issues discovered to https://github.com/zalando-incubator/postgres-operator/issues.
|
Please, report any issues discovered to https://github.com/zalando-incubator/postgres-operator/issues.
|
||||||
|
|
||||||
|
## Running and testing the operator
|
||||||
|
|
||||||
|
The best way to test the operator is to run it in minikube. Minikube is a tool to run Kubernetes cluster locally.
|
||||||
|
|
||||||
|
### Installing and starting minikube
|
||||||
|
|
||||||
|
See [minikube installation guide](https://github.com/kubernetes/minikube/releases)
|
||||||
|
|
||||||
|
Make sure you use the latest version of Minikube.
|
||||||
|
After the installation, issue the
|
||||||
|
|
||||||
|
$ minikube start
|
||||||
|
|
||||||
|
Note: if you are running on a Mac, make sure to use the [xhyve driver](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#xhyve-driver)
|
||||||
|
instead of the default docker-machine one for performance reasons.
|
||||||
|
|
||||||
|
One you have it started successfully, use [the quickstart guide](https://github.com/kubernetes/minikube#quickstart) in order
|
||||||
|
to test your that your setup is working.
|
||||||
|
|
||||||
|
Note: if you use multiple kubernetes clusters, you can switch to minikube with `kubectl config use-context minikube`
|
||||||
|
|
||||||
|
### Create ConfigMap
|
||||||
|
|
||||||
|
ConfigMap is used to store configuration of the operator
|
||||||
|
|
||||||
|
$ kubectl --context minikube create -f manifests/configmap.yaml
|
||||||
|
|
||||||
|
### Deploying the operator
|
||||||
|
|
||||||
|
First you need to install the service account definition in your minikube cluster.
|
||||||
|
|
||||||
|
$ kubectl --context minikube create -f manifests/serviceaccount.yaml
|
||||||
|
|
||||||
|
Next deploy the postgers-operator from the Docker image Zalando is using:
|
||||||
|
|
||||||
|
$ kubectl --context minikube create -f manifests/postgres-operator.yaml
|
||||||
|
|
||||||
|
If you perfer to build the image yourself follow up down below.
|
||||||
|
|
||||||
|
### Check if CustomResourceDefinition has been registered
|
||||||
|
|
||||||
|
$ kubectl --context minikube get crd
|
||||||
|
|
||||||
|
NAME KIND
|
||||||
|
postgresqls.acid.zalan.do CustomResourceDefinition.v1beta1.apiextensions.k8s.io
|
||||||
|
|
||||||
|
|
||||||
|
### Create a new spilo cluster
|
||||||
|
|
||||||
|
$ kubectl --context minikube create -f manifests/minimal-postgres-manifest.yaml
|
||||||
|
|
||||||
|
### Watch Pods being created
|
||||||
|
|
||||||
|
$ kubectl --context minikube get pods -w --show-labels
|
||||||
|
|
||||||
|
### Connect to PostgreSQL
|
||||||
|
|
||||||
|
We can use the generated secret of the `postgres` robot user to connect to our `acid-test-cluster` master running in Minikube:
|
||||||
|
|
||||||
|
$ export HOST_PORT=$(minikube service acid-test-cluster --url | sed 's,.*/,,')
|
||||||
|
$ export PGHOST=$(echo $HOST_PORT | cut -d: -f 1)
|
||||||
|
$ export PGPORT=$(echo $HOST_PORT | cut -d: -f 2)
|
||||||
|
$ export PGPASSWORD=$(kubectl --context minikube get secret postgres.acid-test-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
|
||||||
|
$ psql -U postgres
|
||||||
|
|
||||||
|
|
||||||
|
# Setup development environment
|
||||||
|
|
||||||
|
The following steps guide you through the setup to work on the operator itself.
|
||||||
|
|
||||||
## Setting up Go
|
## Setting up Go
|
||||||
|
|
||||||
Postgres operator is written in Go. Use the [installation instructions](https://golang.org/doc/install#install) if you don't have Go on your system.
|
Postgres operator is written in Go. Use the [installation instructions](https://golang.org/doc/install#install) if you don't have Go on your system.
|
||||||
|
|
@ -68,102 +138,27 @@ Building the operator binary (for testing the out-of-cluster option):
|
||||||
|
|
||||||
The binary will be placed into the build directory.
|
The binary will be placed into the build directory.
|
||||||
|
|
||||||
## Testing the operator
|
### Deploying self build image
|
||||||
|
|
||||||
The best way to test the operator is to run it in minikube. Minikube is a tool to run Kubernetes cluster locally.
|
The fastest way to run your docker image locally is to reuse the docker from minikube.
|
||||||
|
The following steps will get you the docker image built and deployed.
|
||||||
### Installing and starting minikube
|
|
||||||
|
|
||||||
See [minikube installation guide](https://github.com/kubernetes/minikube/releases)
|
|
||||||
|
|
||||||
Make sure you use the latest version of Minikube.
|
|
||||||
After the installation, issue the
|
|
||||||
|
|
||||||
$ minikube start
|
|
||||||
|
|
||||||
Note: if you are running on a Mac, make sure to use the [xhyve driver](https://github.com/kubernetes/minikube/blob/master/DRIVERS.md#xhyve-driver)
|
|
||||||
instead of the default docker-machine one for performance reasons.
|
|
||||||
|
|
||||||
One you have it started successfully, use [the quickstart guide](https://github.com/kubernetes/minikube#quickstart) in order
|
|
||||||
to test your that your setup is working.
|
|
||||||
|
|
||||||
Note: if you use multiple kubernetes clusters, you can switch to minikube with `kubectl config use-context minikube`
|
|
||||||
|
|
||||||
### Deploy etcd
|
|
||||||
|
|
||||||
Etcd is required to deploy the operator.
|
|
||||||
|
|
||||||
$ kubectl --context minikube create -f https://raw.githubusercontent.com/coreos/etcd/master/hack/kubernetes-deploy/etcd.yml
|
|
||||||
|
|
||||||
### Create ConfigMap
|
|
||||||
|
|
||||||
ConfigMap is used to store configuration of the operator
|
|
||||||
|
|
||||||
$ kubectl --context minikube create -f manifests/configmap.yaml
|
|
||||||
|
|
||||||
### Deploy fake Teams API
|
|
||||||
|
|
||||||
Teams API is used as a source of human users.
|
|
||||||
|
|
||||||
$ kubectl --context minikube create -f manifests/fake-teams-api.yaml
|
|
||||||
|
|
||||||
### Deploying the operator
|
|
||||||
|
|
||||||
You need to install the service account definition in your minikube cluster. You can run without it, but then you
|
|
||||||
have to change the service account references in the postgres-operator manifest as well.
|
|
||||||
|
|
||||||
$ kubectl --context minikube create -f manifests/serviceaccount.yaml
|
|
||||||
|
|
||||||
The fastest way to run your docker image locally is to reuse the docker from minikube. That way, there is no need to
|
|
||||||
pull docker images from pierone or push them, as the image is essentially there once you build it. The following steps
|
|
||||||
will get you the docker image built and deployed.
|
|
||||||
|
|
||||||
$ eval $(minikube docker-env)
|
$ eval $(minikube docker-env)
|
||||||
$ export TAG=$(git describe --tags --always --dirty)
|
$ export TAG=$(git describe --tags --always --dirty)
|
||||||
$ make docker
|
$ make docker
|
||||||
$ sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml|kubectl --context minikube create -f -
|
$ sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml|kubectl --context minikube create -f -
|
||||||
|
|
||||||
The last line changes the docker image tag in the manifest to the one the operator image has been built with and removes
|
|
||||||
the serviceAccountName definition, as the ServiceAccount is not defined in minikube (neither it should, as one has admin
|
|
||||||
permissions there).
|
|
||||||
|
|
||||||
### Check if CustomResourceDefinition has been registered
|
|
||||||
|
|
||||||
$ kubectl --context minikube get crd
|
|
||||||
|
|
||||||
NAME KIND
|
|
||||||
postgresqls.acid.zalan.do CustomResourceDefinition.v1beta1.apiextensions.k8s.io
|
|
||||||
|
|
||||||
|
|
||||||
### Create a new spilo cluster
|
|
||||||
|
|
||||||
$ kubectl --context minikube create -f manifests/testpostgresql.yaml
|
|
||||||
|
|
||||||
### Watch Pods being created
|
|
||||||
|
|
||||||
$ kubectl --context minikube get pods -w --show-labels
|
|
||||||
|
|
||||||
### Connect to PostgreSQL
|
|
||||||
|
|
||||||
We can use the generated secret of the `postgres` robot user to connect to our `acid-testcluster` master running in Minikube:
|
|
||||||
|
|
||||||
$ export HOST_PORT=$(minikube service acid-testcluster --url | sed 's,.*/,,')
|
|
||||||
$ export PGHOST=$(echo $HOST_PORT | cut -d: -f 1)
|
|
||||||
$ export PGPORT=$(echo $HOST_PORT | cut -d: -f 2)
|
|
||||||
$ export PGPASSWORD=$(kubectl --context minikube get secret postgres.acid-testcluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)
|
|
||||||
$ psql -U postgres
|
|
||||||
|
|
||||||
### Debugging the operator itself
|
### Debugging the operator itself
|
||||||
|
|
||||||
There is a web interface in the operator to observe its internal state. The operator listens on port 8080. It is possible to expose it to the localhost:8080 by doing:
|
There is a web interface in the operator to observe its internal state. The operator listens on port 8080. It is possible to expose it to the localhost:8080 by doing:
|
||||||
|
|
||||||
$ kubectl --context minikube port-forward $(kubectl --context minikube get pod -l name=postgres-operator -o jsonpath={.items..metadata.name}) 8080:8080
|
$ kubectl --context minikube port-forward $(kubectl --context minikube get pod -l name=postgres-operator -o jsonpath={.items..metadata.name}) 8080:8080
|
||||||
|
|
||||||
The inner 'query' gets the name of the postgres operator pod, and the outer enables port forwarding. Afterwards, you can access the operator API with:
|
The inner 'query' gets the name of the postgres operator pod, and the outer enables port forwarding. Afterwards, you can access the operator API with:
|
||||||
|
|
||||||
$ curl http://127.0.0.1:8080/$endpoint| jq .
|
$ curl http://127.0.0.1:8080/$endpoint| jq .
|
||||||
|
|
||||||
The available endpoints are listed below. Note that the worker ID is an integer from 0 up to 'workers' - 1 (value configured in the operator configuration and defaults to 4)
|
The available endpoints are listed below. Note that the worker ID is an integer from 0 up to 'workers' - 1 (value configured in the operator configuration and defaults to 4)
|
||||||
|
|
||||||
* /workers/all/queue - state of the workers queue (cluster events to process)
|
* /workers/all/queue - state of the workers queue (cluster events to process)
|
||||||
* /workers/$id/queue - state of the queue for the worker $id
|
* /workers/$id/queue - state of the queue for the worker $id
|
||||||
|
|
@ -181,5 +176,3 @@ The operator also supports pprof endpoints listed at the [pprof package](https:/
|
||||||
* /debug/pprof/profile
|
* /debug/pprof/profile
|
||||||
* /debug/pprof/symbol
|
* /debug/pprof/symbol
|
||||||
* /debug/pprof/trace
|
* /debug/pprof/trace
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ apiVersion: "acid.zalan.do/v1"
|
||||||
kind: postgresql
|
kind: postgresql
|
||||||
|
|
||||||
metadata:
|
metadata:
|
||||||
name: acid-testcluster17
|
name: acid-test-cluster
|
||||||
spec:
|
spec:
|
||||||
teamId: "ACID"
|
teamId: "ACID"
|
||||||
volume:
|
volume:
|
||||||
|
|
@ -18,7 +18,7 @@ spec:
|
||||||
foo: zalando
|
foo: zalando
|
||||||
#Expert section
|
#Expert section
|
||||||
postgresql:
|
postgresql:
|
||||||
version: "9.6"
|
version: "10"
|
||||||
parameters:
|
parameters:
|
||||||
shared_buffers: "32MB"
|
shared_buffers: "32MB"
|
||||||
max_connections: "10"
|
max_connections: "10"
|
||||||
|
|
@ -11,8 +11,8 @@ data:
|
||||||
debug_logging: "true"
|
debug_logging: "true"
|
||||||
dns_name_format: '{cluster}.{team}.staging.{hostedzone}'
|
dns_name_format: '{cluster}.{team}.staging.{hostedzone}'
|
||||||
docker_image: registry.opensource.zalan.do/acid/demospilo-10:1.3-p3
|
docker_image: registry.opensource.zalan.do/acid/demospilo-10:1.3-p3
|
||||||
|
secret_name_template: '{username}.{cluster}.credentials'
|
||||||
etcd_host: ""
|
etcd_host: ""
|
||||||
secret_name_template: '{username}.{cluster}.credentials.{tprkind}.{tprgroup}'
|
|
||||||
infrastructure_roles_secret_name: postgresql-infrastructure-roles
|
infrastructure_roles_secret_name: postgresql-infrastructure-roles
|
||||||
oauth_token_secret_name: postgresql-operator
|
oauth_token_secret_name: postgresql-operator
|
||||||
pam_configuration: |
|
pam_configuration: |
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
apiVersion: "acid.zalan.do/v1"
|
||||||
|
kind: postgresql
|
||||||
|
metadata:
|
||||||
|
name: acid-minimal-cluster
|
||||||
|
spec:
|
||||||
|
teamId: "ACID"
|
||||||
|
volume:
|
||||||
|
size: 1Gi
|
||||||
|
numberOfInstances: 2
|
||||||
|
users:
|
||||||
|
# database owner
|
||||||
|
zalando:
|
||||||
|
- superuser
|
||||||
|
- createdb
|
||||||
|
|
||||||
|
# role for application foo
|
||||||
|
foo_user:
|
||||||
|
|
||||||
|
#databases: name->owner
|
||||||
|
databases:
|
||||||
|
foo: zalando
|
||||||
|
postgresql:
|
||||||
|
version: "10"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
apiVersion: extensions/v1beta1
|
apiVersion: apps/v1beta1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: postgres-operator
|
name: postgres-operator
|
||||||
|
|
@ -12,7 +12,7 @@ spec:
|
||||||
serviceAccountName: operator
|
serviceAccountName: operator
|
||||||
containers:
|
containers:
|
||||||
- name: postgres-operator
|
- name: postgres-operator
|
||||||
image: pierone.stups.zalan.do/acid/postgres-operator:workerassgn
|
image: registry.opensource.zalan.do/acid/postgres-operator:c17aabb
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
env:
|
env:
|
||||||
- name: WATCH_NAMESPACE
|
- name: WATCH_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,3 @@ apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
name: operator
|
name: operator
|
||||||
imagePullSecrets:
|
|
||||||
- name: pierone.example.com
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue