简体   繁体   English

如何使用SDK在Kubernetes Operator中观看Pod api端点

[英]How to watch a Pod api endpoint in a Kubernetes Operator using the SDK

Description 描述

I have a CR associated with a POD with a container that is exposing an API, eg: 我有一个与POD相关联的CR,该POD带有一个暴露API的容器,例如:

/available

returning for example 例如返回

{"available":"true"}

Is there a way to create a controller watcher on that API call that whenever the response changes will trigger the reconcile function? 有没有一种方法可以在该API调用上创建控制器观察程序,以便每当响应更改时都会触发协调功能? I believe it could be possible using a channel with the controller watcher, but I don't see any similar examples out there 我相信它可能使用与控制器守望通道是可能的,但我没有看到任何类似的例子在那里

Using 运用

Kubernetes operator-sdk version v0.5.0+git Kubernetes Operator-SDK版本v0.5.0 + git

I'm afraid it's not as easy as you hope. 恐怕这没有您希望的那么容易。 The Kubernetes controller objects react to add/edit/delete operations of some kind of resource in the cluster. Kubernetes控制器对象对集群中某种资源的添加/编辑/删除操作做出反应。 A value exposed inside an API of something running inside the Pod is not visible in the resource database. 在资源库中看不到在Pod中运行的某些东西的API内部公开的值。 There is not event going off, notifying about the change either. 没有事件发生,也没有通知更改。

I see two things you can consider doing: 我看到您可以考虑做的两件事:

  1. Create a regular controller that would have the reconcile function triggered fairly often, but would check the availability value inside it's reconcile function. 创建一个常规控制器,该控制器会经常触发协调功能,但会检查其协调功能内部的availability值。 If it changed, it would do something, if it didn't it would do nothing. 如果改变了,它会做些什么,如果没有改变,它将什么都不做。
  2. Just create a separate task, outside the controller domain, that would monitor this API value and do something. 只需在控制器域之外创建一个单独的任务,该任务将监视此API值并执行某些操作。

Controllers work using notifications, they don't actively watch for changes, they are notified about them. 控制器使用通知进行工作,他们不会主动监视更改,而是会收到通知。 That's different than what you want to do - periodically check the API response. 这与您要执行的操作不同-定期检查API响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM