kubernetes-client / java Goto Github PK
View Code? Open in Web Editor NEWOfficial Java client library for kubernetes
Home Page: http://kubernetes.io/
License: Apache License 2.0
Official Java client library for kubernetes
Home Page: http://kubernetes.io/
License: Apache License 2.0
When loading a config that looks like:
apiVersion: v1
clusters:
- cluster:
server: "192.168.1.135:8001"
name: "nuc"
Connection requests fail, because there is no protocol for the URL.
However kubectl
works properly. We should add a prefix if it is missing.
There is a Java library here:
https://github.com/betamaxteam/betamax
Similar to VCR for Ruby and VCR.py for Python.
It supports recording and playback of HTTP requests. We should consider using it to write a bunch of functional tests for this library.
on performing repeated watches on custom objects I eventually see in logs
2017-10-14 15:26:12.773 WARN 5 --- [ ConnectionPool] com.squareup.okhttp.OkHttpClient : A connection to https://10.0.0.1/ was leaked. Did you forget to close a response body?
I don't see any way to close the response body from the Watch wrappers or gain access to it to close manually.
I'm doing:
CustomObjectsApi api = new CustomObjectsApi();
Watch<Object> watch = Watch.createWatch(
client,
api.listNamespacedCustomObjectCall("xxx.yyy", "v1alpha1", "default", "mykind", null, null, rs, true, null, null),
new TypeToken<Watch.Response<Object>>(){}.getType());
When I wrote Exec I placed it in the util
directory, because I wanted everything in kubernetes
to be generated code.
When @mbohlool added Watch he placed it in kubernetes
We should only place clients in one place. This issue is to figure out where that is.
@mbohlool , @lwander I think separating generated from non-generated code is the right idea as it will make management easier in the long term. What do you think?
Thanks!
Hi,
I was getting exception when I issued deleteNamespacedStatefulSet() call. The call did delete statefulset, but it throw the exception back to caller.
Exception:
java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 2004 path $.status
Here is my code,
V1DeleteOptions deleteOptions = new V1DeleteOptions()
Boolean orphanDependents = true
apiInstance.deleteNamespacedStatefulSet(name, namespace, deleteOptions, null, 60, orphanDependents, null)
Thanks.
Reported by a user:
Hey everyone! I am having an issue running the new java-client inside a cluster. I am using
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
to acquire a client, which works locally, but I get this when the code is executed inside a cluster:
java.lang.RuntimeException: No OAuth2 authentication configured!
Hi,
'm following the document: " https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#updating-statefulsets " for updating my statefulset to use new image version (rolling update).
On issuing the command:
kubectl patch statefulset my_statefulset_name -p '{"spec":{"updateStrategy":{"type":"RollingUpdate"}}}'
Output: my_statefulset_name patched.
On issuing the command:
kubectl patch statefulset my_statefulset_name --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"my_image"}]'
Output: my_statefulset_name patched
But, nothing happens, I don't see any pods recreating with the new image mentioned. What's happening here? Where to find the logs on what's going wrong here? kubectl describe pod was not helpful.
Note: If I manually delete the pods, the new pods comes up with new image specified as part of patch command. Is this the expected behavior?
Yaml file refers to apiVersion: apps/v1beta1
Hello everybody.
I am trying to use the java client to develop a new solution on kubernetes.
But when I try to use the Example.java, after set my pom.xml on maven dependency, I get some errors.
null for gcp Exception in thread "main" io.kubernetes.client.ApiException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at io.kubernetes.client.ApiClient.execute(ApiClient.java:801) at io.kubernetes.client.apis.CoreV1Api.listPodForAllNamespacesWithHttpInfo(CoreV1Api.java:16967) at io.kubernetes.client.apis.CoreV1Api.listPodForAllNamespaces(CoreV1Api.java:16948) at br.ufpe.cin.gfads.microservice_client.Example.main(Example.java:18) Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026) at sun.security.ssl.Handshaker.process_record(Handshaker.java:961) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) at com.squareup.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192) at com.squareup.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149) at com.squareup.okhttp.internal.io.RealConnection.connect(RealConnection.java:112) at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184) at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126) at com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95) at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281) at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224) at com.squareup.okhttp.Call.getResponse(Call.java:286) at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243) at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205) at com.squareup.okhttp.Call.execute(Call.java:80) at io.kubernetes.client.ApiClient.execute(ApiClient.java:797) ... 3 more Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:397) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:302) at sun.security.validator.Validator.validate(Validator.java:260) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496) ... 23 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392) ... 29 more
I checked on my terminal, and if I ask it about my nodes, I get what is expect.:
vinicius@vinicius-VPCEG17FB:~/Documentos$ kubectl get nodes NAME STATUS ROLES AGE VERSION swarm1 Ready master 10d v1.8.0 swarm5 Ready <none> 10d v1.8.0
what is wrong?
Hi,
I have two questions.
Call `readNamespacedControllerRevision`, but get "Not Found". If I make the api call listNamespacedControllerRevision, I can get result back.
apiInstance.readNamespacedControllerRevision(name, namespace, null, null, null)
item(0).data
from result. The result only contains item(0).metadata
.apiInstance.listNamespacedControllerRevision(namespace, pretty, null, null, null, "app=abc", 10, null, 30, null)
Thanks
Hi,
I am trying to run it on v1.6.7 and get:
Exception in thread "main" java.net.SocketTimeoutException: timeout
at okio.Okio$3.newTimeoutException(Okio.java:207)
at okio.AsyncTimeout.exit(AsyncTimeout.java:261)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:215)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
at com.squareup.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
at com.squareup.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:87)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:722)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:576)
at com.squareup.okhttp.Call.getResponse(Call.java:287)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
at com.squareup.okhttp.Call.execute(Call.java:80)
at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:80)
at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:72)
at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:66)
at io.kubernetes.client.examples.LogsExample.main(LogsExample.java:49)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.read(SocketInputStream.java:204)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
... 17 more
And similar error when I am running it from maven.
This error is displayed immediately if the pod doesn't have any log or have multi containers, otherwise it is displayed after the log.
Thanks,
Assaf
Methods for:
Order should be:
$KUBECONFIG
env var$HOME/.kube/config
Hi,
When I create a DaemonSet with RollingUpdate in UpdateStrategy, does it automatically enable ControllerRevision? When do I need to make api call for createNamespacedControllerRevision
?
Thanks.
This should allow people to reference them when building custom resource proto files and building then using the Maven plugin https://github.com/xolstice/protobuf-maven-plugin
Most of the Kubernetes objects have a set of fields in common:
The objects that support this really need to reflect that by implementing an interface and possibly extending a base class.
I have a pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: my-name
spec:
...
Using kubectl
I can create this pod with:
kubectl apply -f pod.yaml
How can I do this with this java API?
My first attempt was to use createNamespacedPod
:
V1Pod pod = api.createNamespacedPod("default", podBody, "false");
My pod body I want to create:
V1ObjectMeta meta = new V1ObjectMeta();
meta.name("my-name");
V1EnvVar addr = new V1EnvVar();
addr.name("var1");
addr.value("value1");
V1EnvVar port = new V1EnvVar();
addr.name("var2");
addr.value("value2");
V1ResourceRequirements res = new V1ResourceRequirements();
Map<String, String> limits = new HashMap<>();
limits.put("cpu", "300m");
limits.put("memory", "500Mi");
res.limits(limits);
V1Container container = new V1Container();
container.name("my-name");
container.image("my-image");
container.env(Arrays.asList(addr, port));
container.resources(res);
V1PodSpec spec = new V1PodSpec();
spec.containers(Arrays.asList(container));
V1Pod podBody = new V1Pod();
podBody.apiVersion("v1");
podBody.kind("Pod");
podBody.metadata(meta);
podBody.spec(spec);
I am getting:
Exception in thread "main" io.kubernetes.client.ApiException: Unprocessable Entity
at io.kubernetes.client.ApiClient.handleResponse(ApiClient.java:882)
at io.kubernetes.client.ApiClient.execute(ApiClient.java:798)
at io.kubernetes.client.apis.CoreV1Api.createNamespacedPodWithHttpInfo(CoreV1Api.java:8223)
at io.kubernetes.client.apis.CoreV1Api.createNamespacedPod(CoreV1Api.java:8207)
EDIT: Sorry, I did not include the code that is actually causing the problem, added in the env vars and resource limits part. It works correctly when that code is not included:
Pod created when I delete:
V1EnvVar addr = new V1EnvVar();
addr.name("var1");
addr.value("value1");
V1EnvVar port = new V1EnvVar();
addr.name("var2");
addr.value("value2");
V1ResourceRequirements res = new V1ResourceRequirements();
Map<String, String> limits = new HashMap<>();
limits.put("cpu", "300m");
limits.put("memory", "500Mi");
res.limits(limits);
For example: V1beta2Deployment
My use case: I want to use the ProtoClient to create a Deployment.
TODO: Better title.
There are many optional parameters in API calls, setting them to null would make a very ugly call like:
V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
Also adding an optional parameter to an API call (in a newer version of kubernetes) is not backward compatible as it will add another parameter to API call in java and all code need to be updated for that.
I suggest we generate every possible variation of API call with regard to optional parameters, e.g.:
// Optional _continue parameter
public V1PodList listPodForAllNamespaces(String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String pretty, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException {
return this.listPodForAllNamespaces(null, fieldSelector, includeUninitialized, labelSelector, limit, pretty, resourceVersion, timeoutSeconds, watch)
}
...
// original call
public V1PodList listPodForAllNamespaces(String _continue, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String pretty, String resourceVersion, Integer timeoutSeconds, Boolean watch) throws ApiException {
...
}
cc @brendandburns @lwander any thoughts?
The code here:
https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/util/Config.java#L111
Should do a base64 decode.
Hi,
I am using createNamespacedStatefulSet(...)
api to create a new statefulset. The statefulset is created, but I am getting the following error which did not have sufficient information to tell me where is the error for me to fix. Also, what is the api for kubernetes apply
?
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'class V1beta1StatefulSet {
apiVersion: apps/v1beta1
kind: StatefulSet
metadata: class V1ObjectMeta {
...
}' with class 'io.kubernetes.client.models.V1beta1StatefulSet' to class 'io.kubernetes.client.models.AppsV1beta1Deployment'
Thanks.
This will give us a chance to test the release process again now that I've run it once. We'll likely promote this to 1.0.0-beta.1 if everything goes smoothly. I'll link to release notes & an updated version matrix here.
This issue is to track the release process of the client (on maven?).
(Edited, adding and edited action items from lwander's comment bellow)
Related to this issue in the fabric8-maven-plugin.
The watch is always done with a resource version number that is fetched from the build list (not from the actual build) on the first attempt. Everything is looked up from the new API endpoint apis/build.openshift.io
.
The error is like:
Caused by: io.fabric8.kubernetes.client.KubernetesClientException: Timeout: Too large resource version: 19393279, current: 19393278
at io.fabric8.kubernetes.client.dsl.internal.WatchConnectionManager$2.onFailure(WatchConnectionManager.java:191)
at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:543)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:185)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
From my tests, it seems that the resource version number in the list object is independent from the resource version number of the actual build object (in the new API).
So the first revision number should not be taken from the list, but from the actual build. I don't know why it is taken from the list.
Using a empty revision number should be a viable option on the first attempt to create the watch. While on a subsequent reconnection, the client should use the last revision number received from the server.
Which objects in the API are thread-safe? I assume the ApiClient is thread safe, since it is stored statically in the Configuration. Are the various API objects, such as CoreV1Api also thread-safe?
Hi everybody.
I saw in k8 tutorial that we can select the node where we want to deploy a pod. It is using the nodeSelector.
So, I am trying to change this property while my k8 application is running.
My main class has this code to set a new node selector:
`public class Test {
public static void main(String[] args) throws FileNotFoundException, ApiException {
final String podName = "etcd-swarm1";
//final String oldNode = "swarm1";
final String newNode = "swarm5";
PodAbstraction podAbstraction = new PodAbstraction(podName, newNode);
RuntimeDealer runtimeDealer = new RuntimeDealer();
V1Pod pod = runtimeDealer.searchPod(podName);
podAbstraction.updateNodeSelector(pod);
}
}`
And, my podAbstraction class, has the method updateNodeSelector(), which is:
public void updateNodeSelector(V1Pod pod) {
//System.out.println("the pod is on node : "+"\n"+pod.getSpec().toString());
pod.getSpec().setNodeSelector(this.nodeSelector);
pod.getSpec().setNodeName("swarm5");
System.out.println("and now it is on node: "+pod.getSpec().getNodeName());
}
Aparently it is now enough to make a pod leave on node to another (in my case, I am trying to move the pod
etcd-swarm1 from the node swarm1 to the node swarm5).
Finally, I got this message on my terminal after running this java-client program( I have abstracted some comands here):
vinicius@vinicius-VPCEG17FB:~/Documentos$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
etcd-swarm1 1/1 Running 0 20d 10.66.66.23 swarm1
As you can see, it has not been moved.
Does someone has any idea of how I can complete the task of moving a pod from a node to another one?
Thanks
Hi,
I try to find out if kubernetes-client java api plans to include the io.kubernetes.client.util
package in the released jar file. We would like to use some of java code.
Thanks.
I don't see this in current java's kubeconfig loader.
This is needed for many of the more advanced methods.
Hi team,
Assuming I have the JSON representation of some Kubernetes resource retrieved from the Kubernetes API server - would I be able to deserialize this into the corresponding resource in this client library? For example, would something like this work?
V1Pod v1pod = new ObjectMapper().convertValue(jsonPayload, V1Pod.class)
Poking through the generated code I don't see why not, but just wanted to make sure that this is the intended behavior.
Thanks
Required for 'bronze' level client.
We have written our custom CRD type and controller. We would like to generate Java client for that. Is there any document on how to generate java client for CRDs ?
Useful for rewriting tokens and the like.
Depends on #28
We need this for Beta release.
Hi,
When we call apiInstance.listNamespacedStatefulSet, the result only contains the apiVersion and kind under list level not each item level. Is this an expected behavior? Thanks.
class V1beta1StatefulSetList {
apiVersion: apps/v1beta1
items: [class V1beta1StatefulSet {
apiVersion: null
kind: null
....
}]
kind: StatefulSetList
metadata: class V1ListMeta {
resourceVersion: 1078833
selfLink: /apis/apps/v1beta1/namespaces/default/statefulsets
}
}
Hi,
I notice that both AppV1beta1Api (https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/AppsV1beta1Api.md#createnamespacedstatefulset) and ExtensionV1beta1Api (https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ExtensionsV1beta1Api.md#createnamespacedreplicaset) classes can access createNamespacedReplicaSet method. What are the differences and any suggestions?
Thanks.
Ignore CA root problems, required for 'bronze' certification.
Hi,
I try to update/replace the statefulset image version. Can you suggestion where I can find the supported api?
I also posted my question to slack "sig-apis-machinary". Please advise where is the best place to have my questions answered.
Thanks.
I'm thinking not jumping to 1.0.0 directly gives us more leeway in applying early fixes.
Java8 builds of the client disabled doclint due to a bug in the swagger code gen that didn't HTML-escape certain parameter descriptions.
The fix will be to revert #47 once swagger-api/swagger-codegen#6040 is merged.
We've added TPR support in gen repo. This should be as simple as generating client again, though in the process, I've found a bug in java client generator and fixed it in gen repo.
Created this issue to continue the discussion in #19
TODO(mehdy): add a summary of discussion here.
I've digged a little more and found the issue that resulted in adding POST: kubernetes/kubernetes#10366
I've also looked at kubernetes code, and GET and POST serving paths look the same (as far as I can tell).
The argument in kubernetes/kubernetes#10366 could be applied to SPDY or http/2 but not websocket. I think we should be fine with websocket GET only as the serving path is the same and there is no plan to remove GET from exec/attach/portforward serving stack in kubernetes.
Another solution for java client is to support SPDY/HTTP2 instead of websocket (we supported websocket for python client because there were no good SPDY client for python). This way we are not bounded by websocket limitation of GET.
cc: @brendandburns
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.