微服务Demo

第5章 5.2 OpenShift Origin下快速部署JAV

2018-11-08  本文已影响75人  elef

在容器编排领域,Kubernetes的市场占有率遥遥领先。但编者认为Kubernetes是面向运维人员的分布式系统,所以Redhat公司在Kubernetes的基础上推出了OpenShift,除了支持Kubernetes原有的所有功能外,针对Paas平台的特点,对Kubernetes进行了深度开发。
文中介绍的S2I就是OpenShift之所以区别于Kubernetets,能成为PaaS平台的实现中一个主要环节。通过选择对应的image,编写assmble和run的脚本,最终生成包含依靠源代码生成的可以执行文件的docker image,并利用OpenShift现有的体系架构(BC和DC)直接发布,完成所有的应用的生命周期管理,让开发者真正仅仅关注与代码本身,这才是一个真正的Paas平台需要实现的。

Source-To-Image(S2I)是一个在创建builder image时可以独立运行的常用的工具。在OpenShiftV3里,它还是一个创建应用程序的主要手段。这篇文档就是关于如何去创建一个简单的S2I的builder image。

总的来说,S2I利用源代码和builder Docker image去生成一个新的Docker image。S2I这个项目本身其实已经包含了一些常用的Docker builder image,比如用来创建Java和Dotnet的builder image,当然你也可以根据需要去扩展它。

OpenShift 服务器,centos7,192.168.10.225
测试客户端 ,Window7,192.168.10.103

oc login -u dev -p dev

oc new-project mybank-dev --display-name="MyBank DEV" --description=" mydev"

oc new-app openshift/wildfly-100-centos7~https://github.com/nichochen/mybank-demo-maven

反馈信息如下:

--> Found Docker image 736d0ef (7 weeks old) from Docker Hub for "openshift/wildfly-100-centos7"

    WildFly 10.0.0.Final 
    -------------------- 
    Platform for building and running JEE applications on WildFly 10.0.0.Final

    Tags: builder, wildfly, wildfly10

    * An image stream will be created as "wildfly-100-centos7:latest" that will track the source image
    * A source build using source code from https://github.com/nichochen/mybank-demo-maven will be created
      * The resulting image will be pushed to image stream "mybank-demo-maven:latest"
      * Every time "wildfly-100-centos7:latest" changes a new build will be triggered
    * This image will be deployed in deployment config "mybank-demo-maven"
    * Port 8080/tcp will be load balanced by service "mybank-demo-maven"
      * Other containers can access this service through the hostname "mybank-demo-maven"

--> Creating resources ...
    imagestream "wildfly-100-centos7" created
    imagestream "mybank-demo-maven" created
    buildconfig "mybank-demo-maven" created
    deploymentconfig "mybank-demo-maven" created
    service "mybank-demo-maven" created
--> Success
    Build scheduled, use 'oc logs -f bc/mybank-demo-maven' to track its progress.
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/mybank-demo-maven' 
    Run 'oc status' to view your app.

使用帐号密码 dev/dev 登录web console


构建中
构建日志输出

再回到之前控制台输入:oc status
返回:

In project MyBank DEV (mybank-dev) on server https://127.0.0.1:8443

svc/mybank-demo-maven - 172.30.135.232:8080
  dc/mybank-demo-maven deploys istag/mybank-demo-maven:latest <-
    bc/mybank-demo-maven source builds https://github.com/nichochen/mybank-demo-maven on istag/wildfly-100-centos7:latest 
      build #1 pending for 2 seconds
    deployment #1 waiting on image or update


2 infos identified, use 'oc status -v' to see details.

上面的反馈中包含服务的集群内部地址:172.30.135.232:8080

在【OpenShift 服务器,centos7,192.168.10.225】上通过浏览器是可以访问网址: http://172.30.135.232:8080 的,但是在其他机器上是无法访问到 openshift集群的内部地址的。我还是需要在其他的测试机器上访问刚刚创建的服务。

oc expose svc/mybank-demo-maven --hostname=mybank-dev.apps.example.com

mybank-dev.apps.example.com 是我们自己虚拟出来的,需要修改机器的hosts 文件才能访问。
当前机器是【测试客户端 ,Window7,192.168.10.103】
打开 C:\Windows\System32\drivers\etc\hosts


域名映射
上一篇下一篇

猜你喜欢

热点阅读