πŸš€ In-Place Pod Resize in Kubernetes: What You Need to Know

DRAFT This is not a complete article. I haven’t yet fully tested and vetted the steps I built. I will come back and hopefully update.

In Kubernetes v1.33, In-Place Pod Resize has entered Beta. This feature allows you to resize the CPU and memory resources of containers in a running Pod without needing to restart them. This feature is fairly nice for Power customers who scale their systems vertically. You would need to also restart the kubelet.

One no longer has to change the resource requests or limits of a pod in Kubernetes and restart the Pod. This restart was disruptive for long-running workloads.

With in-place pod resize, autoscaling workloads, improving stateful applications is a real win.

  1. Enable the InPlacePodVerticalScaling featuregate in a kind config called kind-cluster-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
featureGates:
  InPlacePodVerticalScaling: true
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: ClusterConfiguration
    apiServer:
        extraArgs:
          v: "1"
    scheduler:
        extraArgs:
          v: "1"
    controllerManager:
        extraArgs:
          v: "1"
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        v: "1"
- role: worker
  kubeadmConfigPatches:
  - |
    kind: JoinConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        v: "1"
  1. Download kind
mkdir -p dev-cache
GOBIN=$(PWD)/dev-cache/ go install sigs.k8s.io/kind@v0.29.0
  1. Start the kind cluster
KIND_EXPERIMENTAL_PROVIDER=podman dev-cache/kind create cluster \
		--image quay.io/powercloud/kind-node:v1.33.1 \
		--name test \
		--config kind-cluster-config.yaml\
		--wait 5m
  1. Create a namespace
apiVersion: v1
kind: Namespace
metadata:
  labels:
    kubernetes.io/metadata.name: resize-test
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/audit-version: v1.24
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/warn-version: v1.24
  name: resize-test
  1. Create a Pod
apiVersion: v1
kind: Pod
metadata:
  name: resize-test
spec:
  containers:
  - name: resize-test
    image: registry.access.redhat.com/ubi9/ubi
    resizePolicy:
    - resourceName: cpu
      restartPolicy: NotRequired
    - resourceName: memory
      restartPolicy: NotRequired
    resources:
      limits:
        memory: "200Mi"
        cpu: "1"
      requests:
        memory: "200Mi"
        cpu: "1"
  1. Edit kubectl edit pod/test -n resize-test
  2. Check kubectl describe pod/test -n resize-test
  3. Check oc rsh pod/test and run lscpu to see the size changed

You’ve seen how this feature functions with Kubernetes and can resize your Pod without a restart.

References

  1. Kubernetes v1.33: In-Place Pod Resize Graduated to Beta
  2. Resize CPU and Memory Resources assigned to Containers