我来自 Fabric8 团队。您无需从已安装 OpenShift 的主机运行目标。插件会读取您~/.kube/config
的 OpenShift 集群相关信息,并使用您的 API 令牌与 OpenShift REST API 进行交互。
Fabric8 Maven 插件已迁移到Eclipse JKube。尽管 Fabric8 Maven 插件也适用于远程 OpenShift 集群。它是相同的 Fabric8 Maven 插件,但名称和目标 OpenShift 插件不同。我会用 Eclipse JKube 的OpenShift Maven Plugin给出这个答案。你可以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
- 使用提供的凭据登录您的 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".
- 转到您的项目并发布 OpenShift Maven 插件目标:
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] ------------------------------------------------------------------------
- 访问部署到 OpenShift 中的应用程序
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 快速入门