Skip to content

Commit 88f7bcf

Browse files
authored
[v17] Make teleport container do a graceful shutdown (#48942)
* Container image should try a graceful shutdown by default * Make grace termination period configurable in teleport-kube-agent * re-render docs
1 parent 171c249 commit 88f7bcf

File tree

9 files changed

+92
-0
lines changed

9 files changed

+92
-0
lines changed

build.assets/charts/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# DEPRECATED: Images from this dockerfile are not published for v15 and above
2+
# https://goteleport.com/docs/changelog/#heavy-container-images-are-discontinued
3+
# Teleport images are built from Dockerfile-distroless
4+
# TODO(hugoShaka): cleanup the Makefile docker/image targets and remove this file.
5+
16
# Stage to build the image, without FIPS entrypoint argument
27
FROM ubuntu:20.04 AS teleport
38

@@ -67,6 +72,10 @@ RUN --mount=target=/ctx \
6772
# Used to track whether a Teleport agent was installed using this method.
6873
ENV TELEPORT_INSTALL_METHOD_DOCKERFILE=true
6974

75+
# Attempt a graceful shutdown by default
76+
# See https://goteleport.com/docs/reference/signals/ for signal reference.
77+
STOPSIGNAL SIGQUIT
78+
7079
# By setting this entry point, we expose make target as command.
7180
ENTRYPOINT ["/usr/bin/dumb-init", "teleport", "start", "-c", "/etc/teleport/teleport.yaml"]
7281

build.assets/charts/Dockerfile-distroless

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ FROM $BASE_IMAGE
3030
COPY --from=teleport /opt/staging /
3131
COPY --from=staging /opt/staging/root /
3232
COPY --from=staging /opt/staging/status /var/lib/dpkg/status.d
33+
# Attempt a graceful shutdown by default
34+
# See https://goteleport.com/docs/reference/signals/ for signal reference.
35+
STOPSIGNAL SIGQUIT
3336
ENTRYPOINT ["/usr/bin/dumb-init", "/usr/local/bin/teleport", "start", "-c", "/etc/teleport/teleport.yaml"]

build.assets/charts/Dockerfile-distroless-fips

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ FROM $BASE_IMAGE
3030
COPY --from=teleport /opt/staging /
3131
COPY --from=staging /opt/staging/root /
3232
COPY --from=staging /opt/staging/status /var/lib/dpkg/status.d
33+
# Attempt a graceful shutdown by default
34+
# See https://goteleport.com/docs/reference/signals/ for signal reference.
35+
STOPSIGNAL SIGQUIT
3336
ENTRYPOINT ["/usr/bin/dumb-init", "/usr/local/bin/teleport", "start", "-c", "/etc/teleport/teleport.yaml", "--fips"]

docs/pages/includes/helm-reference/zz_generated.teleport-kube-agent.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,21 @@ teleportConfig:
631631
"*":"*"
632632
```
633633

634+
## `terminationGracePeriodSeconds`
635+
636+
| Type | Default |
637+
|------|---------|
638+
| `integer` | `30` |
639+
640+
`terminationGracePeriodSeconds` is the time the pod has to do a graceful shutdown.
641+
If teleport has not existed after this delay, the process gets killed.
642+
Teleport will wait until every connection backed by the agent is over before exiting.
643+
If you want to reduce the disruption of rolling out agents at the price of a slower rollout, you can increase this
644+
value to an hour.
645+
646+
See the [Kubernetes Pod Lifecycle docs](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination)
647+
for more details.
648+
634649
## `tls`
635650

636651
`tls` contains settings for mounting your own TLS material in the agent pod.

examples/chart/teleport-kube-agent/templates/statefulset.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ spec:
4949
{{- if .Values.podSecurityContext }}
5050
securityContext: {{- toYaml .Values.podSecurityContext | nindent 8}}
5151
{{- end }}
52+
{{- if .Values.terminationGracePeriodSeconds }}
53+
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
54+
{{- end }}
5255
{{- if or .Values.affinity (gt (int $replicaCount) 1) }}
5356
affinity:
5457
{{- if .Values.affinity }}

examples/chart/teleport-kube-agent/tests/__snapshot__/statefulset_test.yaml.snap

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ sets Pod annotations when specified:
6363
securityContext:
6464
fsGroup: 9807
6565
serviceAccountName: RELEASE-NAME
66+
terminationGracePeriodSeconds: 30
6667
volumes:
6768
- configMap:
6869
name: RELEASE-NAME
@@ -135,6 +136,7 @@ sets Pod labels when specified:
135136
securityContext:
136137
fsGroup: 9807
137138
serviceAccountName: RELEASE-NAME
139+
terminationGracePeriodSeconds: 30
138140
volumes:
139141
- configMap:
140142
name: RELEASE-NAME
@@ -231,6 +233,7 @@ sets StatefulSet labels when specified:
231233
securityContext:
232234
fsGroup: 9807
233235
serviceAccountName: RELEASE-NAME
236+
terminationGracePeriodSeconds: 30
234237
volumes:
235238
- configMap:
236239
name: RELEASE-NAME
@@ -335,6 +338,7 @@ should add insecureSkipProxyTLSVerify to args when set in values:
335338
securityContext:
336339
fsGroup: 9807
337340
serviceAccountName: RELEASE-NAME
341+
terminationGracePeriodSeconds: 30
338342
volumes:
339343
- configMap:
340344
name: RELEASE-NAME
@@ -407,6 +411,7 @@ should add volumeClaimTemplate for data volume when using StatefulSet and action
407411
securityContext:
408412
fsGroup: 9807
409413
serviceAccountName: RELEASE-NAME
414+
terminationGracePeriodSeconds: 30
410415
volumes:
411416
- configMap:
412417
name: RELEASE-NAME
@@ -499,6 +504,7 @@ should add volumeClaimTemplate for data volume when using StatefulSet and is Fre
499504
securityContext:
500505
fsGroup: 9807
501506
serviceAccountName: RELEASE-NAME
507+
terminationGracePeriodSeconds: 30
502508
volumes:
503509
- configMap:
504510
name: RELEASE-NAME
@@ -581,6 +587,7 @@ should add volumeMount for data volume when using StatefulSet:
581587
securityContext:
582588
fsGroup: 9807
583589
serviceAccountName: RELEASE-NAME
590+
terminationGracePeriodSeconds: 30
584591
volumes:
585592
- configMap:
586593
name: RELEASE-NAME
@@ -653,6 +660,7 @@ should expose diag port:
653660
securityContext:
654661
fsGroup: 9807
655662
serviceAccountName: RELEASE-NAME
663+
terminationGracePeriodSeconds: 30
656664
volumes:
657665
- configMap:
658666
name: RELEASE-NAME
@@ -725,6 +733,7 @@ should generate Statefulset when storage is disabled and mode is a Upgrade:
725733
securityContext:
726734
fsGroup: 9807
727735
serviceAccountName: RELEASE-NAME
736+
terminationGracePeriodSeconds: 30
728737
volumes:
729738
- configMap:
730739
name: RELEASE-NAME
@@ -811,6 +820,7 @@ should have multiple replicas when replicaCount is set (using .replicaCount, dep
811820
securityContext:
812821
fsGroup: 9807
813822
serviceAccountName: RELEASE-NAME
823+
terminationGracePeriodSeconds: 30
814824
volumes:
815825
- configMap:
816826
name: RELEASE-NAME
@@ -895,6 +905,7 @@ should have multiple replicas when replicaCount is set (using highAvailability.r
895905
securityContext:
896906
fsGroup: 9807
897907
serviceAccountName: RELEASE-NAME
908+
terminationGracePeriodSeconds: 30
898909
volumes:
899910
- configMap:
900911
name: RELEASE-NAME
@@ -967,6 +978,7 @@ should have one replica when replicaCount is not set:
967978
securityContext:
968979
fsGroup: 9807
969980
serviceAccountName: RELEASE-NAME
981+
terminationGracePeriodSeconds: 30
970982
volumes:
971983
- configMap:
972984
name: RELEASE-NAME
@@ -1039,6 +1051,7 @@ should install Statefulset when storage is disabled and mode is a Fresh Install:
10391051
securityContext:
10401052
fsGroup: 9807
10411053
serviceAccountName: RELEASE-NAME
1054+
terminationGracePeriodSeconds: 30
10421055
volumes:
10431056
- configMap:
10441057
name: RELEASE-NAME
@@ -1115,6 +1128,7 @@ should mount extraVolumes and extraVolumeMounts:
11151128
securityContext:
11161129
fsGroup: 9807
11171130
serviceAccountName: RELEASE-NAME
1131+
terminationGracePeriodSeconds: 30
11181132
volumes:
11191133
- configMap:
11201134
name: RELEASE-NAME
@@ -1193,6 +1207,7 @@ should mount jamfCredentialsSecret if it already exists and when role is jamf:
11931207
securityContext:
11941208
fsGroup: 9807
11951209
serviceAccountName: RELEASE-NAME
1210+
terminationGracePeriodSeconds: 30
11961211
volumes:
11971212
- configMap:
11981213
name: RELEASE-NAME
@@ -1273,6 +1288,7 @@ should mount jamfCredentialsSecret.name when role is jamf:
12731288
securityContext:
12741289
fsGroup: 9807
12751290
serviceAccountName: RELEASE-NAME
1291+
terminationGracePeriodSeconds: 30
12761292
volumes:
12771293
- configMap:
12781294
name: RELEASE-NAME
@@ -1355,6 +1371,7 @@ should mount tls.existingCASecretName and set environment when set in values:
13551371
securityContext:
13561372
fsGroup: 9807
13571373
serviceAccountName: RELEASE-NAME
1374+
terminationGracePeriodSeconds: 30
13581375
volumes:
13591376
- configMap:
13601377
name: RELEASE-NAME
@@ -1439,6 +1456,7 @@ should mount tls.existingCASecretName and set extra environment when set in valu
14391456
securityContext:
14401457
fsGroup: 9807
14411458
serviceAccountName: RELEASE-NAME
1459+
terminationGracePeriodSeconds: 30
14421460
volumes:
14431461
- configMap:
14441462
name: RELEASE-NAME
@@ -1516,6 +1534,7 @@ should not add emptyDir for data when using StatefulSet:
15161534
securityContext:
15171535
fsGroup: 9807
15181536
serviceAccountName: RELEASE-NAME
1537+
terminationGracePeriodSeconds: 30
15191538
volumes:
15201539
- configMap:
15211540
name: RELEASE-NAME
@@ -1626,6 +1645,7 @@ should provision initContainer correctly when set in values:
16261645
securityContext:
16271646
fsGroup: 9807
16281647
serviceAccountName: RELEASE-NAME
1648+
terminationGracePeriodSeconds: 30
16291649
volumes:
16301650
- configMap:
16311651
name: RELEASE-NAME
@@ -1718,6 +1738,7 @@ should set affinity when set in values:
17181738
securityContext:
17191739
fsGroup: 9807
17201740
serviceAccountName: RELEASE-NAME
1741+
terminationGracePeriodSeconds: 30
17211742
volumes:
17221743
- configMap:
17231744
name: RELEASE-NAME
@@ -1790,6 +1811,7 @@ should set default serviceAccountName when not set in values:
17901811
securityContext:
17911812
fsGroup: 9807
17921813
serviceAccountName: RELEASE-NAME
1814+
terminationGracePeriodSeconds: 30
17931815
volumes:
17941816
- configMap:
17951817
name: RELEASE-NAME
@@ -1875,6 +1897,7 @@ should set environment when extraEnv set in values:
18751897
securityContext:
18761898
fsGroup: 9807
18771899
serviceAccountName: RELEASE-NAME
1900+
terminationGracePeriodSeconds: 30
18781901
volumes:
18791902
- configMap:
18801903
name: RELEASE-NAME
@@ -1947,6 +1970,7 @@ should set image and tag correctly:
19471970
securityContext:
19481971
fsGroup: 9807
19491972
serviceAccountName: RELEASE-NAME
1973+
terminationGracePeriodSeconds: 30
19501974
volumes:
19511975
- configMap:
19521976
name: RELEASE-NAME
@@ -2019,6 +2043,7 @@ should set imagePullPolicy when set in values:
20192043
securityContext:
20202044
fsGroup: 9807
20212045
serviceAccountName: RELEASE-NAME
2046+
terminationGracePeriodSeconds: 30
20222047
volumes:
20232048
- configMap:
20242049
name: RELEASE-NAME
@@ -2093,6 +2118,7 @@ should set nodeSelector if set in values:
20932118
securityContext:
20942119
fsGroup: 9807
20952120
serviceAccountName: RELEASE-NAME
2121+
terminationGracePeriodSeconds: 30
20962122
volumes:
20972123
- configMap:
20982124
name: RELEASE-NAME
@@ -2177,6 +2203,7 @@ should set preferred affinity when more than one replica is used:
21772203
securityContext:
21782204
fsGroup: 9807
21792205
serviceAccountName: RELEASE-NAME
2206+
terminationGracePeriodSeconds: 30
21802207
volumes:
21812208
- configMap:
21822209
name: RELEASE-NAME
@@ -2249,6 +2276,7 @@ should set probeTimeoutSeconds when set in values:
22492276
securityContext:
22502277
fsGroup: 9807
22512278
serviceAccountName: RELEASE-NAME
2279+
terminationGracePeriodSeconds: 30
22522280
volumes:
22532281
- configMap:
22542282
name: RELEASE-NAME
@@ -2331,6 +2359,7 @@ should set required affinity when highAvailability.requireAntiAffinity is set:
23312359
securityContext:
23322360
fsGroup: 9807
23332361
serviceAccountName: RELEASE-NAME
2362+
terminationGracePeriodSeconds: 30
23342363
volumes:
23352364
- configMap:
23362365
name: RELEASE-NAME
@@ -2410,6 +2439,7 @@ should set resources when set in values:
24102439
securityContext:
24112440
fsGroup: 9807
24122441
serviceAccountName: RELEASE-NAME
2442+
terminationGracePeriodSeconds: 30
24132443
volumes:
24142444
- configMap:
24152445
name: RELEASE-NAME
@@ -2482,6 +2512,7 @@ should set serviceAccountName when set in values:
24822512
securityContext:
24832513
fsGroup: 9807
24842514
serviceAccountName: teleport-kube-agent-sa
2515+
terminationGracePeriodSeconds: 30
24852516
volumes:
24862517
- configMap:
24872518
name: RELEASE-NAME
@@ -2554,6 +2585,7 @@ should set storage.requests when set in values and action is an Upgrade:
25542585
securityContext:
25552586
fsGroup: 9807
25562587
serviceAccountName: RELEASE-NAME
2588+
terminationGracePeriodSeconds: 30
25572589
volumes:
25582590
- configMap:
25592591
name: RELEASE-NAME
@@ -2626,6 +2658,7 @@ should set storage.storageClassName when set in values and action is an Upgrade:
26262658
securityContext:
26272659
fsGroup: 9807
26282660
serviceAccountName: RELEASE-NAME
2661+
terminationGracePeriodSeconds: 30
26292662
volumes:
26302663
- configMap:
26312664
name: RELEASE-NAME
@@ -2698,6 +2731,7 @@ should set tolerations when set in values:
26982731
securityContext:
26992732
fsGroup: 9807
27002733
serviceAccountName: RELEASE-NAME
2734+
terminationGracePeriodSeconds: 30
27012735
tolerations:
27022736
- effect: NoExecute
27032737
key: dedicated

examples/chart/teleport-kube-agent/tests/statefulset_test.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,13 @@ tests:
814814
hostnames:
815815
- "foo.remote"
816816
- "bar.remote"
817+
- it: should set the terminationGracePeriodSeconds when specified
818+
template: statefulset.yaml
819+
values:
820+
- ../.lint/stateful.yaml
821+
set:
822+
terminationGracePeriodSeconds: 3600
823+
asserts:
824+
- equal:
825+
path: spec.template.spec.terminationGracePeriodSeconds
826+
value: 3600

examples/chart/teleport-kube-agent/values.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@
252252
"type": "object",
253253
"default": {}
254254
},
255+
"terminationGracePeriodSeconds": {
256+
"$id": "#/properties/terminationGracePeriodSeconds",
257+
"type": "integer",
258+
"default": 30
259+
},
255260
"tls": {
256261
"$id": "#/properties/tls",
257262
"type": "object",

examples/chart/teleport-kube-agent/values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,16 @@ insecureSkipProxyTLSVerify: false
538538
# ```
539539
teleportConfig: {}
540540

541+
# terminationGracePeriodSeconds(integer) -- is the time the pod has to do a graceful shutdown.
542+
# If teleport has not existed after this delay, the process gets killed.
543+
# Teleport will wait until every connection backed by the agent is over before exiting.
544+
# If you want to reduce the disruption of rolling out agents at the price of a slower rollout, you can increase this
545+
# value to an hour.
546+
#
547+
# See the [Kubernetes Pod Lifecycle docs](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination)
548+
# for more details.
549+
terminationGracePeriodSeconds: 30
550+
541551
# tls -- contains settings for mounting your own TLS material in the agent pod.
542552
# The agent does not expose a TLS server, so this is only used to trust CAs.
543553
tls:

0 commit comments

Comments
 (0)