What Is The Watch Mechanism in Kubernetes?

Question
What is the "watch mechanism" in Kubernetes?

Solution
A notification system from the API server to trigger changes in Kubernetes. In Kubernetes there are observable events. The watch mechanism is a system for listening for specific events to respond to. The Kubelet, the Scheduler, the kube-dns pod, and individual controllers are components that use the watch mechanism. The API server is a central component that watching components are aware of. (This was summarized from pages 319, 321, and 323 of Kubernetes in Action.)

If you want to see how the relevant --watch flag works, run this command:

kubectl get pods --watch

(This command was taken from 318 of Kubernetes in Action.)

To see various watch.go files, see this: https://github.com/kubernetes/kubernetes/search?q=filename%3Awatch.go

To see the source code of watch.go you for etcd you used to be able to go to this file: https://github.com/etcd-io/etcd/blob/master/clientv3/watch.go

Leave a comment

Your email address will not be published. Required fields are marked *