当前位置: 首页 > 知识库问答 >
问题:

Maven/Fabric8-针对远程OpenShift安装构建OpenShift容器映像

韩自怡
2023-03-14

有了Docker,我只需要提供Docker_主机和适当的凭据,fabric8插件就可以构建我的容器映像。只要Docker注册表可用,就不需要在生成映像的实际主机上安装Docker相关的基础设施(例如my Bambole agent)。

使用OpenShift,我似乎找不到这样做的方法。相反,我似乎必须在安装了OpenShift的主机上运行maven goals,该主机必须是RedHat Linux主机。

这似乎比实际情况复杂得多。我是不是遗漏了什么?

在OpenShift模式下,是否有方法从fabric8 maven插件引用远程OpenShift环境?

谢谢你,罗宾。

共有1个答案

翟鹏
2023-03-14

我是Fabric8队的。您不需要从安装了OpenShift的主机上运行目标。插件读取您的~/。kube/config获取与OpenShift集群相关的信息,并使用API令牌与OpenShift REST API交互。

Fabric8 Maven插件已经迁移到EclipseJkube。尽管Fabric8 Maven插件在远程OpenShift集群上也可以正常工作。这是同一个Fabric8 Maven插件,但有不同的名称和目标OpenShift插件。我会用EclipseJkube的OpenShift Maven插件给出这个答案。你可以把它放在你的pom里。xml如下所示:

<dependency>
  <groupId>org.eclipse.jkube</groupId>
  <artifactId>openshift-maven-plugin</artifactId>
  <version>1.0.0</version>
  <type>maven-plugin</type>
</dependency>

下面是一个使用简单随机生成器应用程序的演示:https://github.com/rohanKanojia/eclipse-jkube-demo-project

  1. 使用提供的凭据登录到OpenShift群集:
~ : $ oc login https://your-cluster.openshift.com--token=your-token
Logged into "https://your-cluster.openshift.com:443" as "rohanKanojia" using the token provided.

You have one project on this server: "rokumar"

Using project "rokumar".
eclipse-jkube-demo-project : $ mvn package oc:build oc:resource oc:apply
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< meetup:random-generator >-----------------------
[INFO] Building random-generator 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ random-generator ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ random-generator ---

...

