From a3026bddbb3ee267d64f3362554088a80e9398c7 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Thu, 7 Nov 2024 17:33:58 +0300 Subject: [PATCH] Add Kubernetes support --- k8s/db.yml | 73 +++++++++++++++++++++++++++++++++++++++++++++++ k8s/petclinic.yml | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 k8s/db.yml create mode 100644 k8s/petclinic.yml diff --git a/k8s/db.yml b/k8s/db.yml new file mode 100644 index 00000000000..c230ddba2b1 --- /dev/null +++ b/k8s/db.yml @@ -0,0 +1,73 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: demo-db +type: servicebinding.io/postgresql +stringData: + type: "postgresql" + provider: "postgresql" + host: "demo-db" + port: "5432" + database: "petclinic" + username: "user" + password: "pass" + +--- +apiVersion: v1 +kind: Service +metadata: + name: demo-db +spec: + ports: + - port: 5432 + selector: + app: demo-db + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: demo-db + labels: + app: demo-db +spec: + selector: + matchLabels: + app: demo-db + template: + metadata: + labels: + app: demo-db + spec: + containers: + - image: postgres:17 + name: postgresql + env: + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: demo-db + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: demo-db + key: password + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: demo-db + key: database + ports: + - containerPort: 5432 + name: postgresql + livenessProbe: + tcpSocket: + port: postgresql + readinessProbe: + tcpSocket: + port: postgresql + startupProbe: + tcpSocket: + port: postgresql diff --git a/k8s/petclinic.yml b/k8s/petclinic.yml new file mode 100644 index 00000000000..a5677cd06a6 --- /dev/null +++ b/k8s/petclinic.yml @@ -0,0 +1,64 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: petclinic +spec: + type: NodePort + ports: + - port: 80 + targetPort: 8080 + selector: + app: petclinic + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: petclinic + labels: + app: petclinic +spec: + replicas: 1 + selector: + matchLabels: + app: petclinic + template: + metadata: + labels: + app: petclinic + spec: + containers: + - name: workload + image: dsyer/petclinic + env: + - name: SPRING_PROFILES_ACTIVE + value: postgres + - name: SERVICE_BINDING_ROOT + value: /bindings + - name: SPRING_APPLICATION_JSON + value: | + { + "management.endpoint.health.probes.add-additional-paths": true + } + ports: + - name: http + containerPort: 8080 + livenessProbe: + httpGet: + path: /livez + port: http + readinessProbe: + httpGet: + path: /readyz + port: http + volumeMounts: + - mountPath: /bindings/secret + name: binding + readOnly: true + volumes: + - name: binding + projected: + sources: + - secret: + name: demo-db