Skip to content

Commit f482e35

Browse files
committed
Initial draft of blog post for in-place pod resize feature
1 parent 27a0af9 commit f482e35

File tree

2 files changed

+125
-35
lines changed

2 files changed

+125
-35
lines changed

content/en/blog/_posts/2022-10-21-in-place-pod-resize-alpha.md

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
layout: blog
3+
title: "Kubernetes 1.27: In-place Resource Resize for Kubernetes Pods (alpha)"
4+
date: 2023-04-04
5+
slug: in-place-pod-resize-alpha
6+
---
7+
8+
**Author:** Vinay Kulkarni
9+
10+
Kubernetes v1.27 brings a new alpha feature that allows users to resize CPU
11+
and memory resources allocated to their pod without restarting them. The
12+
`resources` field in pod's containers are now mutable for `cpu` and `memory`
13+
resources. Additionally, a new `restartPolicy` for resize gives users control
14+
over how their containers are handled during resize.
15+
16+
Kubernetes gets the actual CPU and memory requests and limits enforced on the
17+
containers via an API call to the container runtime, and hence need support
18+
from container runtimes. The CRI (Container Runtime Interface) API changes
19+
for this feature were merged in v1.25 release.
20+
21+
## What's new in 1.27?
22+
23+
Besides the aforementioned resize policy in the pod's spec, a new field named
24+
`allocatedResources` was added to `containerStatuses` in the pod's status. This
25+
field reflects the resources allocated to the pod's containers by the node.
26+
27+
In addition, a new field called `resources` was added to the container's status.
28+
This field reflects the actual resource requests and limits that are configured
29+
on the running containers as reported by the container runtime.
30+
31+
Lastly, a new field named `resize` was added to the pod's status to show the
32+
status of the last requested resize. A value of `Proposed` is an acknowledgement
33+
of the requested resize and indicates that request was validated and recorded. A
34+
value of `InProgress` indicates that the node has accepted the resize request
35+
and is in the process of applying the resize request to the pod's containers.
36+
A value of `Deferred` means that the requested resize cannot be granted at this
37+
time, and the node will keep retrying. The resize may be granted when other pods
38+
leave and free up node resources. A value of `InFeasible` is a signal that the
39+
node cannot accommodate the requested resize. This can happen if the requested
40+
resize exceeds the maximum resources the node can ever allocate for a pod.
41+
42+
43+
## When to use this feature
44+
45+
Below are a few examples where this feature may be useful:
46+
- Pod is running on node but with either too much or too little resources.
47+
- Pods are not being scheduled do to lack of sufficient CPU or memory in a
48+
cluster that is under-utilized.
49+
- Evicting certain pods that need more resources and scheduling them on
50+
bigger nodes is an expensive or disruptive operation when other pods on
51+
the nodes can be moved.
52+
53+
54+
## How to use this feature
55+
56+
In order to use this feature in v1.27, the `InPlacePodVerticalScaling`
57+
feature gate needs to be enabled.
58+
59+
```bash
60+
root@vbuild:~/go/src/k8s.io/kubernetes# FEATURE_GATES=InPlacePodVerticalScaling=true ./hack/local-up-cluster.sh
61+
go version go1.20.2 linux/arm64
62+
+++ [0320 13:52:02] Building go targets for linux/arm64
63+
k8s.io/kubernetes/cmd/kubectl (static)
64+
k8s.io/kubernetes/cmd/kube-apiserver (static)
65+
k8s.io/kubernetes/cmd/kube-controller-manager (static)
66+
k8s.io/kubernetes/cmd/cloud-controller-manager (non-static)
67+
k8s.io/kubernetes/cmd/kubelet (non-static)
68+
...
69+
...
70+
Logs:
71+
/tmp/etcd.log
72+
/tmp/kube-apiserver.log
73+
/tmp/kube-controller-manager.log
74+
75+
/tmp/kube-proxy.log
76+
/tmp/kube-scheduler.log
77+
/tmp/kubelet.log
78+
79+
To start using your cluster, you can open up another terminal/tab and run:
80+
81+
export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig
82+
cluster/kubectl.sh
83+
84+
Alternatively, you can write to the default kubeconfig:
85+
86+
export KUBERNETES_PROVIDER=local
87+
88+
cluster/kubectl.sh config set-cluster local --server=https://localhost:6443 --certificate-authority=/var/run/kubernetes/server-ca.crt
89+
cluster/kubectl.sh config set-credentials myself --client-key=/var/run/kubernetes/client-admin.key --client-certificate=/var/run/kubernetes/client-admin.crt
90+
cluster/kubectl.sh config set-context local --cluster=local --user=myself
91+
cluster/kubectl.sh config use-context local
92+
cluster/kubectl.sh
93+
94+
```
95+
96+
97+
## Example Use Cases
98+
99+
### Cloud-based Development Environment
100+
101+
In this scenario, a developer or development teams write their code locally
102+
but build and test the code in Kubernetes pods that with consistent configs.
103+
Such pods need minimal resources when the user is writing code, but need
104+
significantly more CPU and memory when the user builds the code or runs a
105+
battery of tests. This use case can leverage in-place pod resize feature
106+
(with a help from eBPF) to quickly resize the pod's resources and avoid
107+
kernel OOM (out of memory) killer from terminating the user's processes.
108+
109+
This [KubeCon North America 2022 conference talk](https://www.youtube.com/watch?v=jjfa1cVJLwc)
110+
illustrates the use case.
111+
112+
### Java processes initialization CPU requirements
113+
114+
Some Java applications may need significantly more CPU during initialization
115+
than what is needed during normal process running times. If such
116+
applications specify CPU requests and limits suited for normal operation,
117+
they may suffer very long startup times. Such pods can request higher CPU
118+
values at the time of pod creation, and can resize down to normal running
119+
needs once the application has finished initializing.
120+
121+
122+
## References
123+
124+
TBD-placeholder
125+

0 commit comments

Comments
 (0)