chore: Add Kubernetes resources for API and client deployments, services, and ingress

This commit is contained in:
2024-08-11 22:17:25 +08:00
parent 69ab87e4ed
commit 1f0b71fab1
8 changed files with 121 additions and 0 deletions
+11
View File
@@ -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
+27
View File
@@ -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
@@ -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
+20
View File
@@ -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
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-persistent-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
+19
View File
@@ -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
@@ -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
+12
View File
@@ -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
```