Sunday, 26 April 2026

Update Deployment Resource Allocation in AKS with Kubectl

 Sometimes we might have to update resource allocations (memory and CPU) in AKS deployed apps without full redeployment. In such cases we can easly use kubectl to patch the deployment so it increase or reduce resources as we need it and gradually apply to running pods by restartting them gracefully. Let's see how.

For example let's take a video processor currently running with 12Gi of memery limit and request setup as sown below.


We need to reduce them memory limit to 8Gi. To do that we can use below command. Note that here we set CPU as well but it is not required unless you want to change it.

kubectl patch deployment video-messageprocessor \
  -n mynamespace \
  --type='json' \
  -p='[
    {"op": "replace", "path": "/spec/template/spec/containers/0/resources/limits/memory", "value": "8Gi"},
    {"op": "replace", "path": "/spec/template/spec/containers/0/resources/requests/memory", "value": "8Gi"},
    {"op": "replace", "path": "/spec/template/spec/containers/0/resources/requests/cpu", "value": "2"}
  ]'


Once applied the memory change,  we can see a new pod(s) comes up and existing pod(s) will evetually terminated gracefully.


The new pod now has 8Gi memory setup.


No comments:

Popular Posts