I want to serve every request to run python code in separate container/pod as it is not thread safe, how to achieve this in gke
Hello saurabhraut,
You can try to create a Deployment [1], then use HPA to automatically scale the workload to match the demands [2] and expose it with service loadbalancer [3]. To achieve one request per pod, you have to define the load request in container specification in Deployment yaml file [4].
You can consider using jobs if the pods will be disposed of after use. A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. Deleting a Job will clean up the Pods it created. Suspending a Job will delete its active Pods until the Job is resumed again.
A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example due to a node hardware failure or a node reboot).
[1] https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
[2] https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
[3] https://cloud.google.com/kubernetes-engine/docs/concepts/service#services_of_type_loadbalancer
[4] https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/