0

I want to change the resource allocation of each pod dynamically using python client.

I tried below code but it seems doesn't change.

I searched really hard but I don't know how to...

Or is there any other API that makes this change possible?

from kubernetes import client, config
...
config.load_kube_config()
v1 = client.CoreV1Api()

  res_pods = v1.list_pod_for_all_namespaces(pretty=True)
  for i in res_pods.items:
      for j in i.spec.containers:
          if j.resources.requests or j.resources.limits:
              print(i.spec.node_name, j.name, j.resources)
              j.resources.requests["cpu"] = ... # want to change 

Thanks!

juliysys
  • 1
  • 1
  • I guess you're changing the resources of pods that are managed by deployment/statefulset. Your changes are getting overwritten by the deployment/statefulset controller. – Kamol Hasan Apr 11 '22 at 06:00
  • Then, is the change applied? or Do I need to do another way(such as using other API) to change resources? I am really beginner. Thanks! – juliysys Apr 11 '22 at 06:19
  • Instead of changing the pod's resources, change the deployments/statefulsets resources. – Kamol Hasan Apr 11 '22 at 07:18
  • Is there any link that I can refer to? Thanks! – juliysys Apr 11 '22 at 19:12

0 Answers0