feat: Add PostgreSQL deployment, service, configmap, persistent volume, and persistent volume claim
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: pg-secret
|
||||||
|
namespace: postgresql
|
||||||
|
data:
|
||||||
|
# base64 encoded prism-ip:prism-port:admin:password.
|
||||||
|
# ex:echo -n "10.0.00.000:9440:admin:mypass" | base64
|
||||||
|
key: MTAuNDcuMjQuNjg6OTQ0MDptYWhlc2g6TnV0YW5peEAxMjM0
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: postgres-config
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
data:
|
||||||
|
POSTGRES_DB: postgresdb
|
||||||
|
POSTGRES_USER: admin
|
||||||
|
POSTGRES_PASSWORD: test123
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: postgres
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: postgres:10.1
|
||||||
|
imagePullPolicy: "IfNotPresent"
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: postgres-config
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /var/lib/postgresql/data
|
||||||
|
name: postgredb
|
||||||
|
volumes:
|
||||||
|
- name: postgredb
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: postgres-pv-claim
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- port: 5432
|
||||||
|
selector:
|
||||||
|
app: postgres
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
kind: PersistentVolume
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: postgres-pv-volume
|
||||||
|
labels:
|
||||||
|
type: local
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
storageClassName: manual
|
||||||
|
capacity:
|
||||||
|
storage: 2Gi
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteMany
|
||||||
|
hostPath:
|
||||||
|
path: "/mnt/data"
|
||||||
|
---
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: postgres-pv-claim
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
storageClassName: manual
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteMany
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 2Gi
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: postgresql-pv-claim
|
||||||
|
spec:
|
||||||
|
storageClassName: manual
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 2Gi
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolume
|
||||||
|
metadata:
|
||||||
|
name: postgresql-pv
|
||||||
|
labels:
|
||||||
|
type: local
|
||||||
|
spec:
|
||||||
|
storageClassName: manual
|
||||||
|
capacity:
|
||||||
|
storage: 2Gi
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
hostPath:
|
||||||
|
path: "/mnt/data"
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# postgresql
|
||||||
|
|
||||||
|
```bash
|
||||||
|
create ns postgresql-svc
|
||||||
|
kubectl config set-context --current --namespace=postgresql-svc
|
||||||
|
k apply -f ps-configmap.yaml
|
||||||
|
k apply -f ps-storage.yaml
|
||||||
|
k get pvc
|
||||||
|
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
|
||||||
|
postgres-pv-claim Bound postgres-pv-volume 2Gi RWX manual <unset> 6s
|
||||||
|
|
||||||
|
k apply -f ps-deployment.yaml
|
||||||
|
k apply -f ps-service.yaml
|
||||||
|
|
||||||
|
k get all
|
||||||
|
NAME READY STATUS RESTARTS AGE
|
||||||
|
pod/postgres-84bd99bf45-sf6xq 1/1 Running 0 78s
|
||||||
|
|
||||||
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||||
|
service/postgres NodePort 10.43.158.173 <none> 5432:30795/TCP 12s
|
||||||
|
|
||||||
|
NAME READY UP-TO-DATE AVAILABLE AGE
|
||||||
|
deployment.apps/postgres 1/1 1 1 78s
|
||||||
|
|
||||||
|
NAME DESIRED CURRENT READY AGE
|
||||||
|
replicaset.apps/postgres-84bd99bf45 1 1 1 78s
|
||||||
|
|
||||||
|
kubectl exec -it [pod-name] -- psql -h localhost -U admin --password -p [port] postgresdb
|
||||||
|
|
||||||
|
kubectl exec -it postgres-84bd99bf45-sf6xq -- psql -h localhost -U admin --password -p 5432 postgresdb
|
||||||
|
|
||||||
|
helm repo add bitnami https://charts.bitnami.com/bitnami
|
||||||
|
helm install postgresql bitnami/postgresql --create-namespace -n 'postgresql-svc' --set persistence.existingClaim=postgresql-pv-claim --set volumePermissions.enabled=true
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
io.kompose.service: postgres-data
|
||||||
|
name: postgres-data
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 100Mi
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
kompose.cmd: kompose convert -f services.yml
|
||||||
|
kompose.version: 1.34.0 (HEAD)
|
||||||
|
labels:
|
||||||
|
io.kompose.service: postgres-db
|
||||||
|
traefik.constraint-label: traefik-public
|
||||||
|
traefik.docker.network: traefik-public
|
||||||
|
traefik.enable: "true"
|
||||||
|
traefik.tcp.routers.postgres.entrypoints: postgres-socket
|
||||||
|
traefik.tcp.routers.postgres.rule: HostSNI(`*`)
|
||||||
|
traefik.tcp.routers.postgres.service: postgres_service
|
||||||
|
traefik.tcp.services.postgres_service.loadbalancer.server.port: "5432"
|
||||||
|
name: postgres-db
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
io.kompose.service: postgres-db
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
kompose.cmd: kompose convert -f services.yml
|
||||||
|
kompose.version: 1.34.0 (HEAD)
|
||||||
|
labels:
|
||||||
|
io.kompose.service: postgres-db
|
||||||
|
spec:
|
||||||
|
affinity:
|
||||||
|
nodeAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
nodeSelectorTerms:
|
||||||
|
- matchExpressions:
|
||||||
|
- key: postgres.postgres_data
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- "true"
|
||||||
|
containers:
|
||||||
|
- args:
|
||||||
|
- postgres
|
||||||
|
- -c
|
||||||
|
- log_connections=on
|
||||||
|
env:
|
||||||
|
- name: LANG
|
||||||
|
value: en_US.utf8
|
||||||
|
- name: PGDATA
|
||||||
|
value: /var/lib/postgresql/data
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
- name: TZ
|
||||||
|
value: Asia/Singapore
|
||||||
|
image: postgres
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command:
|
||||||
|
- pg_isready -d ${POSTGRES_DB} -U ${POSTGRES_USER}
|
||||||
|
failureThreshold: 10
|
||||||
|
periodSeconds: 30
|
||||||
|
timeoutSeconds: 10
|
||||||
|
name: postgres-db
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /var/lib/postgresql/data
|
||||||
|
name: postgres-data
|
||||||
|
restartPolicy: Always
|
||||||
|
volumes:
|
||||||
|
- name: postgres-data
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: postgres-data
|
||||||
Reference in New Issue
Block a user