1
0
Fork 0

switch from mariadb to postgres

This commit is contained in:
Massaki Archambault 2021-08-26 12:42:10 -04:00
parent d05812e9d6
commit 0678bbd56d
14 changed files with 48 additions and 125 deletions

8
.postgres/initdb.sql Normal file
View File

@ -0,0 +1,8 @@
CREATE USER gitea WITH PASSWORD 'changeme';
CREATE DATABASE gitea WITH OWNER gitea;
CREATE USER grafana WITH password 'changeme';
CREATE DATABASE grafana WITH OWNER grafana;
CREATE USER nextcloud WITH PASSWORD 'changeme';
CREATE DATABASE nextcloud WITH OWNER nextcloud;

View File

@ -2,5 +2,5 @@
k3d cluster delete local k3d cluster delete local
docker rm -f registry-localhost docker rm -f registry-localhost
docker rm -f mariadb-localhost docker rm -f postgres-localhost
docker rm -f nfs-localhost docker rm -f nfs-localhost

View File

@ -30,26 +30,26 @@ spec:
- name: SSH_DOMAIN - name: SSH_DOMAIN
value: ${GITEA_EXTERNAL_HOST} value: ${GITEA_EXTERNAL_HOST}
- name: DB_TYPE - name: DB_TYPE
value: mysql value: postgres
- name: DB_HOST - name: DB_HOST
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: host key: host
- name: DB_NAME - name: DB_NAME
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: database key: database
- name: DB_USER - name: DB_USER
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: username key: username
- name: DB_PASSWD - name: DB_PASSWD
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: password key: password
ports: ports:
- name: http - name: http

View File

@ -3,11 +3,11 @@ resources:
- ingress.yaml - ingress.yaml
secretGenerator: secretGenerator:
- name: mariadb-credentials-secret - name: postgres-credentials-secret
type: Opaque type: Opaque
behavior: create behavior: create
literals: literals:
- host=mariadb-localhost:3306 - host=172.18.1.2:5432
- database=gitea - database=gitea
- username=gitea - username=gitea
- password=changeme - password=changeme

View File

@ -22,26 +22,26 @@ spec:
- name: GF_AUTH_ANONYMOUS_ORG_ROLE - name: GF_AUTH_ANONYMOUS_ORG_ROLE
value: Admin value: Admin
- name: GF_DATABASE_TYPE - name: GF_DATABASE_TYPE
value: mysql value: postgres
- name: GF_DATABASE_HOST - name: GF_DATABASE_HOST
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: host key: host
- name: GF_DATABASE_NAME - name: GF_DATABASE_NAME
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: database key: database
- name: GF_DATABASE_USER - name: GF_DATABASE_USER
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: username key: username
- name: GF_DATABASE_PASSWORD - name: GF_DATABASE_PASSWORD
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: password key: password
ports: ports:
- name: http - name: http

View File

@ -8,11 +8,11 @@ configMapGenerator:
- datasources.yaml=provision/datasources.yaml - datasources.yaml=provision/datasources.yaml
secretGenerator: secretGenerator:
- name: mariadb-credentials-secret - name: postgres-credentials-secret
type: Opaque type: Opaque
behavior: create behavior: create
literals: literals:
- host=mariadb-localhost:3306 - host=172.18.1.2:5432
- database=grafana - database=grafana
- username=grafana - username=grafana
- password=changeme - password=changeme

View File

@ -1,10 +0,0 @@
resources:
- mariadb-statefulset.yaml
secretGenerator:
- name: mariadb-credentials-secret
type: Opaque
literals:
- database=mariadb
- username=mariadb
- password=replaceme

View File

@ -1,63 +0,0 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mariadb
spec:
selector:
matchLabels:
app: mariadb
serviceName: mariadb
template:
metadata:
labels:
app: mariadb
spec:
containers:
- name: mariadb
image: mariadb:10.5.2
env:
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: mariadb-credentials-secret
key: database
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mariadb-credentials-secret
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb-credentials-secret
key: password
- name: MYSQL_RANDOM_ROOT_PASSWORD
value: "yes"
ports:
- name: mariadb
containerPort: 3306
volumeMounts:
- name: mariadb-pvc
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mariadb-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: v1
kind: Service
metadata:
name: mariadb
labels:
app: mariadb
spec:
selector:
app: mariadb
ports:
- name: mariadb
port: 3306

View File

@ -4,11 +4,11 @@ resources:
- ingress.yaml - ingress.yaml
secretGenerator: secretGenerator:
- name: mariadb-credentials-secret - name: postgres-credentials-secret
type: Opaque type: Opaque
behavior: create behavior: create
literals: literals:
- host=mariadb-localhost:3306 - host=172.18.1.2:5432
- database=nextcloud - database=nextcloud
- username=nextcloud - username=nextcloud
- password=changeme - password=changeme

