|
1 | 1 | ## Prerequisites:
|
2 | 2 |
|
3 |
| -In order to run the Postgres operator locally in minikube you need to install the following tools: |
| 3 | +In order to run the Postgres Operator locally in minikube you need to install |
| 4 | +the following tools: |
4 | 5 |
|
5 | 6 | * [minikube](https://github.com/kubernetes/minikube/releases)
|
6 | 7 | * [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl)
|
7 | 8 |
|
8 | 9 | Note that you can also use built-in Kubernetes support in the Docker Desktop
|
9 | 10 | for Mac to follow the steps of this tutorial. You would have to replace
|
10 |
| -`minikube start` and `minikube delete` with your launch actionsfor the Docker |
| 11 | +`minikube start` and `minikube delete` with your launch actions for the Docker |
11 | 12 | built-in Kubernetes support.
|
12 | 13 |
|
13 |
| -## Local execution |
| 14 | +Clone the repository and change to the directory. Then start minikube. |
14 | 15 |
|
15 | 16 | ```bash
|
16 | 17 | git clone https://github.com/zalando/postgres-operator.git
|
17 | 18 | cd postgres-operator
|
18 | 19 |
|
19 | 20 | minikube start
|
| 21 | +``` |
20 | 22 |
|
21 |
| -# start the operator using one of helm chart or yaml manifests; |
| 23 | +## Manual deployment setup |
22 | 24 |
|
23 |
| -# - install postgres-operator with helm chart. |
24 |
| -# 1) initialize helm |
25 |
| -helm init |
26 |
| -# 2) install postgres-operator chart |
27 |
| -helm install --name postgres-operator ./charts/postgres-operator |
| 25 | +The Postgres Operator can be installed simply by applying yaml manifests. |
28 | 26 |
|
29 |
| -# - install postgres-operator with yaml manifests. |
| 27 | +```bash |
30 | 28 | kubectl create -f manifests/configmap.yaml # configuration
|
31 | 29 | kubectl create -f manifests/operator-service-account-rbac.yaml # identity and permissions
|
32 | 30 | kubectl create -f manifests/postgres-operator.yaml # deployment
|
| 31 | +``` |
33 | 32 |
|
| 33 | +## Helm chart |
34 | 34 |
|
35 |
| -# starting the operator may take a few seconds |
36 |
| -# check if operator pod is running |
| 35 | +Another possibility is using a provided [Helm](https://helm.sh/) chart which |
| 36 | +saves you these steps. Therefore, you would need to install the helm CLI on your |
| 37 | +machine. After initializing helm (and its server component Tiller) in your local |
| 38 | +cluster you can install the operator chart. |
37 | 39 |
|
38 |
| -# - if you've created the operator using helm chart |
39 |
| -kubectl get po -l app.kubernetes.io/name=postgres-operator |
| 40 | +```bash |
| 41 | +# 1) initialize helm |
| 42 | +helm init |
| 43 | +# 2) install postgres-operator chart |
| 44 | +helm install --name postgres-operator ./charts/postgres-operator |
| 45 | +``` |
| 46 | + |
| 47 | +## Create a Postgres cluster |
40 | 48 |
|
41 |
| -# - if you've created the operator using yaml manifests |
42 |
| -kubectl get po -l name=postgres-operator |
| 49 | +Starting the operator may take a few seconds. Check if the operator pod is |
| 50 | +running before applying a Postgres cluster manifest. |
| 51 | + |
| 52 | +```bash |
| 53 | +# if you've created the operator using yaml manifests |
| 54 | +kubectl get pod -l name=postgres-operator |
43 | 55 |
|
| 56 | +# if you've created the operator using helm chart |
| 57 | +kubectl get pod -l app.kubernetes.io/name=postgres-operator |
44 | 58 |
|
45 | 59 | # create a Postgres cluster
|
46 | 60 | kubectl create -f manifests/minimal-postgres-manifest.yaml
|
| 61 | +``` |
| 62 | + |
| 63 | +After the cluster manifest is submitted the operator will create Service and |
| 64 | +Endpoint resources and a StatefulSet which spins up new Pod(s) given the number |
| 65 | +of instances specified in the manifest. All resources are named like the |
| 66 | +cluster. The database pods can be identified by their number suffix, starting |
| 67 | +from `-0`. They run the [Spilo](https://github.com/zalando/spilo) container |
| 68 | +image by Zalando. As for the services and endpoints, there will be one for the |
| 69 | +master pod and another one for all the replicas (`-repl` suffix). Check if all |
| 70 | +components are coming up. Use the label `application=spilo` to filter and list |
| 71 | +the label `spilo-role` to see who is currently the master. |
| 72 | + |
| 73 | +```bash |
| 74 | +# check the deployed cluster |
| 75 | +kubectl get postgresql |
| 76 | + |
| 77 | +# check created database pods |
| 78 | +kubectl get pods -l application=spilo -L spilo-role |
47 | 79 |
|
48 |
| -# connect to the Postgres master via psql |
49 |
| -# operator creates the relevant k8s secret |
| 80 | +# check created service resources |
| 81 | +kubectl get svc -l application=spilo -L spilo-role |
| 82 | +``` |
| 83 | + |
| 84 | +## Connect to the Postgres cluster via psql |
| 85 | + |
| 86 | +You can retrieve the host and port of the Postgres master from minikube. |
| 87 | +Retrieve the password from the Kubernetes Secret that is created in your cluster. |
| 88 | + |
| 89 | +```bash |
50 | 90 | export HOST_PORT=$(minikube service acid-minimal-cluster --url | sed 's,.*/,,')
|
51 | 91 | export PGHOST=$(echo $HOST_PORT | cut -d: -f 1)
|
52 | 92 | export PGPORT=$(echo $HOST_PORT | cut -d: -f 2)
|
53 | 93 | export PGPASSWORD=$(kubectl get secret postgres.acid-minimal-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
|
54 | 94 | psql -U postgres
|
| 95 | +``` |
| 96 | + |
| 97 | +## Delete a Postgres cluster |
| 98 | + |
| 99 | +To delete a Postgres cluster simply delete the postgresql custom resource. |
| 100 | + |
| 101 | +```bash |
| 102 | +kubectl delete postgresql acid-minimal-cluster |
55 | 103 |
|
56 | 104 | # tear down cleanly
|
57 | 105 | minikube delete
|
58 | 106 | ```
|
59 | 107 |
|
60 |
| -We have automated starting the operator and submitting the `acid-minimal-cluster` for you: |
61 |
| -```bash |
62 |
| -cd postgres-operator |
63 |
| -./run_operator_locally.sh |
64 |
| -``` |
65 | 108 |
|
66 | 109 | ## Running and testing the operator
|
67 | 110 |
|
68 | 111 | The best way to test the operator is to run it in [minikube](https://kubernetes.io/docs/getting-started-guides/minikube/).
|
69 | 112 | Minikube is a tool to run Kubernetes cluster locally.
|
70 | 113 |
|
| 114 | +For convenience, we have automated starting the operator and submitting the |
| 115 | +`acid-minimal-cluster`. From inside the cloned repository execute the |
| 116 | +`run_operator_locally` shell script. |
| 117 | + |
| 118 | +```bash |
| 119 | +./run_operator_locally.sh |
| 120 | +``` |
| 121 | + |
| 122 | +Note we provide the `/manifests` directory as an example only; you should |
| 123 | +consider adjusting the manifests to your particular setting. |
| 124 | + |
| 125 | + |
71 | 126 | ### Configuration Options
|
72 | 127 |
|
73 |
| -The operator can be configured with the provided ConfigMap (`manifests/configmap.yaml`). |
| 128 | +The operator can be configured with the provided ConfigMap |
| 129 | +(`manifests/configmap.yaml`) or the operator's own CRD. See |
| 130 | +[developer docs](developer.md) for details. |
0 commit comments