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

kubernetes deployment #193

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion k8s/helm/PostDock/templates/postgres/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ data:
app.db.database: "{{ .Values.postgres.db.name }}"
app.db.cluster.name: "{{ .Values.postgres.clusterName }}"
app.db.cluster.replication.db: "{{ .Values.postgres.replicationDb.name }}"
app.db.pool.backends: "{{ range $i, $e := .Values.postgres.nodes }}{{ if $i }},{{ end }}{{ $i }}:{{ $.Values.postDock.name }}-db-node-{{ $i }}.{{ $.Values.postDock.name }}-db::::{{ end }}"
app.db.pool.backends: "{{ range $i, $e := .Values.postgres.nodes }}{{ if $i }},{{ end }}{{ $i }}:{{ $.Values.postDock.name }}-db-node-{{ $i }}.{{ $.Values.postDock.name }}-db.{{ $.Values.postDock.k8sFullDomainName }}::::{{ end }}"
3 changes: 2 additions & 1 deletion k8s/helm/PostDock/templates/postgres/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
labels:
name: database
system: {{ .Values.postDock.name }}
app: {{ .Values.postDock.name }}
spec:
clusterIP: None
ports:
Expand All @@ -13,4 +14,4 @@ spec:
selector:
name: database
system: {{ .Values.postDock.name }}


10 changes: 5 additions & 5 deletions k8s/helm/PostDock/templates/postgres/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
containers:
- name: db-node
image: {{ .Values.postgres.image }}:{{ .Values.postgres.tag }}
imagePullPolicy: Always
livenessProbe:
exec:
command: ['bash', '-c', '/usr/local/bin/cluster/healthcheck/is_major_master.sh']
Expand All @@ -28,7 +29,6 @@ spec:
periodSeconds: 30
successThreshold: 1
failureThreshold: 3
imagePullPolicy: Always
{{ if .Values.postgres.resources }}
resources:
{{ toYaml .Values.postgres.resources | indent 12 }}
Expand All @@ -42,13 +42,13 @@ spec:
fieldRef:
fieldPath: metadata.name
- name: "REPLICATION_PRIMARY_HOST"
value: "{{ .Values.postDock.name }}-db-node-0.{{ .Values.postDock.name }}-db"
value: "{{ .Values.postDock.name }}-db-node-0.{{ .Values.postDock.name }}-db.{{ .Values.postDock.k8sFullDomainName }}"
- name: "PARTNER_NODES"
value: "{{ range $i, $e := .Values.postgres.nodes }}{{ if $i }},{{ end }}{{ $.Values.postDock.name }}-db-node-{{ $i }}.{{ $.Values.postDock.name }}-db{{ end }}"
value: "{{ range $i, $e := .Values.postgres.nodes }}{{ if $i }},{{ end }}{{ $.Values.postDock.name }}-db-node-{{ $i }}.{{ $.Values.postDock.name }}-db.{{ $.Values.postDock.k8sFullDomainName }}{{ end }}"
- name: "NODE_NAME"
value: "$(MY_POD_NAME)"
- name: "CLUSTER_NODE_NETWORK_NAME"
value: "$(MY_POD_NAME).{{ .Values.postDock.name }}-db"
value: "$(MY_POD_NAME).{{ .Values.postDock.name }}-db.{{ .Values.postDock.k8sFullDomainName }}"
- name: "POSTGRES_DB"
valueFrom:
configMapKeyRef:
Expand Down Expand Up @@ -92,4 +92,4 @@ spec:
volumeClaimTemplates:
- metadata:
name: db-data