[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ random-generator ---
[INFO] Building jar: /home/rohaan/work/repos/eclipse-jkube-demo-project/target/random-generator-0.0.1.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.3.3.RELEASE:repackage (repackage) @ random-generator ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- openshift-maven-plugin:1.0.1-SNAPSHOT:build (default-cli) @ random-generator ---
[INFO] oc: Using OpenShift build with strategy S2I
[INFO] oc: Running in OpenShift mode
[INFO] oc: Running generator spring-boot
[INFO] oc: spring-boot: Using Docker image quay.io/jkube/jkube-java-binary-s2i:0.0.8 as base / builder
[INFO] oc: [random-generator:0.0.1] "spring-boot": Created docker source tar /home/rohaan/work/repos/eclipse-jkube-demo-project/target/docker/random-generator/0.0.1/tmp/docker-build.tar
[INFO] oc: Adding to Secret pullsecret-jkube
[INFO] oc: Using Secret pullsecret-jkube
[INFO] oc: Creating BuildServiceConfig random-generator-s2i for Source build
[INFO] oc: Adding to ImageStream random-generator
[INFO] oc: Starting Build random-generator-s2i
[INFO] oc: Waiting for build random-generator-s2i-1 to complete...
[INFO] oc: Using quay.io/jkube/jkube-java-binary-s2i:0.0.8 as the s2i builder image
[INFO] oc: INFO S2I source build with plain binaries detected
[INFO] oc: INFO S2I binary build from fabric8-maven-plugin detected
[INFO] oc: INFO Copying binaries from /tmp/src/deployments to /deployments ...
[INFO] oc: random-generator-0.0.1.jar
[INFO] oc: INFO Copying deployments from deployments to /deployments...
[INFO] oc: '/tmp/src/deployments/random-generator-0.0.1.jar' -> '/deployments/random-generator-0.0.1.jar'
[INFO] oc: INFO Cleaning up source directory (/tmp/src)
[INFO] oc: 
[INFO] oc: Pushing image 172.30.39.149:5000/rokumar/random-generator:0.0.1 ...
[INFO] oc: Pushed 0/4 layers, 19% complete
[INFO] oc: Pushed 1/4 layers, 25% complete
[INFO] oc: Push successful
[INFO] oc: Build random-generator-s2i-1 in status Complete
[INFO] oc: Found tag on ImageStream random-generator tag: sha256:51756e1ff9b639c939f3c0c9246ab4ed924faa269bc9cbf05035c859d19fa50c
[INFO] oc: ImageStream random-generator written to /home/rohaan/work/repos/eclipse-jkube-demo-project/target/random-generator-is.yml
[INFO] 
[INFO] --- openshift-maven-plugin:1.0.1-SNAPSHOT:resource (default-cli) @ random-generator ---
[INFO] oc: Using docker image name of namespace: rokumar
[INFO] oc: Running generator spring-boot
[INFO] oc: spring-boot: Using Docker image quay.io/jkube/jkube-java-binary-s2i:0.0.8 as base / builder
[INFO] oc: jkube-controller: Adding a default DeploymentConfig
[INFO] oc: jkube-service: Adding a default service 'random-generator' with ports [8080]
[INFO] oc: jkube-healthcheck-spring-boot: Adding readiness probe on port 8080, path='/actuator/health', scheme='HTTP', with initial delay 10 seconds
[INFO] oc: jkube-healthcheck-spring-boot: Adding liveness probe on port 8080, path='/actuator/health', scheme='HTTP', with initial delay 180 seconds
[INFO] oc: jkube-revision-history: Adding revision history limit to 2
[INFO] oc: validating /home/rohaan/work/repos/eclipse-jkube-demo-project/target/classes/META-INF/jkube/openshift/random-generator-service.yml resource
[INFO] oc: validating /home/rohaan/work/repos/eclipse-jkube-demo-project/target/classes/META-INF/jkube/openshift/random-generator-route.yml resource
[INFO] oc: validating /home/rohaan/work/repos/eclipse-jkube-demo-project/target/classes/META-INF/jkube/openshift/random-generator-deploymentconfig.yml resource
[INFO] 
[INFO] --- openshift-maven-plugin:1.0.1-SNAPSHOT:apply (default-cli) @ random-generator ---
[INFO] oc: Using OpenShift at https://api.rh-idev.openshift.com:443/ in namespace rokumar with manifest /home/rohaan/work/repos/eclipse-jkube-demo-project/target/classes/META-INF/jkube/openshift.yml 
[INFO] oc: OpenShift platform detected
[INFO] oc: Using project: rokumar
[INFO] oc: Creating a Service from openshift.yml namespace rokumar name random-generator
[INFO] oc: Created Service: target/jkube/applyJson/rokumar/service-random-generator.json
[INFO] oc: Creating a DeploymentConfig from openshift.yml namespace rokumar name random-generator
[INFO] oc: Created DeploymentConfig: target/jkube/applyJson/rokumar/deploymentconfig-random-generator.json
[INFO] oc: Creating Route rokumar:random-generator host: null
[INFO] oc: HINT: Use the command `oc get pods -w` to watch your pods start up
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:02 min
[INFO] Finished at: 2020-09-29T10:57:34+05:30
[INFO] ------------------------------------------------------------------------
eclipse-jkube-demo-project : $ oc get routes
NAME                      HOST/PORT                                                        PATH      SERVICES                  PORT      TERMINATION   WILDCARD
random-generator          random-generator-rokumar.b6ff.rh-idev.openshiftapps.com                    random-generator          8080                    None
weather-web-application   weather-web-application-rokumar.b6ff.rh-idev.openshiftapps.com             weather-web-application   8080                    None
eclipse-jkube-demo-project : $ curl random-generator-rokumar.b6ff.rh-idev.openshiftapps.com/random | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    45    0    45    0     0     56      0 --:--:-- --:--:-- --:--:--    56
{
  "id": "d79ca3fd-4505-43d1-9920-a39ac15a3b49"
}

有关更多信息,您可以查看Eclipse JKube快速入门

 类似资料:
  • 我正在尝试使用令牌调用远程构建。它给了我401。根据我的理解,token不需要。 我在这里缺少什么?

  • 问题内容: 我通过阅读本教程安装了预构建版本。如果我启动elasticsearch,则会收到以下错误消息,我应该尝试旧版本的ES还是解决该问题? 问题答案: 您尝试将ES分配给已使用的端口8080。从那里的配置的罪魁祸首是。只需将两个配置都保留在配置之外,或为envvar分配其他端口。ES的默认端口是http和9300的9200。

  • 我试图使用Fabric8 Maven插件部署示例项目。https://github.com/jbossdemocentral/katacoda-fuse-getting-started.git 我在远程机器中有一个启动并运行的Openshift环境,我正在使用“oc登录…”连接到它 本地开发机器设置:有docker,maven。已安装oc。 当我从命令提示符下运行示例项目“mvn fabric8:

  • 我对OpenShift有点陌生,我已经安装了一个主节点和多个节点(现在已删除此设置)。 现在我需要更高的可靠性,所以我现在准备用三个主机和两个节点来启动我的主机。 我有一个dns、一个dhcp和一个etcd2集群,并使用主机的特定条目运行,例如: < li>openshift-router(外部和内部访问,将作为LB与HAproxy一起使用) < li>openshift-etcd1 < li>o

  • 问题内容: 我正在尝试在OpenShift上安装python软件包,但是我看不到有关执行此操作的最佳方法的页面。有人可以建议最好的话语和交流方式吗。我尝试将它们包含在中,但我不知道它们是否实际可用,或者我必须上载并指向路径。我怎样才能做到这一点? 问题答案: 您安装了(由OpenShift.com制造)吗? 如果没有,请参见OpenShift.com:安装OpenShift RHC客户端工具 现在

  • 然而,我正试图使它在Windows10中工作,但没能做到。Windows 10中的等价物是什么?