JcaPEMKeyConverter 由 BouncyCastle 提供,是一个可选依赖项。要使用对 EC 密钥的支持,您必须显式添加对类路径的依赖项

Hon*_*iao 5 java kubernetes apache-flink k3s k3d

我有一个简单的 Flink 流应用程序。在通过命令创建的集群中运行良好start-cluster.sh

\n

现在根据Flink 教程,我希望将其以应用程序模式原生部署在 macOS 上k3d创建的 Kubernetes 集群中。

\n

首先,我通过创建一个集群k3d cluster create dev

\n

这是我的Dockerfile

\n
FROM flink\nRUN mkdir -p $FLINK_HOME/usrlib\nCOPY target/streaming-0.1.jar $FLINK_HOME/usrlib/streaming-0.1.jar\n
Run Code Online (Sandbox Code Playgroud)\n

我构建了它并将其推送到 Docker Hub。

\n

我的集群名称是k3d-dev,所以我跑了

\n
flink run-application \\\n    --target kubernetes-application \\\n    -Dkubernetes.cluster-id=k3d-dev \\\n    -Dkubernetes.container.image=hongbomiao/my-flink-xxx:latest \\\n    local:///opt/flink/usrlib/streaming-0.1.jar\n\n
Run Code Online (Sandbox Code Playgroud)\n

但是,我得到了错误:

\n
 The program finished with the following exception:\n\nio.fabric8.kubernetes.client.KubernetesClientException: JcaPEMKeyConverter is provided by BouncyCastle, an optional dependency. To use support for EC Keys you must explicitly add this dependency to classpath.\n    at io.fabric8.kubernetes.client.internal.CertUtils.handleECKey(CertUtils.java:161)\n    at io.fabric8.kubernetes.client.internal.CertUtils.loadKey(CertUtils.java:131)\n    at io.fabric8.kubernetes.client.internal.CertUtils.createKeyStore(CertUtils.java:111)\n    at io.fabric8.kubernetes.client.internal.CertUtils.createKeyStore(CertUtils.java:243)\n    at io.fabric8.kubernetes.client.internal.SSLUtils.keyManagers(SSLUtils.java:128)\n    at io.fabric8.kubernetes.client.internal.SSLUtils.keyManagers(SSLUtils.java:122)\n    at io.fabric8.kubernetes.client.utils.HttpClientUtils.createHttpClient(HttpClientUtils.java:82)\n    at io.fabric8.kubernetes.client.utils.HttpClientUtils.createHttpClient(HttpClientUtils.java:62)\n    at io.fabric8.kubernetes.client.BaseClient.<init>(BaseClient.java:51)\n    at io.fabric8.kubernetes.client.DefaultKubernetesClient.<init>(DefaultKubernetesClient.java:105)\n    at org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory.fromConfiguration(FlinkKubeClientFactory.java:102)\n    at org.apache.flink.kubernetes.KubernetesClusterClientFactory.createClusterDescriptor(KubernetesClusterClientFactory.java:61)\n    at org.apache.flink.kubernetes.KubernetesClusterClientFactory.createClusterDescriptor(KubernetesClusterClientFactory.java:39)\n    at org.apache.flink.client.deployment.application.cli.ApplicationClusterDeployer.run(ApplicationClusterDeployer.java:63)\n    at org.apache.flink.client.cli.CliFrontend.runApplication(CliFrontend.java:213)\n    at org.apache.flink.client.cli.CliFrontend.parseAndRun(CliFrontend.java:1057)\n    at org.apache.flink.client.cli.CliFrontend.lambda$main$10(CliFrontend.java:1132)\n    at org.apache.flink.runtime.security.contexts.NoOpSecurityContext.runSecured(NoOpSecurityContext.java:28)\n    at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1132)\n
Run Code Online (Sandbox Code Playgroud)\n

看完之后

\n\n

我添加了

\n
<dependency>\n    <groupId>org.bouncycastle</groupId>\n    <artifactId>bcpkix-jdk15on</artifactId>\n    <version>1.69</version>\n</dependency>\n<dependency>\n    <groupId>org.bouncycastle</groupId>\n    <artifactId>bcprov-jdk15on</artifactId>\n    <version>1.69</version>\n</dependency>\n<dependency>\n    <groupId>org.bouncycastle</groupId>\n    <artifactId>bcprov-ext-jdk15on</artifactId>\n    <version>1.69</version>\n</dependency>\n
Run Code Online (Sandbox Code Playgroud)\n

