diff --git a/z2/configmap.yaml b/z2/configmap.yaml new file mode 100644 index 0000000..a3b844a --- /dev/null +++ b/z2/configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: db-init + namespace: notes-app +data: + init.sql: | + CREATE TABLE IF NOT EXISTS notes ( + id SERIAL PRIMARY KEY, + content TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); + + INSERT INTO notes (content) VALUES + ('Welcome to the Notes App!'), + ('Add, view, and delete notes using the web interface.'); diff --git a/z2/deployment.yaml b/z2/deployment.yaml new file mode 100644 index 0000000..47a9957 --- /dev/null +++ b/z2/deployment.yaml @@ -0,0 +1,67 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend + namespace: notes-app +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: notes-backend:latest + imagePullPolicy: Never + env: + - name: DATABASE_URL + value: postgresql://appuser:apppassword@db:5432/appdb + ports: + - containerPort: 5000 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend + namespace: notes-app +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: notes-frontend:latest + imagePullPolicy: Never + ports: + - containerPort: 80 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: adminer + namespace: notes-app +spec: + replicas: 1 + selector: + matchLabels: + app: adminer + template: + metadata: + labels: + app: adminer + spec: + containers: + - name: adminer + image: adminer:4 + ports: + - containerPort: 8080 diff --git a/z2/namespace.yaml b/z2/namespace.yaml new file mode 100644 index 0000000..0ba1356 --- /dev/null +++ b/z2/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: notes-app diff --git a/z2/service.yaml b/z2/service.yaml new file mode 100644 index 0000000..1cf6f7a --- /dev/null +++ b/z2/service.yaml @@ -0,0 +1,52 @@ +apiVersion: v1 +kind: Service +metadata: + name: db + namespace: notes-app +spec: + selector: + app: db + ports: + - port: 5432 + targetPort: 5432 + clusterIP: None +--- +apiVersion: v1 +kind: Service +metadata: + name: backend + namespace: notes-app +spec: + selector: + app: backend + ports: + - port: 5000 + targetPort: 5000 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend + namespace: notes-app +spec: + selector: + app: frontend + type: NodePort + ports: + - port: 80 + targetPort: 80 + nodePort: 30080 +--- +apiVersion: v1 +kind: Service +metadata: + name: adminer + namespace: notes-app +spec: + selector: + app: adminer + type: NodePort + ports: + - port: 8080 + targetPort: 8080 + nodePort: 30081 diff --git a/z2/statefulset.yaml b/z2/statefulset.yaml new file mode 100644 index 0000000..7806db2 --- /dev/null +++ b/z2/statefulset.yaml @@ -0,0 +1,66 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: postgres-pv + namespace: notes-app +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteOnce + hostPath: + path: /data/notes-postgres + persistentVolumeReclaimPolicy: Retain +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres-pvc + namespace: notes-app +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: db + namespace: notes-app +spec: + serviceName: db + replicas: 1 + selector: + matchLabels: + app: db + template: + metadata: + labels: + app: db + spec: + containers: + - name: postgres + image: postgres:16-alpine + env: + - name: POSTGRES_DB + value: appdb + - name: POSTGRES_USER + value: appuser + - name: POSTGRES_PASSWORD + value: apppassword + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-storage + mountPath: /var/lib/postgresql/data + - name: init-sql + mountPath: /docker-entrypoint-initdb.d + volumes: + - name: postgres-storage + persistentVolumeClaim: + claimName: postgres-pvc + - name: init-sql + configMap: + name: db-init