环境:OCP 3.4
注意, 这个微服务例子非常占用内存,因此至少要给运行微服务的 Node 节点分配 4G 内存。
cd ~/mygit/redhat-helloworld-msa
1. 创建一个 admin 用户,并且赋予权限 (在 Master 机器上操作)
htpasswd -b /etc/origin/master/htpasswd admin admin
oadm policy add-cluster-role-to-user admin admin
oc adm policy add-cluster-role-to-user admin admin
2. 下载微服务基础镜像 (在 MAC 机器上操作)
docker pull fabric8/java-jboss-openjdk8-jdk:1.2.1
docker pull ryanj/centos7-nodejs:6.4.0
docker pull jboss/base-jdk:8
docker pull registry.access.redhat.com/openshift3/nodejs-010-rhel7 (之前已下载)
docker pull registry.access.redhat.com/jboss-eap-7/eap70-openshift (之前已下载)
docker save -o redhat-msa-basic.tar.gz fabric8/java-jboss-openjdk8-jdk:1.2.1 ryanj/centos7-nodejs:6.4.0 jboss/base-jdk:8
scp redhat-msa-basic.tar.gz root@192.168.56.112:/opt/ose/images/
3. 加载微服务基础镜像(在 Registry 机器上操作)
cd /opt/ose/images
docker load -i redhat-msa-basic.tar.gz
docker tag fabric8/java-jboss-openjdk8-jdk:1.2.1 registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
docker push registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
docker tag ryanj/centos7-nodejs:6.4.0 registry.example.com:5000/ryanj/centos7-nodejs:6.4.0
docker push registry.example.com:5000/ryanj/centos7-nodejs:6.4.0
docker tag jboss/base-jdk:8 registry.example.com:5000/jboss/base-jdk:8
docker push registry.example.com:5000/jboss/base-jdk:8
4. 登录并创建 helloworld-msa project (在 MAC 机器上操作)oc login -u admin -p admin https://master.example.com:8443
oc new-project helloworld-msa
5. 手动构建各个微服务及镜像(在 MAC 机器上操作)
5.1 构建 hola 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/hola
cd hola/
mvn clean package
修改 Dockerfile
把 FROM fabric8/java-jboss-openjdk8-jdk:1.2.1
改成 FROM registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
oc new-build --binary --name=hola -l app=hola
oc start-build hola --from-dir=. --follow
oc new-app hola -l app=hola,hystrix.enabled=true
oc expose service hola
使能 readiness probe
oc set probe dc/hola --readiness --get-url=http://:8080/api/health
测试
http://hola-helloworld-msa.apps.example.com/api/hola
输出如下:
Hola de hola-1-molbq
5.2 构建 aloha 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/aloha
cd aloha/
mvn clean package
修改 Dockerfile
把 FROM fabric8/java-jboss-openjdk8-jdk:1.2.1
改成 FROM registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
oc new-build --binary --name=aloha -l app=aloha
oc start-build aloha --from-dir=. --follow
oc new-app aloha -l app=aloha,hystrix.enabled=true
oc expose service aloha
使能 jolokia 和 readiness probe
oc env dc/aloha AB_ENABLED=jolokia; oc patch dc/aloha -p '{"spec":{"template":{"spec":{"containers":[{"name":"aloha","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}'
oc set probe dc/aloha --readiness --get-url=http://:8080/api/health
测试
http://aloha-helloworld-msa.apps.example.com/api/aloha
输出如下:
Aloha mai aloha-3-grw22
5.3 构建 ola 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/ola
cd ola/
mvn clean package
修改 Dockerfile
把 FROM fabric8/java-jboss-openjdk8-jdk:1.2.1
改成 FROM registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
oc new-build --binary --name=ola -l app=ola
oc start-build ola --from-dir=. --follow
oc new-app ola -l app=ola,hystrix.enabled=true
oc expose service ola
使能 jolokia 和 readiness probe
oc env dc/ola AB_ENABLED=jolokia; oc patch dc/ola -p '{"spec":{"template":{"spec":{"containers":[{"name":"ola","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}'
oc set probe dc/ola --readiness --get-url=http://:8080/api/health
测试
http://ola-helloworld-msa.apps.example.com/api/ola
输出如下:
Olá de ola-3-28zue
5.4 构建 bonjour 微服务
git clone https://github.com/redhat-helloworld-msa/bonjour
cd bonjour/
npm install
修改 Dockerfile
把 FROM ryanj/centos7-nodejs:6.4.0
改成 FROM registry.example.com:5000/ryanj/centos7-nodejs:6.4.0
oc new-build --binary --name=bonjour -l app=bonjour
oc start-build bonjour --from-dir=. --follow
oc new-app bonjour -l app=bonjour
oc expose service bonjour
使能 readiness probe
oc set probe dc/bonjour --readiness --get-url=http://:8080/api/health
测试
http://bonjour-helloworld-msa.apps.example.com/api/bonjour
输出如下:
Bonjour de bonjour-2-p57za
5.5 构建 api-gateway 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/api-gateway
cd api-gateway/
mvn clean package
oc new-build --binary --name=api-gateway -l app=api-gateway
oc start-build api-gateway --from-dir=. --follow
oc new-app api-gateway -l app=api-gateway,hystrix.enabled=true
oc expose service api-gateway
使能 jolokia 和 readiness probe
oc env dc/api-gateway AB_ENABLED=jolokia; oc patch dc/api-gateway -p '{"spec":{"template":{"spec":{"containers":[{"name":"api-gateway","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}'
oc set probe dc/api-gateway --readiness --get-url=http://:8080/health
测试
http://api-gateway-helloworld-msa.apps.example.com/api
输出如下:
["Aloha mai aloha-3-1p2ox","Bonjour de bonjour-2-p57za","Hola de hola-2-mdu7z","Olá de ola-3-50nsy"]
5.6 构建 frontend 微服务
git clone https://github.com/redhat-helloworld-msa/frontend
cd frontend/
npm install
修改 Dockerfile
把 FROM registry.access.redhat.com/openshift3/nodejs-010-rhel7
改成 FROM registry.example.com:5000/openshift3/nodejs-010-rhel7
把 ENV OS_SUBDOMAIN='rhel-cdk.10.1.2.2.xip.io' \
改成 ENV OS_SUBDOMAIN='apps.example.com' \
oc new-build --binary --name=frontend -l app=frontend
oc start-build frontend --from-dir=. --follow
oc new-app frontend -l app=frontend
oc expose service frontend
测试
http://frontend-helloworld-msa.apps.example.com/
输出如下:
5.7 构建 kubeflix 微服务
oc create -f http://central.maven.org/maven2/io/fabric8/kubeflix/packages/kubeflix/1.0.17/kubeflix-1.0.17-kubernetes.yml
oc new-app kubeflix
oc expose service hystrix-dashboard --port=8080
oc policy add-role-to-user admin system:serviceaccount:helloworld-msa:turbine
使能 hystrix dashboard
oc env dc/frontend ENABLE_HYSTRIX=true
测试
http://hystrix-dashboard-helloworld-msa.apps.example.com/
输出如下:
5.8 构建 zipkin 微服务
oc create -f http://repo1.maven.org/maven2/io/fabric8/zipkin/zipkin-starter-minimal/0.0.8/zipkin-starter-minimal-0.0.8-kubernetes.yml
oc expose service zipkin-query
使能 zipkin dashboard in frontend
oc env dc/frontend ENABLE_ZIPKIN=true
测试
http://zipkin-query-helloworld-msa.apps.example.com/
参考文献:
1. https://youtu.be/SPATMHP-xw8
2. http://bit.ly/helloworldmsa
3. https://github.com/redhat-helloworld-msa
4. http://developers.redhat.com/products/cdk/docs-and-apis/
注意, 这个微服务例子非常占用内存,因此至少要给运行微服务的 Node 节点分配 4G 内存。
cd ~/mygit/redhat-helloworld-msa
1. 创建一个 admin 用户,并且赋予权限 (在 Master 机器上操作)
htpasswd -b /etc/origin/master/htpasswd admin admin
oadm policy add-cluster-role-to-user admin admin
oc adm policy add-cluster-role-to-user admin admin
2. 下载微服务基础镜像 (在 MAC 机器上操作)
docker pull fabric8/java-jboss-openjdk8-jdk:1.2.1
docker pull ryanj/centos7-nodejs:6.4.0
docker pull jboss/base-jdk:8
docker pull registry.access.redhat.com/openshift3/nodejs-010-rhel7 (之前已下载)
docker pull registry.access.redhat.com/jboss-eap-7/eap70-openshift (之前已下载)
docker save -o redhat-msa-basic.tar.gz fabric8/java-jboss-openjdk8-jdk:1.2.1 ryanj/centos7-nodejs:6.4.0 jboss/base-jdk:8
scp redhat-msa-basic.tar.gz root@192.168.56.112:/opt/ose/images/
3. 加载微服务基础镜像(在 Registry 机器上操作)
cd /opt/ose/images
docker load -i redhat-msa-basic.tar.gz
docker tag fabric8/java-jboss-openjdk8-jdk:1.2.1 registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
docker push registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
docker tag ryanj/centos7-nodejs:6.4.0 registry.example.com:5000/ryanj/centos7-nodejs:6.4.0
docker push registry.example.com:5000/ryanj/centos7-nodejs:6.4.0
docker tag jboss/base-jdk:8 registry.example.com:5000/jboss/base-jdk:8
docker push registry.example.com:5000/jboss/base-jdk:8
4. 登录并创建 helloworld-msa project (在 MAC 机器上操作)oc login -u admin -p admin https://master.example.com:8443
oc new-project helloworld-msa
5. 手动构建各个微服务及镜像(在 MAC 机器上操作)
5.1 构建 hola 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/hola
cd hola/
mvn clean package
修改 Dockerfile
把 FROM fabric8/java-jboss-openjdk8-jdk:1.2.1
改成 FROM registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
oc new-build --binary --name=hola -l app=hola
oc start-build hola --from-dir=. --follow
oc new-app hola -l app=hola,hystrix.enabled=true
oc expose service hola
使能 readiness probe
oc set probe dc/hola --readiness --get-url=http://:8080/api/health
测试
http://hola-helloworld-msa.apps.example.com/api/hola
输出如下:
Hola de hola-1-molbq
5.2 构建 aloha 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/aloha
cd aloha/
mvn clean package
修改 Dockerfile
把 FROM fabric8/java-jboss-openjdk8-jdk:1.2.1
改成 FROM registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
oc new-build --binary --name=aloha -l app=aloha
oc start-build aloha --from-dir=. --follow
oc new-app aloha -l app=aloha,hystrix.enabled=true
oc expose service aloha
使能 jolokia 和 readiness probe
oc env dc/aloha AB_ENABLED=jolokia; oc patch dc/aloha -p '{"spec":{"template":{"spec":{"containers":[{"name":"aloha","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}'
oc set probe dc/aloha --readiness --get-url=http://:8080/api/health
测试
http://aloha-helloworld-msa.apps.example.com/api/aloha
输出如下:
Aloha mai aloha-3-grw22
5.3 构建 ola 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/ola
cd ola/
mvn clean package
修改 Dockerfile
把 FROM fabric8/java-jboss-openjdk8-jdk:1.2.1
改成 FROM registry.example.com:5000/fabric8/java-jboss-openjdk8-jdk:1.2.1
oc new-build --binary --name=ola -l app=ola
oc start-build ola --from-dir=. --follow
oc new-app ola -l app=ola,hystrix.enabled=true
oc expose service ola
使能 jolokia 和 readiness probe
oc env dc/ola AB_ENABLED=jolokia; oc patch dc/ola -p '{"spec":{"template":{"spec":{"containers":[{"name":"ola","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}'
oc set probe dc/ola --readiness --get-url=http://:8080/api/health
测试
http://ola-helloworld-msa.apps.example.com/api/ola
输出如下:
Olá de ola-3-28zue
5.4 构建 bonjour 微服务
git clone https://github.com/redhat-helloworld-msa/bonjour
cd bonjour/
npm install
修改 Dockerfile
把 FROM ryanj/centos7-nodejs:6.4.0
改成 FROM registry.example.com:5000/ryanj/centos7-nodejs:6.4.0
oc new-build --binary --name=bonjour -l app=bonjour
oc start-build bonjour --from-dir=. --follow
oc new-app bonjour -l app=bonjour
oc expose service bonjour
使能 readiness probe
oc set probe dc/bonjour --readiness --get-url=http://:8080/api/health
测试
http://bonjour-helloworld-msa.apps.example.com/api/bonjour
输出如下:
Bonjour de bonjour-2-p57za
5.5 构建 api-gateway 微服务
. ~/setJdk8Env.sh
git clone https://github.com/redhat-helloworld-msa/api-gateway
cd api-gateway/
mvn clean package
oc new-build --binary --name=api-gateway -l app=api-gateway
oc start-build api-gateway --from-dir=. --follow
oc new-app api-gateway -l app=api-gateway,hystrix.enabled=true
oc expose service api-gateway
使能 jolokia 和 readiness probe
oc env dc/api-gateway AB_ENABLED=jolokia; oc patch dc/api-gateway -p '{"spec":{"template":{"spec":{"containers":[{"name":"api-gateway","ports":[{"containerPort": 8778,"name":"jolokia"}]}]}}}}'
oc set probe dc/api-gateway --readiness --get-url=http://:8080/health
测试
http://api-gateway-helloworld-msa.apps.example.com/api
输出如下:
["Aloha mai aloha-3-1p2ox","Bonjour de bonjour-2-p57za","Hola de hola-2-mdu7z","Olá de ola-3-50nsy"]
5.6 构建 frontend 微服务
git clone https://github.com/redhat-helloworld-msa/frontend
cd frontend/
npm install
修改 Dockerfile
把 FROM registry.access.redhat.com/openshift3/nodejs-010-rhel7
改成 FROM registry.example.com:5000/openshift3/nodejs-010-rhel7
把 ENV OS_SUBDOMAIN='rhel-cdk.10.1.2.2.xip.io' \
改成 ENV OS_SUBDOMAIN='apps.example.com' \
oc new-build --binary --name=frontend -l app=frontend
oc start-build frontend --from-dir=. --follow
oc new-app frontend -l app=frontend
oc expose service frontend
测试
http://frontend-helloworld-msa.apps.example.com/
输出如下:
5.7 构建 kubeflix 微服务
oc create -f http://central.maven.org/maven2/io/fabric8/kubeflix/packages/kubeflix/1.0.17/kubeflix-1.0.17-kubernetes.yml
oc new-app kubeflix
oc expose service hystrix-dashboard --port=8080
oc policy add-role-to-user admin system:serviceaccount:helloworld-msa:turbine
使能 hystrix dashboard
oc env dc/frontend ENABLE_HYSTRIX=true
测试
http://hystrix-dashboard-helloworld-msa.apps.example.com/
输出如下:
5.8 构建 zipkin 微服务
oc create -f http://repo1.maven.org/maven2/io/fabric8/zipkin/zipkin-starter-minimal/0.0.8/zipkin-starter-minimal-0.0.8-kubernetes.yml
oc expose service zipkin-query
使能 zipkin dashboard in frontend
oc env dc/frontend ENABLE_ZIPKIN=true
测试
http://zipkin-query-helloworld-msa.apps.example.com/
参考文献:
1. https://youtu.be/SPATMHP-xw8
2. http://bit.ly/helloworldmsa
3. https://github.com/redhat-helloworld-msa
4. http://developers.redhat.com/products/cdk/docs-and-apis/
没有评论:
发表评论