到我的pom.xml文件。我再次构建并推送到 Docker Hub。

\n

当我运行上面的 Flink 命令时,我仍然遇到同样的错误。任何想法?谢谢!

\n
\n

更新1:

\n

除了上面的pom.xml更改之外,我还手动下载了这 3 个 jar 并将我的 Dockerfile 更改为

\n
FROM flink\nCOPY lib/* $FLINK_HOME/lib\nRUN mkdir -p $FLINK_HOME/usrlib\nCOPY target/streaming-0.1.jar $FLINK_HOME/usrlib/streaming-0.1.jar\n
Run Code Online (Sandbox Code Playgroud)\n

并再次尝试,但仍然出现同样的错误。

\n

我可以确认 3 个 jar 文件bcpkix-jdk15on-1.69.jar, bcprov-ext-jdk15on-1.69.jar,bcprov-jdk15on-1.69.jar位于 docker 镜像中:

\n
\xe2\x9e\x9c docker run -it 6c48af48db55c334003a307d1ef7a5fc5181f389613284b66b5cb97588b9708d sh\n\n$ cd lib && ls\nbcpkix-jdk15on-1.69.jar      flink-dist_2.12-1.13.2.jar     flink-table_2.12-1.13.2.jar  log4j-slf4j-impl-2.12.1.jar\nbcprov-ext-jdk15on-1.69.jar  flink-json-1.13.2.jar      log4j-1.2-api-2.12.1.jar\nbcprov-jdk15on-1.69.jar      flink-shaded-zookeeper-3.4.14.jar  log4j-api-2.12.1.jar\nflink-csv-1.13.2.jar         flink-table-blink_2.12-1.13.2.jar  log4j-core-2.12.1.jar\n$ cd ../usrlib && ls\nstreaming-0.1.jar\n
Run Code Online (Sandbox Code Playgroud)\n
\n

更新2:

\n

我尝试通过以下方式启动会话模式

\n
/usr/local/Cellar/apache-flink/1.13.1/libexec/bin/kubernetes-session.sh\n
Run Code Online (Sandbox Code Playgroud)\n

但仍然遇到同样的错误。所以现在我可以确认,当我之前使用应用程序模式时,问题与我的 Docker 镜像无关。

\n

~/.m2我的机器上有这些罐子:

\n

在此输入图像描述

\n

我错过了其他罐子吗?

\n

另外,我发现该错误仅发生在 k3d/k3s 创建的集群上,而不会发生在 minikube 上。

\n

Hon*_*iao 5

长话短说

从以下位置下载最新版本的bcprov-jdk15onbcpkix-jdk15onjar 文件

然后移动到您的 apache-flink 文件夹。就我而言,是

/usr/local/Cellar/apache-flink/{version}/libexec/lib
Run Code Online (Sandbox Code Playgroud)

那么你就可以出发了!


我是怎么发现的

检查完代码后

  • /usr/local/Cellar/apache-flink/1.13.1/libexec/bin/kubernetes-session.sh
  • /usr/local/Cellar/apache-flink/1.13.1/libexec/libexec/kubernetes-session.sh

第一个脚本指向第二个脚本,第二个脚本有

# ...
CC_CLASSPATH=`manglePathList $(constructFlinkClassPath):$INTERNAL_HADOOP_CLASSPATHS`

# ...
"$JAVA_RUN" $JVM_ARGS -classpath "$CC_CLASSPATH" $log_setting org.apache.flink.kubernetes.cli.KubernetesSessionCli "$@"
Run Code Online (Sandbox Code Playgroud)

我添加了echo $CC_CLASSPATH,并打印出了类路径。

就我而言,它位于/usr/local/Cellar/apache-flink/1.13.1/libexec/lib

bcprov-jdk15on-1.69.jarbcpkix-jdk15on-1.69.jar放入上面的文件夹后,Flink 现在可以在会话和应用程序模式下部署到 k3s(k3d)。