【问题标题】:Unable to generate Kubernetes manifests yaml files using JKube maven plugin无法使用 JKube maven 插件生成 Kubernetes 清单 yaml 文件
【发布时间】:2021-03-18 18:38:35
【问题描述】:

我正在尝试通过以下命令使用JKube 生成我的 Kubernetes 清单(deployment.ymlservice.yml):mvn k8s:resource

但是我收到了这个错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< io.social.carpooling:trips-api >-------------------
[INFO] Building trips-api 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.1.1:resource (default-cli) @ trips-api ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.979 s
[INFO] Finished at: 2021-03-18T19:11:24+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.1.1:resource (default-cli) on project trips-api: Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.1.1:resource failed.: NullPointerException -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

这是我的pom.xml 的样子:

<properties>
        ...
        <jkube.version>1.1.1</jkube.version>
        <jkube.generator.name>my-dockerhub-username/${project.artifactId}:${project.version}</jkube.generator.name>
        ...
</properties>
...
<plugin>
            <groupId>org.eclipse.jkube</groupId>
            <artifactId>kubernetes-maven-plugin</artifactId>
            <version>${jkube.version}</version>
            <configuration>
                <images>
                    <image>
                        <name>my-dockerhub-username/${project.artifactId}:${project.version}</name>
                    </image>
                </images>
            </configuration>
 </plugin>

我尝试使用插件文档获取更多详细信息,但没有找到太多信息。 有没有人成功生成 yaml 文件并部署到 Kubernetes 集群。

【问题讨论】:

  • 能否请您删除&lt;images&gt; 部分并重试?我认为这是由没有&lt;build&gt; 配置的&lt;image&gt; 字段引起的。这是一个错误,我们应该修复这个 NPE
  • 它不允许我重命名生成的 Docker 映像。奇怪的是,当我输入:&lt;jkube.generator.name&gt;docker.io/ghassenkhalil/${project.artifactId}:${project.version}&lt;/jkube.generator.name&gt;k8s:buildtarget/docker/carpooling/trips-api 下生成并且图像被标记为carpooing/trips-api:latest instead of ghassenkhalil/trips-api 等等时,当我执行mvn k8s:push 时,我得到:Error while trying to push the image: Unable to push 'carpooling/trips-api:latest' : denied: requested access to the resource is denied,因为carpooling/ 不是正确的路径
  • 你有一些我可以尝试的复制器项目吗?
  • @RohanKumar 这里是复制器项目的链接:github.com/ghassen1khalil/jkube-error-reproducer
  • 您好,我试用了您的复制器,但无法复制 NullPointerException。我可以看到Deployment 正在生成,但没有Service。我注意到您的Dockerfile 中没有EXPOSE 语句。您没有在 Docker 映像中公开任何端口,这就是 jkube 没有创建任何服务的原因

标签: java kubernetes nullpointerexception maven-plugin jkube


【解决方案1】:

更新

显然这是 Eclipse JKube(eclipse/jkube#624) 中的一个错误,它不允许用户在简单的 Dockerfile 模式下使用提供的属性配置图像名称。这已在新版本 v1.2.0 中得到修复。

现在您应该可以使用jkube.generator.name 配置图像名称了。您无需提供 XML 配置即可覆盖默认图像名称。之前您提供的 XML 配置没有任何导致此 NPE 的 &lt;build&gt; 配置。根据Kuberntes Maven Plugin Documentation,在提供图像 XML 配置时,此字段是必需的。 配置

我们也将在即将发布的版本中修复此 NPE(eclipse/jkube#618),以便在用户不提供映像构建时得到通知

【讨论】:

  • 您确定使用此pom.xml 可以覆盖图像名称吗?对我来说,我没有工作,它一直在target/reproducer/而不是target/ghassenkhalil下生成
  • 您好,克隆您的项目后,我只更改了 Dockerfile 以包含 EXPOSE 语句。请您再试一次mvn clean install 然后mvn k8s:build
  • 构建阶段运行没有问题,但是当我尝试使用 EXPOSE 指令生成 yaml 文件时,我收到了这个错误:[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.1.1:resource (default-cli) on project jkube-error-reproducer: Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.1.1:resource failed.: NullPointerException -&gt; [Help 1] 但是当我在下面添加一个空的 &lt;build&gt;&lt;/build&gt; &lt;image&gt; 它运行正常,但现在问题是我的 K8S 集群上的 POD 显示 CrashLoopBackOff 错误
  • 啊,奇怪。你确定和你分享的那个是同一个项目吗github.com/ghassen1khalil/jkube-error-reproducer
  • 您能否加入我们的 gitter 聊天,以便我们更好地调试您的问题:gitter.im/eclipse/jkube
猜你喜欢
  • 1970-01-01
  • 2023-03-20
  • 2016-05-04
  • 2019-05-29
  • 1970-01-01
  • 2017-10-04
  • 2019-05-31
  • 1970-01-01
  • 2020-12-27
相关资源
最近更新 更多