add create db and table

main
kevinzcf 3 years ago
parent 24cd27b5e4
commit b63d257cb7

@ -1,83 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/instance: statping
app.kubernetes.io/name: statping
app.kubernetes.io/version: v0.90.74
name: statping
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app.kubernetes.io/instance: statping
app.kubernetes.io/name: statping
strategy:
type: Recreate
template:
metadata:
labels:
app.kubernetes.io/instance: statping
app.kubernetes.io/name: statping
spec:
automountServiceAccountToken: true
containers:
- env:
- name: DB_CONN
value: postgres
- name: DB_DATABASE
value: postgres
- name: DB_HOST
value: statping-postgresql
- name: DB_PASS
value: changeme
- name: DB_USER
value: postgres
- name: DESCRIPTION
value: This is a Statping instance deployed as Helm chart
- name: DISABLE_LOGS
value: "false"
- name: NAME
value: Statping Example
- name: POSTGRES_SSLMODE
value: disable
- name: TZ
value: UTC
- name: USE_CDN
value: "false"
- name: VIRTUAL_HOST
- name: VIRTUAL_PORT
value: "8080"
image: statping/statping:v0.90.74
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8080
timeoutSeconds: 1
name: statping
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8080
timeoutSeconds: 1
resources:
startupProbe:
failureThreshold: 30
periodSeconds: 5
successThreshold: 1
tcpSocket:
port: 8080
timeoutSeconds: 1
restartPolicy: Always

