Hello there,
I was wondering what event is triggered before a new Pod is created? In fact, I want to perform an operation just after the creation of a new Pod. So is there any automatic way, that I can understand when a new Pod is created?
Thanks
Hello there,
I was wondering what event is triggered before a new Pod is created? In fact, I want to perform an operation just after the creation of a new Pod. So is there any automatic way, that I can understand when a new Pod is created?
Thanks
You can watch pods and filter for creations. That also helps ensure
you don’t “miss” events by combining list+watch
Thanks for your reply. But, I don’t want to do it manually. I want a piece of code be executed when a Pod is created or deleted. So is there any way to understand automatically if a Pod that belongs to a specific service is added or deleted?
I am not sure what you mean by “manually”. You want a piece of code
to execute, so you are writing that code. Where do you want it to
execute? On your desktop? On a node in your cluster? On a
serverless framework?
For example:
thockin@freakshow2 kubernetes master /$ k get pods
NAME READY STATUS RESTARTS AGE
hostnames-7677dfcfff-5f8mh 1/1 Running 0 109s
hostnames-7677dfcfff-f9r8s 1/1 Running 0 4m54s
hostnames-7677dfcfff-sj4qx 1/1 Running 0 20h
hostnames2-76b84c7f58-8zrsl 1/1 Running 0 27h
thockin@freakshow2 kubernetes master /$ (sleep 10; k delete pod
hostnames2-76b84c7f58-8zrsl >/dev/null) &
thockin@freakshow2 kubernetes master /$ k get pods --watch
--watch-only --output-watch-events -o go-template='{{.type}}
{{.object.metadata.name}}{{"\n"}}'
MODIFIED hostnames2-76b84c7f58-8zrsl
ADDED hostnames2-76b84c7f58-qqkbl
MODIFIED hostnames2-76b84c7f58-qqkbl
MODIFIED hostnames2-76b84c7f58-qqkbl
MODIFIED hostnames2-76b84c7f58-8zrsl
MODIFIED hostnames2-76b84c7f58-qqkbl
MODIFIED hostnames2-76b84c7f58-8zrsl
DELETED hostnames2-76b84c7f58-8zrsl
What you want to DO with that information is a different conversation