item-atlas/deploy/public/base.yaml

153 lines
5.1 KiB
YAML

apiVersion: v1
kind: ConfigMap
metadata:
name: atlas-public-db-init
data:
10-atlas.sh: |
#!/bin/sh
set -eu
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d postgres \
-v inventory="$INVENTORY_PASSWORD" -v intake="$INTAKE_PASSWORD" -v identity="$IDENTITY_PASSWORD" <<'SQL'
CREATE ROLE atlas_inventory LOGIN PASSWORD :'inventory';
CREATE ROLE atlas_intake LOGIN PASSWORD :'intake';
CREATE ROLE atlas_identity LOGIN PASSWORD :'identity';
CREATE DATABASE itematlas_inventory OWNER atlas_inventory;
CREATE DATABASE itematlas_intake OWNER atlas_intake;
CREATE DATABASE itematlas_identity OWNER atlas_identity;
REVOKE CONNECT ON DATABASE itematlas_inventory FROM PUBLIC;
REVOKE CONNECT ON DATABASE itematlas_intake FROM PUBLIC;
REVOKE CONNECT ON DATABASE itematlas_identity FROM PUBLIC;
SQL
---
apiVersion: v1
kind: Service
metadata:
name: atlas-postgres
spec:
selector: {app: atlas-public-postgres}
ports:
- name: pg
port: 5432
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: atlas-postgres
spec:
serviceName: atlas-postgres
replicas: 1
selector:
matchLabels: {app: atlas-public-postgres}
template:
metadata:
labels: {app: atlas-public-postgres}
spec:
automountServiceAccountToken: false
containers:
- name: postgres
image: postgres:17.12
args: ["-c", "shared_buffers=32MB", "-c", "max_connections=45"]
ports:
- {name: pg, containerPort: 5432}
envFrom:
- secretRef: {name: atlas-public-postgres}
resources:
requests: {cpu: 50m, memory: 96Mi}
limits: {cpu: "1", memory: 256Mi}
readinessProbe:
exec:
command: [pg_isready, -h, 127.0.0.1, -U, postgres]
periodSeconds: 5
timeoutSeconds: 3
volumeMounts:
- {name: data, mountPath: /var/lib/postgresql/data}
- {name: init-db, mountPath: /docker-entrypoint-initdb.d, readOnly: true}
volumes:
- name: init-db
configMap: {name: atlas-public-db-init}
volumeClaimTemplates:
- metadata: {name: data}
spec:
accessModes: [ReadWriteOnce]
resources:
requests: {storage: 4Gi}
---
apiVersion: v1
kind: Service
metadata:
name: atlas-keycloak
spec:
selector: {app: atlas-public-keycloak}
ports:
- name: http
port: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: atlas-keycloak
spec:
replicas: 1
strategy: {type: Recreate}
selector:
matchLabels: {app: atlas-public-keycloak}
template:
metadata:
labels: {app: atlas-public-keycloak}
spec:
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1000
seccompProfile: {type: RuntimeDefault}
containers:
- name: keycloak
image: quay.io/keycloak/keycloak:26.8.2
args: [start, --import-realm]
securityContext:
allowPrivilegeEscalation: false
capabilities: {drop: [ALL]}
ports:
- {name: http, containerPort: 8080}
- {name: management, containerPort: 9000}
env:
- {name: KC_DB, value: postgres}
- {name: KC_DB_URL, value: 'jdbc:postgresql://atlas-postgres:5432/itematlas_identity'}
- {name: KC_DB_USERNAME, value: atlas_identity}
- {name: KC_DB_POOL_MAX_SIZE, value: '10'}
- {name: KC_HOSTNAME, value: 'https://api-atlas.tutudog.com/auth'}
- {name: KC_HTTP_RELATIVE_PATH, value: /auth}
- {name: KC_HTTP_MANAGEMENT_RELATIVE_PATH, value: /}
- {name: KC_HTTP_ENABLED, value: 'true'}
- {name: KC_PROXY_HEADERS, value: xforwarded}
- {name: KC_HEALTH_ENABLED, value: 'true'}
- {name: JAVA_OPTS_KC_HEAP, value: '-Xms128m -Xmx384m'}
envFrom:
- secretRef: {name: atlas-public-keycloak}
resources:
requests: {cpu: 125m, memory: 384Mi}
limits: {cpu: '1', memory: 768Mi}
startupProbe:
httpGet: {path: /health/started, port: management}
periodSeconds: 5
failureThreshold: 45
readinessProbe:
httpGet: {path: /health/ready, port: management}
periodSeconds: 5
timeoutSeconds: 3
volumeMounts:
- {name: realm, mountPath: /opt/keycloak/data/import, readOnly: true}
- {name: login-theme, mountPath: /opt/keycloak/themes/jianwu/login, readOnly: true}
volumes:
- name: realm
secret: {secretName: atlas-public-realm}
- name: login-theme
configMap:
name: atlas-public-login-theme
items:
- {key: theme.properties, path: theme.properties}
- {key: messages_zh_CN.properties, path: messages/messages_zh_CN.properties}
- {key: messages_en.properties, path: messages/messages_en.properties}
- {key: jianwu.css, path: resources/css/jianwu.css}
- {key: brand.png, path: resources/img/brand.png}