英文:
How to configure readiness and liveness probe of pod in kubernetes, where a standalone go service is running?
问题
我已经用中文翻译了你的内容:
我用Go语言编写了一个作业调度服务,它在固定时间间隔内上传文件。该服务内部没有运行HTTP服务。
通常情况下,对于HTTP服务,需要在部署文件中添加以下就绪探针和存活探针配置:
就绪探针:
readinessProbe:
httpGet:
path: <http_get_path>
port: 3401
initialDelaySeconds: 5
timeoutSeconds: 1
periodSeconds: 15
存活探针:
livenessProbe:
httpGet:
path: <http_get_path>
port: 3401
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 15
对于像下面这样的独立服务:
// main: 触发服务的主函数
func main() {
scheduler.RunScheduler()
}
// RunScheduler: 运行调度器
func RunScheduler() {
done := make(chan bool)
quit := make(chan bool)
go startJob1()
go startJob2()
sigs := make(chan os.Signal, 1)
// 只有当应用程序停止时,传递 done "True"
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
.....
}
该服务只是定期运行,并且不监听任何端口,我们能配置任何类型的就绪探针和存活探针吗?
英文:
I have written a job scheduler service in go, which uploads files under a periodic interval. There is no HTTP service is running inside that service.
Normally, for HTTP service, below are liveness and readiness probe configuration, need to be added at the deployment file.
readinessProbe:
httpGet:
path: <http_get_path>
port: 3401
initialDelaySeconds: 5
timeoutSeconds: 1
periodSeconds: 15
livenessProbe:
httpGet:
path: <http_get_path>
port: 3401
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 15
For standalone service like below:
//main : main function to trigger the services
func main() {
scheduler.RunScheduler()
}
//RunScheduler : Run the scheduler
func RunScheduler() {
done := make(chan bool)
quit := make(chan bool)
go startJob1()
go startJob2()
sigs := make(chan os.Signal, 1)
//pass done "True", only if the application is stopped
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
.....
}
which just runs periodically and don't listen to any port, can we configure any kind of readiness probe and liveness probe?
答案1
得分: 3
由于您的容器不处理任何HTTP请求,因此不需要readinessProbe
。
> readinessProbe
:指示容器是否准备好响应请求。如果就绪探针失败,端点控制器将从所有与Pod匹配的服务的端点中删除Pod的IP地址。
您需要一个livenessProbe
。
> livenessProbe
:指示容器是否正在运行。如果存活探针失败,kubelet将终止容器,并将容器受其重启策略的影响。
以下是一个使用ps
命令的示例:
livenessProbe:
exec:
command:
- ps -ef | grep my_process_name
initialDelaySeconds: 120
periodSeconds: 30
请确保在$PATH
中有ps
命令。
另一种方法是在Pod启动时在tmp目录中创建一个文件,并在exec
命令中检查文件是否存在。
英文:
Since your container doesn't handle any http request you dont need readinessProbe
.
> readinessProbe
: Indicates whether the container is ready to respond to
> requests. If the readiness probe fails, the endpoints controller
> removes the Pod's IP address from the endpoints of all Services that
> match the Pod.
When should you use a liveness probe?
You need a livenessProbe
.
> livenessProbe
: Indicates whether the container is running. If the
> liveness probe fails, the kubelet kills the container, and the
> container is subjected to its restart policy.
When should you use a readiness probe?
Here is an example with ps
of process:
livenessProbe:
exec:
command:
- ps -ef | grep my_process_name
initialDelaySeconds: 120
periodSeconds: 30
Be sure you have a ps
command in the $PATH
.
Another way is to create a file in the tmp dir on the pod start and check if a file present in the exec
command.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论