Skip to content

Commit

Permalink
feat(k8s): add startupProbe & readinessProbe support to services;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Feb 1, 2022
1 parent b3f313f commit fa5e57c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"lafyun",
"millicores",
"objs",
"Referer",
"signin",
"uids",
"upsert",
Expand Down
13 changes: 13 additions & 0 deletions deploy/kubernetes/fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ spec:
- image: docker.io/lafyun/storage-service:0.7.3
imagePullPolicy: IfNotPresent
name: storage-service
startupProbe:
httpGet:
path: /health-check
port: http
periodSeconds: 3
timeoutSeconds: 3
failureThreshold: 20
readinessProbe:
httpGet:
path: /health-check
port: http
periodSeconds: 10
timeoutSeconds: 3
resources:
requests:
memory: "256Mi"
Expand Down
21 changes: 17 additions & 4 deletions deploy/kubernetes/sys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ spec:
limits:
memory: "1024Mi"
cpu: "1000m"
livenessProbe:
startupProbe:
httpGet:
path: /health-check
port: 9000
initialDelaySeconds: 20
port: http
httpHeaders:
- name: Referer
value: startupProbe
periodSeconds: 3
timeoutSeconds: 3
failureThreshold: 30
readinessProbe:
httpGet:
path: /health-check
port: http
httpHeaders:
- name: Referer
value: readinessProbe
periodSeconds: 10
timeoutSeconds: 3
command: ["sh", "/app/start.sh"]
Expand Down Expand Up @@ -147,4 +159,5 @@ spec:
- name: LOG_LEVEL
value: debug
ports:
- containerPort: 9000
- name: http
containerPort: 9000
12 changes: 8 additions & 4 deletions packages/system-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: Maslow<wangfugen@126.com>
* @Date: 2021-07-30 10:30:29
* @LastEditTime: 2022-01-23 19:46:34
* @LastEditTime: 2022-02-01 22:55:54
* @Description:
*/

Expand Down Expand Up @@ -58,9 +58,13 @@ process.on('SIGTERM', gracefullyExit)
process.on('SIGINT', gracefullyExit)

async function gracefullyExit() {
logger.info('exiting: removing system extension service')
await ServiceDriver.create().removeService({ appid: Constants.SYSTEM_EXTENSION_APPID } as any)
logger.info('exiting: system extension service has been removed')

// NOT remove system extension app service if service driver is 'kubernetes',
if (Config.SERVICE_DRIVER === 'docker') {
logger.info('exiting: removing system extension service')
await ServiceDriver.create().removeService({ appid: Constants.SYSTEM_EXTENSION_APPID } as any)
logger.info('exiting: system extension service has been removed')
}

logger.info('exiting: closing db connection')
await DatabaseAgent.sys_accessor.close()
Expand Down
27 changes: 25 additions & 2 deletions packages/system-server/src/lib/service-driver/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class KubernetesServiceDriver implements ServiceDriverInterface {
labels: labels
},
spec: {
terminationGracePeriodSeconds: 15,
automountServiceAccountToken: app.appid === Constants.SYSTEM_EXTENSION_APPID,
containers: [
{
Expand All @@ -136,7 +137,7 @@ export class KubernetesServiceDriver implements ServiceDriverInterface {
{ name: 'RUNTIME_IMAGE', value: app.runtime?.image },
{ name: 'FLAGS', value: `--max_old_space_size=${max_old_space_size}` }
],
ports: [{ containerPort: 8000 }],
ports: [{ containerPort: 8000, name: 'http' }],
resources: {
requests: {
memory: `${req_memory}Mi`,
Expand All @@ -146,7 +147,29 @@ export class KubernetesServiceDriver implements ServiceDriverInterface {
memory: `${limit_memory}Mi`,
cpu: `${limit_cpu}m`
}
}
},
startupProbe: {
httpGet: {
path: '/health-check',
port: 'http',
httpHeaders: [{ name: 'Referer', value: 'startupProbe' }]
},
initialDelaySeconds: 0,
periodSeconds: 3,
timeoutSeconds: 3,
failureThreshold: 40
},
readinessProbe: {
httpGet: {
path: '/health-check',
port: 'http',
httpHeaders: [{ name: 'Referer', value: 'readinessProbe' }]
},
initialDelaySeconds: 0,
periodSeconds: 60,
timeoutSeconds: 5,
failureThreshold: 3
},
}
],
}
Expand Down

0 comments on commit fa5e57c

Please sign in to comment.