Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide resource limits in kubernetes go client pod spec?

    Spec: v1.PodSpec{
            Containers: []v1.Container{
                v1.Container{
                    Name:            podName,
                    Image:           deploymentName,
                    ImagePullPolicy: "IfNotPresent",
                    Ports:           []v1.ContainerPort{},
                    Env: []v1.EnvVar{
                        v1.EnvVar{
                            Name:  "RASA_NLU_CONFIG",
                            Value: os.Getenv("RASA_NLU_CONFIG"),
                        },
                        v1.EnvVar{
                            Name:  "RASA_NLU_DATA",
                            Value: os.Getenv("RASA_NLU_DATA"),
                        },
                    },
                    Resources: v1.ResourceRequirements{},
                },
            },
            RestartPolicy: v1.RestartPolicyOnFailure,
        },

I want to provide resource limits as corresponding like :

resources:
  limits:
    cpu: "1"
  requests:
    cpu: "0.5"
args:
- -cpus
- "2"

How do I go on to do that. I tried adding Limits and its map key value pair but it seems to be quite a nested structure. There doesnt seem to be any example as to how to provide resources in kube client go.

like image 919
mohd.gadi Avatar asked Feb 04 '23 21:02

mohd.gadi


1 Answers

I struggled with the same when i was creating a statefulset. Maybe my codesnipped will help you:

Resources: apiv1.ResourceRequirements{
                            Limits: apiv1.ResourceList{
                                "cpu":    resource.MustParse(cpuLimit),
                                "memory": resource.MustParse(memLimit),
                            },
                            Requests: apiv1.ResourceList{
                                "cpu":    resource.MustParse(cpuReq),
                                "memory": resource.MustParse(memReq),
                            },
                        },

the vars cpuReq, memReq, cpuLimit and memLimit are supposed to be strings

like image 70
Louis Baumann Avatar answered Feb 11 '23 21:02

Louis Baumann