View File

@ -19,25 +19,25 @@ spec:
env: env:
- name: TRUSTED_PROXIES - name: TRUSTED_PROXIES
value: 10.0.0.0/8 value: 10.0.0.0/8
- name: MYSQL_HOST - name: POSTGRES_HOST
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: host key: host
- name: MYSQL_DATABASE - name: POSTGRES_DATABASE
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: database key: database
- name: MYSQL_USER - name: POSTGRES_USER
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: username key: username
- name: MYSQL_PASSWORD - name: POSTGRES_PASSWORD
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: mariadb-credentials-secret name: postgres-credentials-secret
key: password key: password
ports: ports:
- name: http - name: http

View File

@ -1,6 +1,6 @@
bases: bases:
- ../../bases/gitea - ../../bases/gitea
# - ../../base/mariadb # - ../../base/postgres
resources: resources:
- namespace.yaml - namespace.yaml

View File

@ -1,6 +1,6 @@
bases: bases:
- ../../bases/grafana - ../../bases/grafana
# - ../../base/mariadb # - ../../base/postgres
resources: resources:
- namespace.yaml - namespace.yaml

View File

@ -1,6 +1,6 @@
bases: bases:
- ../../bases/nextcloud - ../../bases/nextcloud
# - ../../base/mariadb # - ../../base/postgres
resources: resources:
- namespace.yaml - namespace.yaml

View File

@ -39,23 +39,26 @@ if ! docker ps -a | grep registry-localhost &>/dev/null; then
docker run -d \ docker run -d \
--name registry-localhost \ --name registry-localhost \
--net "k3d-$cluster_name" \ --net "k3d-$cluster_name" \
--ip 172.18.1.1 \
--volume local_registry:/var/lib/registry \ --volume local_registry:/var/lib/registry \
--restart always \ --restart always \
-p 5000:5000 \ -p 5000:5000 \
registry:2 registry:2
fi fi
# local mariadb database # local postgres database
if ! docker ps -a | grep mariadb-localhost &>/dev/null; then if ! docker ps -a | grep postgres-localhost &>/dev/null; then
docker volume create local_mariadb docker volume create local_postgres
docker run -d \ docker run -d \
--name mariadb-localhost \ --name postgres-localhost \
--net "k3d-$cluster_name" \ --net "k3d-$cluster_name" \
--volume local_mariadb:/var/lib/mysql \ --ip 172.18.1.2 \
--volume local_postgres:/var/lib/postgresql/data \
--volume "$PWD/.postgres/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql:ro" \
--restart always \ --restart always \
--env MYSQL_ROOT_PASSWORD=changeme \ --env POSTGRES_PASSWORD=changeme \
-p 3306:3306 \ -p 5432:5432 \
mariadb:10.5 postgres:9.6
sleep 10 sleep 10
fi fi
@ -65,6 +68,7 @@ if ! docker ps -a | grep nfs-localhost &>/dev/null; then
docker run -d \ docker run -d \
--name nfs-localhost \ --name nfs-localhost \
--net "k3d-$cluster_name" \ --net "k3d-$cluster_name" \
--ip 172.18.1.3 \
--volume nfs_local:/data \ --volume nfs_local:/data \
--volume /lib/modules:/lib/modules:ro \ --volume /lib/modules:/lib/modules:ro \
--restart always \ --restart always \
@ -78,22 +82,6 @@ if ! docker ps -a | grep nfs-localhost &>/dev/null; then
sleep 10 sleep 10
fi fi
docker exec mariadb-localhost mysql -vv -uroot -pchangeme -e "
CREATE DATABASE IF NOT EXISTS gitea;
CREATE USER IF NOT EXISTS 'gitea'@'%' IDENTIFIED BY 'changeme';
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'%';
CREATE DATABASE IF NOT EXISTS grafana;
CREATE USER IF NOT EXISTS 'grafana'@'%' IDENTIFIED BY 'changeme';
GRANT ALL PRIVILEGES ON grafana.* TO 'grafana'@'%';
CREATE DATABASE IF NOT EXISTS nextcloud;
CREATE USER IF NOT EXISTS 'nextcloud'@'%' IDENTIFIED BY 'changeme';
GRANT ALL PRIVILEGES ON grafana.* TO 'nextcloud'@'%';
FLUSH PRIVILEGES;
"
k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null
kubectl apply -f "$auto_deploy_manifest" kubectl apply -f "$auto_deploy_manifest"
kubectl get nodes kubectl get nodes