commit 517951a0c7a7879455af5e0441662bc3a788d278 Author: Vitor Hideyoshi Date: Mon May 9 22:09:01 2022 -0300 First Version of Infra-Kubernetes for Hideyoshi.com Implements Postgres Database and SpringBoot docker diff --git a/README.md b/README.md new file mode 100644 index 0000000..7d5151f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# infra-kubernetes diff --git a/backend/backend-config.yaml b/backend/backend-config.yaml new file mode 100644 index 0000000..e1287db --- /dev/null +++ b/backend/backend-config.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: backend-config +data: + backend-url: backend-service diff --git a/backend/backend.yaml b/backend/backend.yaml new file mode 100644 index 0000000..547ceb2 --- /dev/null +++ b/backend/backend.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend + labels: + app: backend +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: yoshiunfriendly/backend-hideyoshi.com + ports: + - containerPort: 8070 + env: + - name: FRONT_END_PATH + valueFrom: + configMapKeyRef: + name: frontend-config + key: frontend-url + + - name: FRONT_END_CONNECTION_TYPE + valueFrom: + configMapKeyRef: + name: frontend-config + key: frontend-type + + - name: PORT + value: "8070" + + - name: POSTGRES_URL + valueFrom: + configMapKeyRef: + name: postgres-config + key: postgres-url + + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: postgres-secret + key: POSTGRES_DB + + - name: DATABASE_URL + value: "postgresql://$(POSTGRES_URL):5432/$(POSTGRES_DB)" + + - name: DATABASE_USER + valueFrom: + secretKeyRef: + name: postgres-secret + key: POSTGRES_USER + + - name: DATABASE_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-secret + key: POSTGRES_PASSWORD + +--- +apiVersion: v1 +kind: Service +metadata: + name: backend-service +spec: + ports: + - protocol: TCP + port: 8070 + targetPort: 8070 + selector: + app: backend \ No newline at end of file diff --git a/postgres/postgres-config.yaml b/postgres/postgres-config.yaml new file mode 100644 index 0000000..8cd0ab2 --- /dev/null +++ b/postgres/postgres-config.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-config +data: + postgres-url: postgres-service \ No newline at end of file diff --git a/postgres/postgres-secret.yaml b/postgres/postgres-secret.yaml new file mode 100644 index 0000000..3e401eb --- /dev/null +++ b/postgres/postgres-secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: postgres-secret +type: Opaque +data: + POSTGRES_USER: cG9zdGdyZXM= + POSTGRES_PASSWORD: cG9zdGdyZXM= + POSTGRES_DB: cG9ydGZvbGlv diff --git a/postgres/postgres-storage.yaml b/postgres/postgres-storage.yaml new file mode 100644 index 0000000..36a8db2 --- /dev/null +++ b/postgres/postgres-storage.yaml @@ -0,0 +1,29 @@ +kind: PersistentVolume +apiVersion: v1 +metadata: + name: postgres-pv-volume + labels: + type: local + app: postgres +spec: + storageClassName: manual + capacity: + storage: 5Gi + 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: 5Gi \ No newline at end of file diff --git a/postgres/postgres.yaml b/postgres/postgres.yaml new file mode 100644 index 0000000..d11f6da --- /dev/null +++ b/postgres/postgres.yaml @@ -0,0 +1,42 @@ +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 + imagePullPolicy: "IfNotPresent" + ports: + - containerPort: 5432 + envFrom: + - secretRef: + name: postgres-secret + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgredb + volumes: + - name: postgredb + persistentVolumeClaim: + claimName: postgres-pv-claim +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres-service +spec: + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 + selector: + app: postgres