Kubernetes API
This is the main API of Kubernetes. It is huge. All the concepts we discussed before and many auxiliary concepts, have corresponding API objects and operations. If you have the right permissions you can list, get, create, and update objects. Here is a detailed documentation of one of the most common operations, get a list of all the pods: GET /api/v1/pods It accepts various query parameters (all optional): • pretty: If true, the output is pretty printed • labelSelector: A selector expression to limit the result • watch: If true, watch for changes and return a stream of events • resourceVersion: With watch, returns only events that occurred after that version • timeoutSeconds: Timeout for the list or watch operation
Understanding Kubernetes Watch (kubernetes-client/java api)
I'm using kubernetes-client/java api and I want to programmatically get the pod status of all the pods in all the namespaces. My code is based on this example on Kubernetes java library.
Here's a snippet of my code:
Watch<V1Pod> watch = Watch.createWatch(
client,
api.listPodForAllNamespacesCall(
null, null, null, null, limit,
null, null, null, watchTrue,
null, null),
new TypeToken<Watch.Response<V1Pod>>() {}.getType());
for (Watch.Response<V1Pod> item : watch) {
V1PodStatus podStatus = item.object.getStatus();
String name = item.object.getMetadata().getName();
String status = podStatus.getPhase();
String kind = item.object.getKind();
String details = podStatus.toString();
System.out.printf("NAME: %s | KIND: %s | STATUS: %s | DETAILS: %n%s%n====================%n", name, kind, status, details);
}
My question is this: Is Watch equivalent to an event handler? This code shows me a list of all the statuses of the pods, but will it automatically "push" more pod status events as they occur in realtime? Or is this only triggered once?
BEST ANSWER:
Watch is designed to send continuous updates. If you run your program for a while and start/stop something, you will see new updates coming.
I'm not sure it's correct to call it an event handler though. It's a different pattern.
Note to self: Keep going. You’re doing great. You might not be where you want to be yet, but that’s okay. Just take it one step at a time and keep believing in yourself. And remember: No matter what happens, you can still enjoy your life and be happy.
Lori Deschene