@ -5,11 +5,18 @@ metadata:
data: data:
init.sh: | init.sh: |
#!/bin/bash #!/bin/bash
PGPASSWORD=YOUR_PASSWORD psql -v ON_ERROR_STOP=1 -h statping-postgres -p 5432 -U statping --dbname "statping" -f /init.d/init.sql if psql -p 5432 -l | grep statping
init.sql: | then
echo 'DATABASE EXIST'
else
psql -p 5432 -c 'CREATE DATABASE statping'
psql -v ON_ERROR_STOP=1 -p 5432 -d statping -f /init.d/init.sql
fi
psql -v ON_ERROR_STOP=1 -p 5432 -d statping -f /init.d/data.sql
data.sql: |
TRUNCATE core; TRUNCATE core;
INSERT INTO "core" ("name", "description", "config", "api_secret", "style", "footer", "domain", "version", "language", "migration_id", "use_cdn", "allow_reports", "created_at", "updated_at", "oauth_providers", "gh_client_id", "gh_client_secret", "gh_users", "gh_orgs", "google_client_id", "google_client_secret", "google_users", "slack_client_id", "slack_client_secret", "slack_team", "slack_users", "custom_name", "custom_client_id", "custom_client_secret", "custom_endpoint_auth", "custom_endpoint_token", "custom_scopes", "custom_open_id") VALUES INSERT INTO "core" ("name", "description", "config", "api_secret", "style", "footer", "domain", "version", "language", "migration_id", "use_cdn", "allow_reports", "created_at", "updated_at", "oauth_providers", "gh_client_id", "gh_client_secret", "gh_users", "gh_orgs", "google_client_id", "google_client_secret", "google_users", "slack_client_id", "slack_client_secret", "slack_team", "slack_users", "custom_name", "custom_client_id", "custom_client_secret", "custom_endpoint_auth", "custom_endpoint_token", "custom_scopes", "custom_open_id") VALUES
('demo status', 'This status page has sample data included', '', 'Siwo6GTDxM2wwl65K4kHKgu9QgmS7n6Q', '', '', 'http://localhost:8080', '0.90.74', 'en', 1674599079, 'f', 'f', '2023-01-24 22:24:39.291738+00', '2023-01-24 22:43:59.697317+00', 'local', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', NULL); ('demo 3 status', 'This status page has sample data included', '', 'Siwo6GTDxM2wwl65K4kHKgu9QgmS7n6Q', '', '', 'http://localhost:8080', '0.90.74', 'en', 1674599079, 'f', 'f', '2023-01-24 22:24:39.291738+00', '2023-01-24 22:43:59.697317+00', 'local', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', NULL);
TRUNCATE groups; TRUNCATE groups;
INSERT INTO "groups" ("id", "name", "public", "order_id", "created_at", "updated_at") VALUES INSERT INTO "groups" ("id", "name", "public", "order_id", "created_at", "updated_at") VALUES
@ -23,3 +30,100 @@ data:
TRUNCATE users; TRUNCATE users;
INSERT INTO "users" ("id", "username", "password", "email", "api_key", "scopes", "administrator", "created_at", "updated_at") VALUES INSERT INTO "users" ("id", "username", "password", "email", "api_key", "scopes", "administrator", "created_at", "updated_at") VALUES
(1, 'mystatping', '$2a$14$r7n8uEuWgRegyu9Efa5mwuyazFQSejltE/xuJSB0ae6gufPV6O6oa', 'info@admin.com', '7d8b24cebdfaf57b4cd57c3b6fd803c95a5d4f838b4f7d0544842444809e2cf5', 'admin', 't', '2023-01-24 22:24:39.238789+00', '2023-01-24 22:52:19.360722+00'); (1, 'mystatping', '$2a$14$r7n8uEuWgRegyu9Efa5mwuyazFQSejltE/xuJSB0ae6gufPV6O6oa', 'info@admin.com', '7d8b24cebdfaf57b4cd57c3b6fd803c95a5d4f838b4f7d0544842444809e2cf5', 'admin', 't', '2023-01-24 22:24:39.238789+00', '2023-01-24 22:52:19.360722+00');
init.sql: |
CREATE TABLE "core" (
"name" text NOT NULL,
"description" text NOT NULL,
"config" text,
"api_secret" text,
"style" text NOT NULL,
"footer" text,
"domain" text NOT NULL,
"version" text,
"language" text,
"migration_id" bigint,
"use_cdn" boolean DEFAULT false,
"allow_reports" boolean DEFAULT false,
"created_at" timestamptz,
"updated_at" timestamptz,
"oauth_providers" text,
"gh_client_id" text,
"gh_client_secret" text,
"gh_users" text,
"gh_orgs" text,
"google_client_id" text,
"google_client_secret" text,
"google_users" text,
"slack_client_id" text,
"slack_client_secret" text,
"slack_team" text,
"slack_users" text,
"custom_name" text,
"custom_client_id" text,
"custom_client_secret" text,
"custom_endpoint_auth" text,
"custom_endpoint_token" text,
"custom_scopes" text,
"custom_open_id" boolean
) WITH (oids = false);
CREATE SEQUENCE groups_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;
CREATE TABLE "groups" (
"id" bigint DEFAULT nextval('groups_id_seq') NOT NULL,
"name" text,
"public" boolean DEFAULT true,
"order_id" integer DEFAULT '0',
"created_at" timestamptz,
"updated_at" timestamptz,
CONSTRAINT "groups_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
CREATE SEQUENCE services_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;
CREATE TABLE "services" (
"id" bigint DEFAULT nextval('services_id_seq') NOT NULL,
"name" text,
"domain" text,
"expected" text,
"expected_status" integer DEFAULT '200',
"check_interval" integer DEFAULT '30',
"check_type" text,
"method" text,
"post_data" text,
"port" integer NOT NULL,
"timeout" integer DEFAULT '30',
"order_id" integer DEFAULT '0',
"verify_ssl" boolean DEFAULT false,
"grpc_health_check" boolean DEFAULT false,
"public" boolean DEFAULT true,
"group_id" integer DEFAULT '0',
"tls_cert" text,
"tls_cert_key" text,
"tls_cert_root" text,
"headers" text,
"permalink" text,
"redirect" boolean DEFAULT false,
"created_at" timestamptz,
"updated_at" timestamptz,
"notify_after" bigint,
"allow_notifications" boolean DEFAULT true,
"notify_all_changes" boolean DEFAULT true,
CONSTRAINT "services_pkey" PRIMARY KEY ("id")
) WITH (oids = false);
CREATE SEQUENCE users_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;
CREATE TABLE "users" (
"id" bigint DEFAULT nextval('users_id_seq') NOT NULL,
"username" character varying(100),
"password" text,
"email" character varying(100),
"api_key" text,
"scopes" text,
"administrator" boolean,
"created_at" timestamptz,
"updated_at" timestamptz,
CONSTRAINT "users_pkey" PRIMARY KEY ("id"),
CONSTRAINT "users_username_key" UNIQUE ("username")
) WITH (oids = false);

@ -1,7 +1,7 @@
secretGenerator: secretGenerator:
- name: postgres-pass - name: postgres-pass
literals: literals:
- password=YOUR_PASSWORD - password=letmein
resources: resources:
- postgres-deployment.yaml - postgres-deployment.yaml
- init-config.yaml - init-config.yaml

@ -15,7 +15,7 @@ spec:
apiVersion: v1 apiVersion: v1
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
metadata: metadata:
name: postgres-pv-claim name: statping-postgres-pv-claim
labels: labels:
app: statping app: statping
spec: spec:
@ -24,6 +24,7 @@ spec:
resources: resources:
requests: requests:
storage: 2Gi storage: 2Gi
volumeMode: "Filesystem"
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@ -49,7 +50,7 @@ spec:
name: postgres name: postgres
env: env:
- name: POSTGRES_USER - name: POSTGRES_USER
value: statping value: postgres
- name: POSTGRES_PASSWORD - name: POSTGRES_PASSWORD
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
@ -64,4 +65,4 @@ spec:
volumes: volumes:
- name: postgres-persistent-storage - name: postgres-persistent-storage
persistentVolumeClaim: persistentVolumeClaim:
claimName: postgres-pv-claim claimName: statping-postgres-pv-claim

@ -1,116 +0,0 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app.kubernetes.io/component: primary
app.kubernetes.io/instance: statping
app.kubernetes.io/name: postgresql
name: statping-postgresql
namespace: default
spec:
podManagementPolicy: OrderedReady
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/component: primary
app.kubernetes.io/instance: statping
app.kubernetes.io/name: postgresql
serviceName: statping-postgresql-hl
template:
metadata:
labels:
app.kubernetes.io/component: primary
app.kubernetes.io/instance: statping
app.kubernetes.io/name: postgresql
name: statping-postgresql
spec:
containers:
- env:
- name: BITNAMI_DEBUG
value: "false"
- name: POSTGRESQL_PORT_NUMBER
value: "5432"
- name: POSTGRESQL_VOLUME_DIR
value: /bitnami/postgresql
- name: PGDATA
value: /bitnami/postgresql/data
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: postgres-password
name: statping-postgresql
- name: POSTGRES_DB
value: postgres
- name: POSTGRESQL_ENABLE_LDAP
value: "no"
- name: POSTGRESQL_ENABLE_TLS
value: "no"
- name: POSTGRESQL_LOG_HOSTNAME
value: "false"
- name: POSTGRESQL_LOG_CONNECTIONS
value: "false"
- name: POSTGRESQL_LOG_DISCONNECTIONS
value: "false"
- name: POSTGRESQL_PGAUDIT_LOG_CATALOG
value: "off"
- name: POSTGRESQL_CLIENT_MIN_MESSAGES
value: error
- name: POSTGRESQL_SHARED_PRELOAD_LIBRARIES
value: pgaudit
image: docker.io/bitnami/postgresql:14.4.0-debian-11-r4
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- /bin/sh
- -c
- exec pg_isready -U "postgres" -d "dbname=postgres" -h 127.0.0.1 -p 5432
failureThreshold: 6
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: postgresql
ports:
- containerPort: 5432
name: tcp-postgresqlh
protocol: TCP
readinessProbe:
exec:
command:
- /bin/sh
- -c
- -e
- |
exec pg_isready -U "postgres" -d "dbname=postgres" -h 127.0.0.1 -p 5432
[ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f /bitnami/postgresql/.initialized ]
failureThreshold: 6
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
volumeMounts:
- mountPath: /dev/shm
name: dshm
- mountPath: /bitnami/postgresql
name: data
restartPolicy: Always
volumes:
- emptyDir:
medium: Memory
name: dshm
updateStrategy:
type: RollingUpdate
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
volumeMode: Filesystem

@ -32,6 +32,23 @@ spec:
app: statping app: statping
tier: frontend tier: frontend
spec: spec:
initContainers:
- image: postgres:15.1
name: postgres-importer
env:
- name: PGHOST
value: statping-postgres
- name: PGUSER
value: postgres
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: postgres-pass
key: password
volumeMounts:
- name: importer
mountPath: /init.d
command: ["/init.d/init.sh"]
containers: containers:
- image: statping/statping - image: statping/statping
name: statping name: statping
@ -43,7 +60,7 @@ spec:
- name: DB_DATABASE - name: DB_DATABASE
value: statping value: statping
- name: DB_USER - name: DB_USER
value: statping value: postgres
- name: DB_PASS - name: DB_PASS
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
@ -52,22 +69,8 @@ spec:
ports: ports:
- containerPort: 8080 - containerPort: 8080
name: statping name: statping
---
apiVersion: v1
kind: Pod
metadata:
name: importer
spec:
containers:
- image: postgres:15.1
name: postgres-importer
volumeMounts:
- name: importer
mountPath: /init.d
command: ["/init.d/init.sh"]
volumes: volumes:
- name: importer - name: importer
configMap: configMap:
name: importer name: importer
defaultMode: 0500 defaultMode: 0500
restartPolicy: Never

Loading…
Cancel
Save