问题描述
基本上,我想尝试的是使用pod的生命周期,并检查是否可以在pod终止之前进行一些清理/备份,例如复制日志.
Basically I am trying to do is play around with pod lifecycle and check if we can do some cleanup/backup such as copy logs before the pod terminates.
我需要什么:在终止之前,将日志/堆转储从容器复制到hostPath/S3
What I need :Copy logs/heapdumps from container to a hostPath/S3 before terminating
我尝试过的事情:
我使用带有bash命令的preStop挂钩来回显消息(只是看它是否有效!).使用了terminationGracePeriodSeconds并延迟了preStop和切换它们以查看该过程是否有效.前任.保留TerminalGracePeriodSeconds:30秒(默认值),并将preStop命令设置为休眠50秒,并且不应生成该消息,因为此时容器将被终止.这可以按预期工作.
I used a preStop hook with a bash command to echo a message (just to see if it works !!). Used terminationGracePeriodSeconds with a delay to preStop and toggle them to see if the process works. Ex. keep terminationGracePeriodSeconds:30 sec (default) and set preStop command to sleep by 50 sec and the message should not be generated since the container will be terminated by then. This works as expected.
我的问题:
- preStop挂钩允许(推荐)什么样的过程?由于要复制15或更多的日志/堆,将花费大量时间.然后,这段时间将用于定义终止GracePeriodSeconds
- 当preStop花费的时间超过所设置的gracePeriod时,会发生什么?(以防日志很大,例如10个演出)
- 如果我没有任何钩子但仍设置了terminationGracePeriodSeconds,会发生什么?容器会一直保持到那个宽限期吗?
- what kind of processes are allowed(recommended) for a preStop hook? As copying logs/heapdumps of 15 gigs or more will take a lot of time. This time will then be used to define terminationGracePeriodSeconds
- what happens when preStop takes more time than the set gracePeriod ?(in case logs are huge say 10 gigs)
- what happens if I do not have any hooks but still set terminationGracePeriodSeconds ? will the container remain up until that grace time ?
我发现这篇文章与此紧密相关,但无法通过 https://github来了解.com/kubernetes/kubernetes/issues/24695
I found this article which closely relates to this but could not follow through https://github.com/kubernetes/kubernetes/issues/24695
感谢所有输入!!
推荐答案
这里没有任何内容,更多的是意见,以及您希望吊舱如何徘徊.另一个选择是让您的Pod终止并将您的数据存储在某个位置(例如,AWS S3,EBS),在该位置数据将在Pod生命周期内持续存在,然后使用作业清理数据等.
Anything goes here, it's more of an opinion and how you would like your pods to linger around. Another option is to let your pods terminate and store your data in some place (i.e, AWS S3, EBS) where data will persist past the pod lifecycle then use something like Job to clean up the data, etc.
您的preStop将无法完成,这可能意味着数据不完整或数据损坏.
Your preStop will not complete which may mean incomplete data or data corruption.
这将解释为顺序:
- 将SIGTERM信号发送到每个容器中的主进程,并开始宽限期"倒计时.
- 如果容器未在宽限期内终止,则将发送SIGKILL信号并容器.
这篇关于preStop挂钩和终止之间的关系GracePeriodSeconds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!