From 1f0b71fab11efa8a85e3fce013f2eeb5276ff275 Mon Sep 17 00:00:00 2001 From: Teck Meng Date: Sun, 11 Aug 2024 22:17:25 +0800 Subject: [PATCH] chore: Add Kubernetes resources for API and client deployments, services, and ingress --- cluster/test/api-cluster-ip-service.yaml | 11 ++++++++ cluster/test/api-deployment.yaml | 27 +++++++++++++++++++ .../test/client-cluster-ip-deployment.yaml | 11 ++++++++ cluster/test/client-deployment.yaml | 20 ++++++++++++++ .../database-persistent-volume-claim.yaml | 10 +++++++ cluster/test/ingress-service.yaml | 19 +++++++++++++ cluster/test/postgres-cluster-ip-service.yaml | 11 ++++++++ cluster/test/readme.md | 12 +++++++++ 8 files changed, 121 insertions(+) create mode 100644 cluster/test/api-cluster-ip-service.yaml create mode 100644 cluster/test/api-deployment.yaml create mode 100644 cluster/test/client-cluster-ip-deployment.yaml create mode 100644 cluster/test/client-deployment.yaml create mode 100644 cluster/test/database-persistent-volume-claim.yaml create mode 100644 cluster/test/ingress-service.yaml create mode 100644 cluster/test/postgres-cluster-ip-service.yaml create mode 100644 cluster/test/readme.md diff --git a/cluster/test/api-cluster-ip-service.yaml b/cluster/test/api-cluster-ip-service.yaml new file mode 100644 index 0000000..f37df81 --- /dev/null +++ b/cluster/test/api-cluster-ip-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: api-cluster-ip-service +spec: + type: ClusterIP + selector: + component: api + ports: + - port: 8080 + targetPort: 8080 \ No newline at end of file diff --git a/cluster/test/api-deployment.yaml b/cluster/test/api-deployment.yaml new file mode 100644 index 0000000..ad4694f --- /dev/null +++ b/cluster/test/api-deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres-deployment +spec: + replicas: 1 + selector: + matchLabels: + component: postgres + template: + metadata: + labels: + component: postgres + spec: + volumes: + - name: postgres-storage + persistentVolumeClaim: + claimName: database-persistent-volume-claim + containers: + - name: postgres + image: postgres + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-storage + mountPath: /var/lib/postgresql/data + subPath: postgres \ No newline at end of file diff --git a/cluster/test/client-cluster-ip-deployment.yaml b/cluster/test/client-cluster-ip-deployment.yaml new file mode 100644 index 0000000..0688e32 --- /dev/null +++ b/cluster/test/client-cluster-ip-deployment.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: client-cluster-ip-service +spec: + type: ClusterIP + selector: + component: client + ports: + - port: 3000 + targetPort: 3000 \ No newline at end of file diff --git a/cluster/test/client-deployment.yaml b/cluster/test/client-deployment.yaml new file mode 100644 index 0000000..a4dca02 --- /dev/null +++ b/cluster/test/client-deployment.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: client-deployment +spec: + replicas: 1 + selector: + matchLabels: + component: client + template: + metadata: + labels: + component: client + spec: + containers: + - name: client + image: uxioandrade/tutorial-client + ports: + - containerPort: 3000 + diff --git a/cluster/test/database-persistent-volume-claim.yaml b/cluster/test/database-persistent-volume-claim.yaml new file mode 100644 index 0000000..1eb71ba --- /dev/null +++ b/cluster/test/database-persistent-volume-claim.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: database-persistent-volume-claim +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi \ No newline at end of file diff --git a/cluster/test/ingress-service.yaml b/cluster/test/ingress-service.yaml new file mode 100644 index 0000000..7fde6e9 --- /dev/null +++ b/cluster/test/ingress-service.yaml @@ -0,0 +1,19 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: ingress-service + annotations: + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/rewrite-target: /$1 +spec: + rules: + - http: + paths: + - path: /?(.*) + backend: + serviceName: client-cluster-ip-service + servicePort: 3000 + - path: /api/?(.*) + backend: + serviceName: api-cluster-ip-service + servicePort: 8080 \ No newline at end of file diff --git a/cluster/test/postgres-cluster-ip-service.yaml b/cluster/test/postgres-cluster-ip-service.yaml new file mode 100644 index 0000000..3313c92 --- /dev/null +++ b/cluster/test/postgres-cluster-ip-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-cluster-ip-service +spec: + type: ClusterIP + selector: + component: postgres + ports: + - port: 5432 + targetPort: 5432 \ No newline at end of file diff --git a/cluster/test/readme.md b/cluster/test/readme.md new file mode 100644 index 0000000..637258e --- /dev/null +++ b/cluster/test/readme.md @@ -0,0 +1,12 @@ +# test stack + +```bash +k create ns test +kubectl config set-context --current --namespace=test +k apply -f api-deployment.yaml -f client-deployment.yaml +k apply -f database-persistent-volume-claim.yaml +k apply -f api-cluster-ip-service.yaml +k apply -f client-cluster-ip-deployment.yaml +k apply -f postgres-cluster-ip-service.yaml +k apply -f ingress-service.yaml +``` \ No newline at end of file