-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript
199 lines (151 loc) · 4.57 KB
/
script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Interactive command script for pgKubernetes Tutorial
# Please use the following commands to copy-and-paste for
# the exercises.
# where you see $EDITOR, use the editor of your choice
# start minikube, if you haven't already
minikube start
# download containers, if you haven't:
minikube cache add jberkus/simple-patroni
minikube cache add jberkus/spilo-demo
## Manual Deployment ##
# look at the definition file for a simple Patroni
# cluster and get ready to deploy it
$EDITOR patroni/patroni-k8s.yaml
# deploy the cluster
kubectl create -f patroni/patroni-k8s.yaml
# look at the pods
kubectl get pods -L role
# watch the logs
kubectl logs patronidemo-0
# repeat above a few times
# look at the pods again
kubectl get pods -L role
# look at a pod
kubectl describe pod patronidemo-1
# check out the services
kubectl get services
# check out the configmaps
kubectl get configmaps
kubectl describe configmap patronidemo-config
kubectl describe configmap patronidemo-leader
# check out secrets
kubectl get secrets
# trigger a failover
kubectl delete pod patronidemo-0 --force
# watch roles change
kubectl get pods -L role
# repeat above a few times
# check out logs and leader config
kubectl logs patronidemo-1
kubectl describe configmap patronidemo-leader
# feel free to repeat the above a few times
## Postgres Operator ##
# create the operator and its dependencies
kubectl create -f operator/configmap.yaml # configuration
kubectl create -f operator/operator-service-account-rbac.yaml # identity and permissions
kubectl create -f operator/postgres-operator.yaml # deployment
# also look at the above files in your $EDITOR
# poll the crds to see when the operator is created
kubectl get crd
kubectl get pods
# repeat the above until it's done
# look at the cluster definition
$EDITOR operator/minimal-postgres-manifest.yaml
# now deploy a cluster
kubectl create -f operator/minimal-postgres-manifest.yaml
# wait a minute for deployment, then
kubectl get pods -L spilo-role
# do the above a few times
## Connecting ##
# look at pg-shell container
$EDITOR patroni/pg-shell.yaml
# deploy it and log into a shell
kubectl create -f patroni/pg-shell.yaml
kubectl exec -it pg-shell -- bash
# connect to the cluster master
psql -h patronidemo
select pg_is_in_recovery();
create table test ( test text );
\q
# connect to the load-balancing RO connection
psql -h patronidemo-ss
select pg_is_in_recovery();
# you may have to do the above a couple times to get a replica
\d test
\q
# connect to a specific node
exit
kubectl get pods -L role
kubectl exec -it pg-shell -- bash
psql -h patronidemo-1.patronidemo-ss
select pg_is_in_recovery();
\q
exit
# look at patroni configuration
kubectl exec -it patronidemo-0 -- bash
more /home/postgres/patroni.yml
## Patroni REST API ##
# look at JSON output
curl 127.0.0.1:8008/patroni
# use patronictl
patronictl list
patronictl show-config
# patronictl commands
patronictl
# switchover
patronictl switchover
# hit ENTER for the master, then choose a replica
# then select "now" then select "y"
patronictl list
# do the above a few times until all nodes are running
# failover
patronictl failover
# chose a replica, then select "y"
patronictl list
# do the above a few times until the cluster is restored
exit
## Operator Changes ##
# connect to the operator cluster
# this requires psql on your laptop command-line, sorry
# some folks may skip this
./operator/connect-min-cluster
# look at timezone, time, and the list of
# users and databases
show timezone;
select now();
\du
\l
\q
# now change the manifest
$EDITOR operator/add-to-manifest.yaml
# check out the additional user and the new timezone
kubectl apply -f operator/add-to-manifest.yaml
kubectl edit pg spilo-s1
# exit your editor
./operator/connect-min-cluster
# look at timezone, time, and the list of
# users and databases
# these may take a minute or two to change
show timezone;
select now();
\du
\l
\q
## Delete Everything ##
# delete operator cluster
kubectl delete -f operator/minimal-postgres-manifest.yaml
kubectl get pods -L spilo-role
# do the above a few times until all nodes are gone
# delete operator
kubectl delete -f operator/configmap.yaml # configuration
kubectl delete -f operator/operator-service-account-rbac.yaml # identity and permissions
kubectl delete -f operator/postgres-operator.yaml # deployment
# delete manual patroni cluster and shell
kubectl delete -f patroni/patroni_k8s.yaml
kubectl delete -f patroni/pg-shell.yaml
# now look at configmaps, and delete them.
kubectl get configmaps
kubectl delete configmap patronidemo-leader
kubectl delete configmap patronidemo-config
# and shut down
minikube stop