How to deploy daemonset with different resource limits in kubernetes?

3/7/2020

I need deploy daemonset in Kubernetes, but each pod in different nodes requires different memory and cpu requests for different hardware types.

-- che yang
daemonset
kubernetes

1 Answer

3/8/2020

Since you have asked such an imprecise question, you're going to get an imprecise answer -- update your question with more specifics and you'll get a better answer

Using helm can help you with that problem, since the manifests are subject to golang template evaluation; thus:

# values.yaml
instance_type: m5.large
---
# templates/deployment.yaml
  {{ $mem := "2Gi" }}
  {{ if (hasSuffix .Values.instance_type ".xlarge") }}
  {{   $mem = "4Gi"
  {{ end }}
  spec:
    template:
      spec:
        containers:
        - resources:
             requests:
               memory: {{ $mem }}

then install it and the user can choose the size Node they have:

$ helm install --set instance_type=r5.xlarge my-release my/chart

If, instead, you mean that you have a mixed set if instances and you want your one Deployment to adjust its memory settings according to the headroom available on its target Node, then you'll want a Mutating Admission Webhook which can use whatever business rules you want to adjust the resource: field of the soon-to-be-scheduled Pod to set its resources as you see fit. You can use the vertical pod autoscaler as a source of inspiration, since they're doing roughly the same thing just over a different timescale

-- mdaniel
Source: StackOverflow