kubernetes-client / java

Official Java client library for kubernetes
http://kubernetes.io/
Apache License 2.0
3.55k stars 1.89k forks source link

In-place Resource Resize for Kubernetes (> 1.27) Pods is not working through Java client #3450

Open chandragm opened 4 months ago

chandragm commented 4 months ago

Describe the bug https://kubernetes.io/blog/2023/05/12/in-place-pod-resize-alpha/ In-place Resource Resize for Kubernetes (> 1.27) Pods is working when using the kubectl patch command as mentioned in the linked blog. Meaning the container's resources cpu/ memory get updated in-place without restarting or new containers being created.

I am following (https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/) to achieve similar functionality.

https://github.com/kubernetes-client/java/blob/master/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PatchExample.java

I tried PatchUtils.patch with V1Patch body: "[{ \"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/resources/limits/cpu\", \"value\": \"1\" }]"for PATCH_FORMAT_JSON_PATCH. From the documentation it says that the new pods will be created.

Would like to understand how to update in-place without the creation of new pods.

Client Version 20.0.1

Kubernetes Version Client Version: v1.29.2 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.28.3

Java Version Java 17

To Reproduce https://github.com/kubernetes-client/java/blob/master/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PatchExample.java

Try any of the patch deployment variations and you should see the pods getting created anew. Instead the pod spec has to be updated in-place.

Expected behavior Pods should not get created anew but the cpu/memory resource requests and limits get updated in-place.

KubeConfig `apiVersion: apps/v1 kind: Deployment metadata: name: inplacedemo spec: replicas: 1 selector: matchLabels: app: inplacedemo template: metadata: labels: app: inplacedemo spec: containers:

Server (please complete the following information):

Additional context I would like to achieve the equivalent of https://kubernetes.io/blog/2023/05/12/in-place-pod-resize-alpha/ using the java client.

brendandburns commented 4 months ago

Two things. 1) it appears that you are patching the Deployment, and not the Pods themselves. In place resource update only works at the pod level afaik. (though I could be wrong). You should try patching the Pods directly.

2) If that doesn't work, I would suggest that you add --v=10 to the kubectl command line, that will print out the verbose data on all of the HTTP calls that kubectl is making. That should help you get some insight into the differences between what the java client is doing and what kubectl is doing to make this work.

k8s-triage-robot commented 1 month ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 1 day ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten