在 Kubernetes 中推出后,是否可以更快地终止本地容器
Is it possible to terminate faster a container in local, after a rollout in Kubernetes
当我在本地使用 minikube 时,我会在每次重建我的应用程序时进行检查,并通过以下方式推出它:
kubectl rollout restart deployment/api-local -n influx
容器持续 30 秒被终止。我对生产问题没有问题,但在本地开发中,我最终浪费了很多时间等待,因为我可能会重建我的应用程序 100 次(= 每天损失 50 分钟)。
有什么技巧可以缩短这个终止时间吗?我知道这不是 k8s 最佳实践的一部分,但对我来说很有意义。
在deployment/pod配置中设置terminationGracePeriodSeconds
。根据 reference docs,它是:
...Optional duration in seconds the pod needs to terminate gracefully.
May be decreased in delete request. Value must be non-negative
integer. The value zero indicates delete immediately. If this value is
nil, the default grace period will be used instead. The grace period
is the duration in seconds after the processes running in the pod are
sent a termination signal and the time when the processes are forcibly
halted with a kill signal. Set this value longer than the expected
cleanup time for your process. Defaults to 30 seconds.
示例:
spec:
replicas: 1
selector:
...
template:
spec:
terminationGracePeriodSeconds: 0
containers:
...
此外,来自 here:
The kubectl delete command supports the --grace-period=
option which allows a user to override the default and specify their
own value. The value 0 force deletes the Pod. You must specify an
additional flag --force along with --grace-period=0 in order to
perform force deletions.
示例(指定命名空间,如果需要):
kubectl delete pod <pod-name> --now
...或
kubectl delete pod <pod-name> --grace-period=0 --force
当我在本地使用 minikube 时,我会在每次重建我的应用程序时进行检查,并通过以下方式推出它:
kubectl rollout restart deployment/api-local -n influx
容器持续 30 秒被终止。我对生产问题没有问题,但在本地开发中,我最终浪费了很多时间等待,因为我可能会重建我的应用程序 100 次(= 每天损失 50 分钟)。
有什么技巧可以缩短这个终止时间吗?我知道这不是 k8s 最佳实践的一部分,但对我来说很有意义。
在deployment/pod配置中设置terminationGracePeriodSeconds
。根据 reference docs,它是:
...Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. Defaults to 30 seconds.
示例:
spec:
replicas: 1
selector:
...
template:
spec:
terminationGracePeriodSeconds: 0
containers:
...
此外,来自 here:
The kubectl delete command supports the --grace-period= option which allows a user to override the default and specify their own value. The value 0 force deletes the Pod. You must specify an additional flag --force along with --grace-period=0 in order to perform force deletions.
示例(指定命名空间,如果需要):
kubectl delete pod <pod-name> --now
...或
kubectl delete pod <pod-name> --grace-period=0 --force