Reputation: 117
I have Kubernetes Deployment
with 10 pods.
And I have 10 directories path in my database table (path_table) as follow:
path,id
c:\dir1, 1
c:\dir2, 2
...
c:\dir10, 10
I want to configure each pod to look on different path from DB.
Means - pod1 will monitor c:\dir1
, pod2 will monitor c:\dir2
,etc..
How can I make each pod start with different query from db to take it's path, example:
pod1 start with select path from path_table where id=1
pod2 start with select path from path_table where id=2
...
Upvotes: 1
Views: 3010
Reputation: 9590
As mentioned in the comments, I don't think it is possible with Deployment
as the pods in a Deployment
are independent replicas of the same application with no state.
You might want to look at StatefulSets
where each pod has a unique name that can be used to work on a specific directory as you require.
You can pass the pod name as the environment variable to the pods which has a unique id in case of Statefulset
:
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
So, if you have ten replicas of a Statefulset
with name myapp
then the pods will have the names as myapp-0
, myapp-1
and so on.
You can then internally use these names to work on specific directories based on the env value of MY_POD_NAME
.
Upvotes: 2