Skip to content

Commit

Permalink
feat(envoy): use the healthcheck filter and a prestop hook to gracefu…
Browse files Browse the repository at this point in the history
…lly terminate Envoy (#6194)

* use the healthcheck filter and gracefully terminate Envoy with a prestop hook

* remove magic numbers

* make admin interface port configurable
  • Loading branch information
driev authored Jan 16, 2025
1 parent 235bf27 commit c80ab43
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,15 @@ spec:
image: '{{ .Values.envoy.image.registry }}/{{ .Values.envoy.image.repository
}}:{{ .Values.envoy.image.tag }}'
imagePullPolicy: '{{ .Values.envoy.image.pullPolicy }}'
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
echo -ne "POST /healthcheck/fail HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" > /dev/tcp/localhost/{{ .Values.envoy.adminInterfacePort }}
sleep '{{ .Values.envoy.preStopSleepPeriodSeconds }}'
name: envoy
ports:
- containerPort: 9000
Expand All @@ -969,7 +978,8 @@ spec:
{{- end }}
securityContext: {{- toYaml .Values.envoy.securityContext | nindent
8 }}
terminationGracePeriodSeconds: 5
terminationGracePeriodSeconds: {{ .Values.envoy.terminationGracePeriodSeconds
}}
replicas: 1
- annotations: {{- toYaml .Values.dataflow.annotations | nindent 8
}}
Expand Down
3 changes: 3 additions & 0 deletions k8s/helm-charts/seldon-core-v2-setup/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ envoy:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
preStopSleepPeriodSeconds: 30
terminationGracePeriodSeconds: 120
adminInterfacePort: 9901

scheduler:
image:
Expand Down
3 changes: 3 additions & 0 deletions k8s/helm-charts/seldon-core-v2-setup/values.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ envoy:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
preStopSleepPeriodSeconds: 30
terminationGracePeriodSeconds: 120
adminInterfacePort: 9901

scheduler:
image:
Expand Down
9 changes: 9 additions & 0 deletions k8s/kustomize/helm-components-sc/patch_envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ spec:
name: '{{ .Values.security.controlplane.ssl.client.serverValidationSecret }}'
key: ca.crt
optional: true
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
echo -ne "POST /healthcheck/fail HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" > /dev/tcp/localhost/{{ .Values.envoy.adminInterfacePort }}
sleep '{{ .Values.envoy.preStopSleepPeriodSeconds }}'
3 changes: 3 additions & 0 deletions k8s/kustomize/helm-components-sc/patch_envoy_json6902.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
- op: replace
path: /spec/components/4/annotations
value: HACK_REMOVE_ME{{- toYaml .Values.envoy.annotations | nindent 8 }}
- op: replace
path: /spec/components/4/podSpec/terminationGracePeriodSeconds
value: HACK_REMOVE_ME{{ .Values.envoy.terminationGracePeriodSeconds }}
11 changes: 10 additions & 1 deletion k8s/yaml/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,15 @@ spec:
optional: true
image: 'docker.io/seldonio/seldon-envoy:latest'
imagePullPolicy: 'IfNotPresent'
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- |
echo -ne "POST /healthcheck/fail HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" > /dev/tcp/localhost/9901
sleep '30'
name: envoy
ports:
- containerPort: 9000
Expand All @@ -809,7 +818,7 @@ spec:
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
terminationGracePeriodSeconds: 5
terminationGracePeriodSeconds: 120
replicas: 1
- annotations:
null
Expand Down
11 changes: 7 additions & 4 deletions scheduler/config/envoy-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ static_resources:
port_value: 9003
filter_chains:
- filters:
- name: envoy.filters.http.health_check
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.health_check.v3.HealthCheck
pass_through_mode: false
headers:
- exact_match: /ready
name: :path
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
Expand All @@ -57,10 +64,6 @@ static_resources:
prefix: /stats
route:
cluster: admin_interface_cluster
- match:
prefix: /ready
route:
cluster: admin_interface_cluster
dynamic_resources:
ads_config:
api_type: DELTA_GRPC
Expand Down
11 changes: 7 additions & 4 deletions scheduler/config/envoy-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ static_resources:
port_value: 9003
filter_chains:
- filters:
- name: envoy.filters.http.health_check
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.health_check.v3.HealthCheck
pass_through_mode: false
headers:
- exact_match: /ready
name: :path
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
Expand All @@ -57,10 +64,6 @@ static_resources:
prefix: /stats
route:
cluster: admin_interface_cluster
- match:
prefix: /ready
route:
cluster: admin_interface_cluster
dynamic_resources:
ads_config:
api_type: DELTA_GRPC
Expand Down
11 changes: 7 additions & 4 deletions scheduler/config/envoy-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ static_resources:
port_value: 9003
filter_chains:
- filters:
- name: envoy.filters.http.health_check
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.health_check.v3.HealthCheck
pass_through_mode: false
headers:
- exact_match: /ready
name: :path
- name: envoy.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
Expand All @@ -70,10 +77,6 @@ static_resources:
prefix: /stats
route:
cluster: admin_interface_cluster
- match:
prefix: /ready
route:
cluster: admin_interface_cluster
dynamic_resources:
ads_config:
api_type: DELTA_GRPC
Expand Down
11 changes: 7 additions & 4 deletions scheduler/config/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ static_resources:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: util_endpoint_http
http_filters:
- name: envoy.filters.http.health_check
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.health_check.v3.HealthCheck
pass_through_mode: false
headers:
- exact_match: /ready
name: :path
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
Expand All @@ -57,10 +64,6 @@ static_resources:
prefix: /stats
route:
cluster: admin_interface_cluster
- match:
prefix: /ready
route:
cluster: admin_interface_cluster
dynamic_resources:
ads_config:
api_type: DELTA_GRPC
Expand Down
2 changes: 1 addition & 1 deletion scheduler/k8s/envoy/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ spec:
containerPort: 9000
- name: envoy-stats
containerPort: 9003
terminationGracePeriodSeconds: 5
terminationGracePeriodSeconds: 120

0 comments on commit c80ab43

Please sign in to comment.