我正在使用 Java 客户端来获取其中一个部署的副本数。这就是我使用的方式。我的k8s版本是1.18,java kubernetes客户端版本是10.0.0
KubeClient kubeClient = new KubeClient();
kubeClient.getReplicas();
public class KubeClient {
public void getReplicas() throws IOException, ApiException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
AppsV1Api appsV1Api = new AppsV1Api(client);
V1Scale v1Scale = appsV1Api.readNamespacedDeploymentScale("mydeployment", "mynamespace", null);
System.out.println("no of replicas is : "+v1Scale.getSpec().getReplicas());
}
}
当我调用appsV1Api.readNamespacedDeploymentScale("mydeployment", "mynamespace", null);时出现异常
] |>> ... 30 more |>>
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 12395
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:188) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:146) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172) ~[gson-2.2.2.jar:?]
at com.google.gson.Gson.fromJson(Gson.java:795) ~[gson-2.2.2.jar:?]
at com.google.gson.Gson.fromJson(Gson.java:761) ~[gson-2.2.2.jar:?]
at com.google.gson.Gson.fromJson(Gson.java:710) ~[gson-2.2.2.jar:?]
at io.kubernetes.client.openapi.JSON.deserialize(JSON.java:137) ~[client-java-api-10.0.0.jar:?]
at io.kubernetes.client.openapi.ApiClient.deserialize(ApiClient.java:757) ~[client-java-api-10.0.0.jar:?]
at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:958) ~[client-java-api-10.0.0.jar:?]
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:883) ~[client-java-api-10.0.0.jar:?]
at io.kubernetes.client.openapi.apis.AppsV1Api.readNamespacedDeploymentWithHttpInfo(AppsV1Api.java:14456) ~[client-java-api-10.0.0.jar:?]
at io.kubernetes.client.openapi.apis.AppsV1Api.readNamespacedDeployment(AppsV1Api.java:14426) ~[client-java-api-10.0.0.jar:?]
at com.airwave.acp.kube.KubeClient.getRelicas(KubeClient.java:19) ~[vrf-engine-4.0.4.jar:?]
at com.airwave.svg.init.VRFEngine.init(VRFEngine.java:137) [vrf-engine-4.0.4.jar:?]
at com.airwave.svg.init.VRFEngine.main(VRFEngine.java:92) [vrf-engine-4.0.4.jar:?]
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 12395
at com.google.gson.stream.JsonReader.expect(JsonReader.java:339) ~[gson-2.2.2.jar:?]
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:322) ~[gson-2.2.2.jar:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165) ~[gson-2.2.2.jar:?]
... 30 more
但超越异常。不知道我的实现有什么问题,有人可以告诉我哪个版本的 Kubeclient 与哪个版本兼容哦 K8s