13 changes: 10 additions & 3 deletions k8s/helm/PostDock/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
postDock:
# setup.name - name for your setup, unique name allows you to have many releases of postdock in the same namespace
name: mysystem
# kubernetes namespace
k8sNamespace: default
# kubernetes domain (set when k8s cluster has been created 'kubeadm init --service-dns-domain XXXX')
k8sDnsDomainName: myk8scluster.local
# kubernetes full domain name
# concat does not work k8sFullDomainName: "{{ .Values.postDock.k8sNamespace }}.svc.{{ .Values.postDock.k8sDnsDomainName }}"
k8sFullDomainName: default.svc.myk8scluster.local
# postgres - postgres component related settings
postgres:
# postgres.image - is the image to use for postgres component
Expand All @@ -13,8 +20,8 @@ postgres:
tag: latest-postgres10-repmgr32
# postgres.replicas - number of nodes in you postgres cluster
replicas: 3
# postgres.clusterName - cluster name inside PostDock
clusterName: mysystem_cluster
# postgres.clusterName - cluster name inside PostDock (no '_' or '-' allowed)
clusterName: mysystemCluster
# postgres.db - database and credentials for it which will be created on PostDock start
db:
# postgres.db.name - database name
Expand Down Expand Up @@ -104,4 +111,4 @@ barman:
# barman.volume - same as {postgres.nodes.[*].volume}
volume:
size: 200Gi
recalimPolicy: Delete
recalimPolicy: Delete
9 changes: 4 additions & 5 deletions make/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ function template {
}

# Getting templates processor
if [ ! -f "tmp/mo" ]; then
if [ ! -f "/tmp/mo" ]; then
echo "> Getting Mustache template processor Mo"
mkdir tmp
curl -sSL https://git.io/get-mo > tmp/mo
chmod +x tmp/mo
curl -sSLk https://git.io/get-mo > /tmp/mo
chmod +x /tmp/mo
fi

. ./tmp/mo
. /tmp/mo
for SYSTEM_PATH in `find ./make/* -maxdepth 1 -type d`; do
SYSTEM=`basename $SYSTEM_PATH`
if [ "$SYSTEM_TO_MAKE" != "" ] && [ "$SYSTEM_TO_MAKE" != "$SYSTEM" ]; then
Expand Down
8 changes: 4 additions & 4 deletions src/Pgpool-3.7-Postgres-10.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ RUN groupadd -r postgres --gid=999 && useradd -r -g postgres -d /home/postgres
ARG GOSU_VERSION=1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& wget --no-check-certificate -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget --no-check-certificate -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
Expand All @@ -32,7 +32,7 @@ RUN apt-get install -y postgresql-client-10

RUN apt-get install -y libpgpool0=3.7\* pgpool2=3.7\*

RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
RUN wget --no-check-certificate https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

COPY ./ssh /home/postgres/.ssh
Expand Down
12 changes: 6 additions & 6 deletions src/includes/dockerfile/Pgpool-3.3-3.7.part.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ RUN groupadd -r postgres --gid=999 && useradd -r -g postgres -d /home/postgres
ARG GOSU_VERSION=1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& wget --no-check-certificate -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget --no-check-certificate -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
Expand All @@ -26,19 +26,19 @@ RUN apt-get install -y libffi-dev libssl-dev openssh-server
RUN apt-get install -y postgresql-client-{{ PG_CLIENT_VERSION }}
{{ /PG_CLIENT_LATEST }}{{ ^PG_CLIENT_LATEST }}
RUN TEMP_DEB="$(mktemp)" && \
wget -O "$TEMP_DEB" "http://atalia.postgresql.org/morgue/p/postgresql-{{ PG_CLIENT_VERSION }}/postgresql-client-{{ PG_CLIENT_VERSION }}_{{ PG_CLIENT_PACKAGE_VERSION }}_amd64.deb" && \
wget --no-check-certificate -O "$TEMP_DEB" "http://atalia.postgresql.org/morgue/p/postgresql-{{ PG_CLIENT_VERSION }}/postgresql-client-{{ PG_CLIENT_VERSION }}_{{ PG_CLIENT_PACKAGE_VERSION }}_amd64.deb" && \
(dpkg -i "$TEMP_DEB" || apt-get install -y -f) && rm -f "$TEMP_DEB"
{{ /PG_CLIENT_LATEST }}

