在容器編排領(lǐng)域,Kubernetes的市場占有率遙遙領(lǐng)先。但編者認(rèn)為Kubernetes是面向運(yùn)維人員的分布式系統(tǒng),所以Redhat公司在Kubernetes的基礎(chǔ)上推出了OpenShift,除了支持Kubernetes原有的所有功能外,針對Paas平臺的特點(diǎn),對Kubernetes進(jìn)行了深度開發(fā)。
文中介紹的S2I就是OpenShift之所以區(qū)別于Kubernetets,能成為PaaS平臺的實(shí)現(xiàn)中一個主要環(huán)節(jié)。通過選擇對應(yīng)的image,編寫assmble和run的腳本,最終生成包含依靠源代碼生成的可以執(zhí)行文件的docker image,并利用OpenShift現(xiàn)有的體系架構(gòu)(BC和DC)直接發(fā)布,完成所有的應(yīng)用的生命周期管理,讓開發(fā)者真正僅僅關(guān)注與代碼本身,這才是一個真正的Paas平臺需要實(shí)現(xiàn)的。
Source-To-Image(S2I)是一個在創(chuàng)建builder image時可以獨(dú)立運(yùn)行的常用的工具。在OpenShiftV3里,它還是一個創(chuàng)建應(yīng)用程序的主要手段。這篇文檔就是關(guān)于如何去創(chuàng)建一個簡單的S2I的builder image。
總的來說,S2I利用源代碼和builder Docker image去生成一個新的Docker image。S2I這個項(xiàng)目本身其實(shí)已經(jīng)包含了一些常用的Docker builder image,比如用來創(chuàng)建Java和Dotnet的builder image,當(dāng)然你也可以根據(jù)需要去擴(kuò)展它。
- 測試環(huán)境:
OpenShift 服務(wù)器,centos7,192.168.10.225
測試客戶端 ,Window7,192.168.10.103
基礎(chǔ)鏡像
https://hub.docker.com/r/openshift/wildfly-100-centos7/Java項(xiàng)目源碼
https://github.com/nichochen/mybank-demo-maven創(chuàng)建項(xiàng)目和mybank應(yīng)用
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.
上面的反饋中包含服務(wù)的集群內(nèi)部地址:172.30.135.232:8080
在【OpenShift 服務(wù)器,centos7,192.168.10.225】上通過瀏覽器是可以訪問網(wǎng)址: http://172.30.135.232:8080 的,但是在其他機(jī)器上是無法訪問到 openshift集群的內(nèi)部地址的。我還是需要在其他的測試機(jī)器上訪問剛剛創(chuàng)建的服務(wù)。
- 給服務(wù)指定域名,便于外部訪問
oc expose svc/mybank-demo-maven --hostname=mybank-dev.apps.example.com
- 本地域名映射
mybank-dev.apps.example.com 是我們自己虛擬出來的,需要修改機(jī)器的hosts 文件才能訪問。
當(dāng)前機(jī)器是【測試客戶端 ,Window7,192.168.10.103】
打開 C:\Windows\System32\drivers\etc\hosts

-
打開瀏覽器,輸入域名 mybank-dev.apps.example.com
httpmybank-dev.apps.example.com.jpg
