Python for reading files and requests in more than 1 pod in kubernetes Python for reading files and requests in more than 1 pod in kubernetes kubernetes kubernetes

Python for reading files and requests in more than 1 pod in kubernetes


Edit: as stated in the comments, this is not a production grade solution, just a smart way to answer your exact requirement.

You can put your app as a statefulset - each pod will get a number from 0 to your replicas number -1.

So if you'll set 3 replicas you'll have pods:

files-reader-0files-reader-1files-reader-2

Then you can pass to your pod 2 env vars:

  1. The pod name using that example: https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/inject/dapi-envars-pod.yaml
  2. The replica count which you can hardcode in your deployment files.

Then in your code read those env var, and use that formula:

FileLines / replicaCount * podNameSuffix(which is the pod number)+1

For example, for a file with 1000 lines and 10 pods, which lines should the 3rd pod read? easy:

1000 / 10 * 3 to 1000 / 10 * 3-1


You can use DaemonSet for it.

DaemonSet allows you to run the same pod on each of your cluster nodes.

https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/