{{ #PGPOOL_LATEST }}
RUN apt-get install -y libpgpool0={{ PGPOOL_VERSION }}\* pgpool2={{ PGPOOL_VERSION }}\*
{{ /PGPOOL_LATEST }}{{ ^PGPOOL_LATEST }}
RUN TEMP_DEB="$(mktemp)" && \
wget -O "$TEMP_DEB" "http://atalia.postgresql.org/morgue/p/pgpool2/pgpool2_{{ PGPOOL_PACKAGE_VERSION }}_amd64.deb" && \
wget --no-check-certificate -O "$TEMP_DEB" "http://atalia.postgresql.org/morgue/p/pgpool2/pgpool2_{{ PGPOOL_PACKAGE_VERSION }}_amd64.deb" && \
(dpkg -i "$TEMP_DEB" || apt-get install -y -f) && rm -f "$TEMP_DEB"
{{ /PGPOOL_LATEST }}

RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
RUN wget --no-check-certificate https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

COPY ./ssh /home/postgres/.ssh
Expand Down
2 changes: 2 additions & 0 deletions src/pgsql/bin/functions/postgres_configure
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ do
done

chown postgres:postgres $CONFIG_FILE

echo "<<< DONE Configuring $CONFIG_FILE"
8 changes: 6 additions & 2 deletions src/pgsql/bin/postgres/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ source /usr/local/bin/cluster/repmgr/configure.sh

echo ">>> Sending in background postgres start..."
if [[ "$CURRENT_REPLICATION_PRIMARY_HOST" == "" ]]; then
cp -f /usr/local/bin/cluster/postgres/primary/entrypoint.sh /docker-entrypoint-initdb.d/
cp -f /usr/local/bin/cluster/postgres/primary/entrypoint.sh /primary-entrypoint.sh
/docker-entrypoint.sh postgres &
sleep 20s
echo ">>> Starting primary postgres image entrypoint process..."
gosu postgres /primary-entrypoint.sh
echo "<<< DONE primary postgres image entrypoint process"
else
/usr/local/bin/cluster/postgres/standby/entrypoint.sh
fi

/usr/local/bin/cluster/repmgr/start.sh
/usr/local/bin/cluster/repmgr/start.sh
11 changes: 9 additions & 2 deletions src/pgsql/bin/postgres/primary/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env bash
set -e

echo ">>> STARTING primary postgres entrypoint..."

FORCE_RECONFIGURE=1 postgres_configure

echo ">>> Creating replication user '$REPLICATION_USER'"
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "CREATE ROLE $REPLICATION_USER WITH REPLICATION PASSWORD '$REPLICATION_PASSWORD' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -tc "SELECT 1 FROM pg_user WHERE usename='$REPLICATION_USER'" \
| grep -q 1 || psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "CREATE ROLE $REPLICATION_USER WITH REPLICATION PASSWORD '$REPLICATION_PASSWORD' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"

echo ">>> Creating replication db '$REPLICATION_DB'"
createdb $REPLICATION_DB -O $REPLICATION_USER
psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -c "DROP DATABASE IF EXISTS $REPLICATION_DB;"
createdb -U "${POSTGRES_USER}" "${REPLICATION_DB}" -O "${REPLICATION_USER}"

#TODO: make it more flexible, allow set of IPs
# Why db_name='replication' - https://dba.stackexchange.com/questions/82351/postgresql-doesnt-accept-replication-connection
echo "host replication $REPLICATION_USER 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf

echo "<<< DONE primary postgres entrypoint!"
2 changes: 2 additions & 0 deletions src/pgsql/bin/postgres/standby/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -e

echo ">>> Starting standby entrypoint process..."

wait_upstream_postgres

if [ `ls $PGDATA/ | wc -l` != "0" ]; then
Expand Down
3 changes: 3 additions & 0 deletions src/pgsql/extensions/bin/extensions/pgrouting/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

apt-get install -y postgresql-$PG_MAJOR-pgrouting
2 changes: 1 addition & 1 deletion src/pgsql/extensions/bin/extensions/postgis/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

POSTGIS_VERSION=2.4
apt-get install -y postgresql-$PG_MAJOR-postgis-$POSTGIS_VERSION
apt-get install -y postgresql-$PG_MAJOR-postgis-$POSTGIS_VERSION postgresql-$PG_MAJOR-postgis-$POSTGIS_VERSION-scripts