|
1 | 1 | # Kubectl Plugin for Zalando's Postgres Operator
|
2 | 2 |
|
3 |
| -## Google Summer of Code 2019 |
4 |
| - |
5 |
| -This plugin is a prototype developed as a part of GSoC 2019 under the organisation |
6 |
| -**The Postgres Operator** |
7 |
| - |
8 |
| -### GSoC Proposal |
| 3 | +This plugin is a prototype developed as a part of **Google Summer of Code 2019** under the [Postgres Operator](https://summerofcode.withgoogle.com/archive/2019/organizations/6187982082539520/) organization. |
9 | 4 |
|
10 |
| -[kubectl pg proposal](https://docs.google.com/document/d/1-WMy9HkfZ1XnnMbzplMe9rCzKrRMGaMz4owLVXXPb7w/edit) |
| 5 | +## Installation of kubectl pg plugin |
11 | 6 |
|
12 |
| -### Weekly Reports |
| 7 | +This project uses Go Modules for dependency management to build locally. |
| 8 | +Install go and enable go modules with ```export GO111MODULE=on```. |
| 9 | +From Go >=1.13 Go modules will be enabled by default. |
13 | 10 |
|
14 |
| -https://github.com/VineethReddy02/GSoC-Kubectl-Plugin-for-Postgres-Operator-tracker |
15 |
| - |
16 |
| - ### Final Project Report |
17 |
| - |
18 |
| - https://gist.github.com/VineethReddy02/159283bd368a710379eaf0f6bd60a40a |
19 |
| - |
20 |
| - |
21 |
| -### Installtion of kubectl pg plugin |
22 |
| - |
23 |
| -This project uses Go Modules for dependency management to build locally |
24 |
| -Install go and enable go modules ```export GO111MODULE=on``` |
25 |
| -From Go >=1.13 Go modules will be enabled by default |
26 |
| -``` |
| 11 | +```bash |
27 | 12 | # Assumes you have a working KUBECONFIG
|
28 |
| -$ GO111MODULE="on" |
29 |
| -# As of now go by default doesn't support Go mods. So explicit enabling is required. |
30 |
| -$ GOPATH/src/github.com/zalando/postgres-operator/kubectl-pg go mod vendor |
| 13 | +$ GO111MODULE="on" |
| 14 | +$ GOPATH/src/github.com/zalando/postgres-operator/kubectl-pg go mod vendor |
31 | 15 | # This generate a vendor directory with all dependencies needed by the plugin.
|
32 | 16 | $ $GOPATH/src/github.com/zalando/postgres-operator/kubectl-pg go install
|
33 | 17 | # This will place the kubectl-pg binary in your $GOPATH/bin
|
34 | 18 | ```
|
35 | 19 |
|
36 |
| -### Before using the kubectl pg plugin make sure to set KUBECONFIG env varibale |
| 20 | +## Before using the kubectl pg plugin make sure to set KUBECONFIG env variable |
37 | 21 |
|
38 | 22 | Ideally KUBECONFIG is found in $HOME/.kube/config else specify the KUBECONFIG path here.
|
| 23 | +```export KUBECONFIG=$HOME/.kube/config``` |
39 | 24 |
|
40 |
| -```export KUBECONFIG=$HOME/.kube/config``` |
41 |
| - |
42 |
| -### To list all commands available in kubectl pg |
| 25 | +## List all commands available in kubectl pg |
43 | 26 |
|
44 | 27 | ```kubectl pg --help``` (or) ```kubectl pg```
|
45 | 28 |
|
46 |
| -### This basically means the operator pod managed to start, so our operator is installed. |
| 29 | +## Check if Postgres Operator is installed and running |
47 | 30 |
|
48 | 31 | ```kubectl pg check```
|
49 | 32 |
|
50 |
| -### To create postgresql cluster using manifest file |
| 33 | +## Create a new cluster using manifest file |
51 | 34 |
|
52 | 35 | ```kubectl pg create -f acid-minimal-cluster.yaml```
|
53 | 36 |
|
54 |
| -### To update existing cluster using manifest file |
| 37 | +## List postgres resources |
| 38 | + |
| 39 | +```kubectl pg list``` |
| 40 | + |
| 41 | +List clusters across namespaces |
| 42 | +```kubectl pg list all``` |
| 43 | + |
| 44 | +## Update existing cluster using manifest file |
55 | 45 |
|
56 | 46 | ```kubectl pg update -f acid-minimal-cluster.yaml```
|
57 | 47 |
|
58 |
| -### To delete existing cluster using manifest file |
| 48 | +## Delete existing cluster |
59 | 49 |
|
| 50 | +Using the manifest file: |
60 | 51 | ```kubectl pg delete -f acid-minimal-cluster.yaml```
|
61 | 52 |
|
62 |
| -### To delete existing cluster using cluster name |
63 |
| - |
| 53 | +Or by specifying the cluster name: |
64 | 54 | ```kubectl pg delete acid-minimal-cluster```
|
65 | 55 |
|
66 |
| ---namespace or -n flag to specify namespace if cluster is in other namespace. |
67 |
| - |
| 56 | +Use `--namespace` or `-n` flag if your cluster is in a different namespace to where your current context is pointing to: |
68 | 57 | ```kubectl pg delete acid-minimal-cluster -n namespace01```
|
69 | 58 |
|
70 |
| -### To list postgres resources for the current namespace |
| 59 | +## Adding manifest roles to an existing cluster |
71 | 60 |
|
72 |
| -```kubectl pg list``` |
| 61 | +```kubectl pg add-user USER01 -p CREATEDB,LOGIN -c acid-minimal-cluster``` |
73 | 62 |
|
74 |
| -### To list postgres resources across namespaces |
| 63 | +Privileges can only be [SUPERUSER, REPLICATION, INHERIT, LOGIN, NOLOGIN, CREATEROLE, CREATEDB, BYPASSURL] |
| 64 | +Note: By default, a LOGIN user is created (unless NOLOGIN is specified). |
75 | 65 |
|
76 |
| -```kubectl pg list all``` |
| 66 | +## Adding databases to an existing cluster |
77 | 67 |
|
78 |
| -### To add-user and it's roles to an existing pg cluster |
| 68 | +You have to specify an owner of the new database and this role must already exist in the cluster: |
| 69 | +```kubectl pg add-db DB01 -o OWNER01 -c acid-minimal-cluster``` |
79 | 70 |
|
80 |
| -```kubectl pg add-user USER01 -p CREATEDB,LOGIN -c acid-minimal-cluster``` |
| 71 | +## Extend the volume of an existing pg cluster |
81 | 72 |
|
82 |
| -Privileges can only be [SUPERUSER, REPLICATION, INHERIT, LOGIN, NOLOGIN, CREATEROLE, CREATEDB, BYPASSURL] |
| 73 | +```kubectl pg ext-volume 2Gi -c acid-minimal-cluster``` |
83 | 74 |
|
84 |
| -Note: A login user is created by default unless NOLOGIN is specified, in which case the operator creates a role. |
| 75 | +## Print the version of Postgres Operator and kubectl pg plugin |
85 | 76 |
|
86 |
| -### To add-db and it's owner to an existing pg cluster |
| 77 | +```kubectl pg version``` |
87 | 78 |
|
88 |
| -```kubectl pg add-db DB01 -o OWNER01 -c acid-minimal-cluster``` |
| 79 | +## Connect to the shell of a postgres pod |
89 | 80 |
|
90 |
| -### To extend volume for an existing pg cluster |
| 81 | +Connect to the master pod: |
| 82 | +```kubectl pg connect -c CLUSTER -m``` |
91 | 83 |
|
92 |
| -```kubectl pg ext-volume 2Gi -c acid-minimal-cluster``` |
| 84 | +Connect to a random replica pod: |
| 85 | +```kubectl pg connect -c CLUSTER``` |
93 | 86 |
|
94 |
| -### To find the version of postgres operator and kubectl plugin |
| 87 | +Connect to a certain replica pod: |
| 88 | +```kubectl pg connect -c CLUSTER -r 0``` |
95 | 89 |
|
96 |
| -```kubectl pg version (optional -n NAMESPACE allows to know specific to a namespace)``` |
| 90 | +## Connect to a database via psql |
97 | 91 |
|
98 |
| -### To connect to the shell of a postgres pod |
| 92 | +Adding the `-p` flag allows you to directly connect to a given database with the psql client. |
| 93 | +With `-u` you specify the user. If left out the name of the current OS user is taken. |
| 94 | +`-d` lets you specify the database. If no database is specified, it will be the same as the user name. |
99 | 95 |
|
100 |
| -```kubectl pg connect -c CLUSTER``` #This connects to a random pod |
101 |
| -```kubectl pg connect -c CLUSTER -m``` #This connects the master |
102 |
| -```kubectl pg connect -c CLUSTER -r 0``` #This connects to the desired replica |
| 96 | +Connect to `app_db` database on the master with role `app_user`: |
| 97 | +```kubectl pg connect -c CLUSTER -m -p -u app_user -d app_db``` |
103 | 98 |
|
104 |
| -### To connect to the psql prompt |
| 99 | +Connect to the `postgres` database on a random replica with role `postgres`: |
| 100 | +```kubectl pg connect -c CLUSTER -p -u postgres``` |
105 | 101 |
|
106 |
| -```kubectl pg connect -c CLUSTER -p -u username``` #This connects to a random pod. Not master |
107 |
| -```kubectl pg connect -c CLUSTER -m -p -u username``` #This connects the master |
108 |
| -```kubectl pg connect -c CLUSTER -r 0 -p -u username``` #This connects to the desired replica |
| 102 | +Connect to a certain replica assuming name of OS user, database role and name are all the same: |
| 103 | +```kubectl pg connect -c CLUSTER -r 0 -p``` |
109 | 104 |
|
110 |
| -Note: -p represents psql prompt |
111 | 105 |
|
112 |
| -### To get the logs of postgres operator |
| 106 | +## Access Postgres Operator logs |
113 | 107 |
|
114 | 108 | ```kubectl pg logs -o```
|
115 | 109 |
|
116 |
| -### To get the logs of the postgres cluster |
| 110 | +## Access Patroni logs of different database pods |
| 111 | + |
| 112 | +Fetch logs of master: |
| 113 | +```kubectl pg logs -c CLUSTER -m``` |
| 114 | + |
| 115 | +Fetch logs of a random replica pod: |
| 116 | +```kubectl pg logs -c CLUSTER``` |
117 | 117 |
|
118 |
| -```kubectl pg logs -c CLUSTER``` #Fetches the logs of a random pod. Not master |
119 |
| -```kubectl pg logs -c CLUSTER -m``` #Fetches the logs of master |
120 |
| -```kubectl pg logs -c CLUSTER -r 2``` #Fecthes the logs of specified replica |
| 118 | +Fetch logs of specified replica |
| 119 | +```kubectl pg logs -c CLUSTER -r 2``` |
121 | 120 |
|
122 | 121 | ## Development
|
123 | 122 |
|
124 |
| -- When making changes to plugin make sure to change the major or patch version |
125 |
| -of plugin in ```build.sh``` and run ```./build.sh``` |
| 123 | +When making changes to the plugin make sure to change the (major/patch) version of plugin in `build.sh` script and run `./build.sh`. |
| 124 | + |
| 125 | +## Google Summer of Code 2019 |
| 126 | + |
| 127 | +### GSoC Proposal |
| 128 | + |
| 129 | +[kubectl pg proposal](https://docs.google.com/document/d/1-WMy9HkfZ1XnnMbzplMe9rCzKrRMGaMz4owLVXXPb7w/edit) |
| 130 | + |
| 131 | +### Weekly Reports |
| 132 | + |
| 133 | +https://github.com/VineethReddy02/GSoC-Kubectl-Plugin-for-Postgres-Operator-tracker |
| 134 | + |
| 135 | +### Final Project Report |
| 136 | + |
| 137 | +https://gist.github.com/VineethReddy02/159283bd368a710379eaf0f6bd60a40a |
0 commit comments