Mechanism to configure cpu and memory limit value dynamically

Hi Everyone,

We are looking for a mechanism to dynamically update or configure CPU and Memory values in the container resources section while applying the deployment on the Kubernetes cluster instead of static ones defined in the manifest file. Also, to achieve the same, we don’t want to create the manifest files again. We are looking for a mechanism where the CPU and memory limit can be increased and reapply the same deployment again, and this time, it should pick up the new CPU and memory limits values.

I went through some of the documentation where it says CPU and memory values should be static or should get resolved before applying the deployment to the cluster, and understand, as it’s required to identify on which node this deployment has to go based on available and requested resources. However, we want to refer these values from some Kubernetes resource objects so we can just go and update that object with new values and restart the existing deployment.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        resources:
          limits:
            memory: 512Mi 
            cpu: "1"
          requests:
            memory: 256Mi
            cpu: "0.2" 

Any help would be grateful.

Thanks