In Place Pod VerticalScaling in k8 < 1.33

  • Enable feature gate InPlacePodVerticalScaling
  • enabled by default in the Kubernetes v1.33

/etc/kubernetes/manifests/kube-apiserver.yaml

nginx.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resizePolicy:
        - resourceName: cpu
          restartPolicy: NotRequired
        - resourceName: memory
          restartPolicy: NotRequired
        resources:
          limits:
            memory: "100Mi"
            cpu: "200m"
          requests:
            memory: "100Mi"
            cpu: "200m"

patch.yml [only applied to pod]

kubectl patch pod nginx-pod \
  --subresource='resize' \
  --type='strategic' \
  -p '{"spec":{"containers":[{"name":"nginx","resources":{"requests":{"memory":"2Gi"},"limits":{"memory":"2Gi"}}}]}}'
  • Check pod memory size
root@nginx-pod:/# cat /sys/fs/cgroup/memory.max
3221225472
root@nginx-pod:/# cat /sys/fs/cgroup/memory.max
4294967296

#for CPU
cat /sys/fs/cgroup/cpu.max
  • –type=merge will not work – /api/v1/namespaces/default/pods/nginx-pod and resource changes are rejected as immutable.
  • –subresource=resize hits /api/v1/namespaces/default/pods/nginx-pod/resize, which is the API added for in-place resource updates.
  • use case – Java applications often need more CPU during startup than during steady-state operation. Start with higher CPU and resize down later.

https://kubernetes.io/blog/2025/05/16/kubernetes-v1-33-in-place-pod-resize-beta/