Kubernetes官方Java客户端添加Http身份验证身份验证失败

时间:2019-04-30 07:05:10

标签: kubernetes http-proxy authenticator

我使用Kubernetes Official Java Client访问Kubernetes Api Server的其余api资源。 根据指南,一切都可以,即使我添加未经身份验证的http代理访问资源也是如此。 但是,当我添加带有身份验证的http代理时,它失败并显示

  

由以下原因引起:java.net.ProtocolException:意外的状态行:7E6       在com.squareup.okhttp.internal.http.StatusLine.parse(StatusLine.java:54)       在com.squareup.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)       在com.squareup.okhttp.internal.io.RealConnection.createTunnel(RealConnection.java:270)       在com.squareup.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:172)       在com.squareup.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)       在com.squareup.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)       在com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)       在com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)       在com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)       在com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)       在com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)       在com.squareup.okhttp.Call.getResponse(Call.java:286)       在com.squareup.okhttp.Call $ ApplicationInterceptorChain.proceed(Call.java:243)       在com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)       在com.squareup.okhttp.Call.execute(Call.java:80)       在io.kubernetes.client.ApiClient.execute(ApiClient.java:797)       ...还有4个

有人可以帮我看看如何添加kubernetes官方Java客户端的http代理授权吗?

代码示例:

KubeConfig kubeConfig = KubeConfig.loadKubeConfig(new FileReader(CREDENTIAL_PATH));
ApiClient client = ClientBuilder.kubeconfig(kubeConfig).build();
client.getHttpClient().setProxy(
        new Proxy(
                Proxy.Type.HTTP,
                new InetSocketAddress(
                        <proxyAddress>, 
                        <proxyPort>)));
client.getHttpClient().setAuthenticator(
        new Authenticator() {
                @Override
                public Request authenticate(Proxy proxy, Response response) throws IOException {
                    return null;
                }

                @Override
                public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
                    String credential = Credentials.basic(
                            <proxyAuthUsername>, 
                            <proxyAuthPassword>);
                    return response
                            .request()
                            .newBuilder()
                            .header("Proxy-Authorization", credential)
                            .build();
                }
            });
CoreV1Api api = new CoreV1Api(client);
System.out.println(api.listNode(null, null, null, null, null, null, null, null, null).getItems().size());

0 个答案:

没有答案