Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add k8s deployment #173

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ pnpm dev

快速启动项目,执行以下命令:
```sh
docker compose up
docker compose up -d;
```

用浏览器打开 http://localhost:3000 。
用浏览器打开 http://localhost:3000/create/poem?token=secret 。

添加了诗词信息后,再访问首页 http://localhost:3000 就可以看到正常的页面了。


191 changes: 191 additions & 0 deletions k8s-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres
namespace: default
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /mnt/cfs-xxx/postgres
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: local-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: postgres
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
k8s-app: postgres
spec:
containers:
- name: postgres
image: postgres:16.2
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: "postgres"
- name: POSTGRES_PASSWORD
value: "postgres"
- name: POSTGRES_DB
value: "aspoem"
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
resources:
limits:
cpu: 2000m
memory: 4096M
requests:
cpu: 1000m
memory: 2048Mi
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres
imagePullSecrets:
- name: regcred
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
labels:
app: postgres
name: postgres
namespace: default
spec:
ports:
- protocol: TCP
port: 5432
targetPort: 5432
selector:
k8s-app: postgres
sessionAffinity: None
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: aspoem
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: aspoem
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
k8s-app: aspoem
spec:
containers:
- name: aspoem
image: aspoem:latest
ports:
- containerPort: 5432
env:
- name: POSTGRES_PRISMA_URL
value: "postgresql://postgres:postgres@postgres:5432/aspoem"
- name: POSTGRES_URL_NON_POOLING
value: "postgresql://postgres:postgres@postgres:5432/aspoem"
- name: TOKEN
value: "r2049"
- name: NEXT_PUBLIC_GA_ID
value: "xx"
- name: NEXT_PUBLIC_MC_ID
value: "xx"
resources:
limits:
cpu: 2000m
memory: 1024M
requests:
cpu: 200m
memory: 256Mi
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
labels:
app: aspoem
name: aspoem
namespace: default
spec:
ports:
- protocol: TCP
port: 3000
targetPort: 3000
selector:
k8s-app: aspoem
sessionAffinity: None
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: default
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
kubernetes.io/tls-acme: "true"
generation: 1
name: ingress-example-aspoem
spec:
ingressClassName: traefik
rules:
- host: aspoem.example.cn
http:
paths:
- backend:
service:
name: aspoem
port:
number: 3000
path: /
pathType: Prefix
tls:
- hosts:
- aspoem.example.cn
secretName: aspoem-example-cn