天天看點

OpenShift 4 之在不同的項目之間推送Image

本問示範将應用容器從OpenShift的Development環境晉級到QA環境。這種場景主要适合Development環境和QA環境都使用一個相同的Internal Registry.。

OpenShift 4 之在不同的項目之間推送Image
  1. 用一般使用者建立兩個的項目,一個作為開發環境,一個作為測試環境。
$ oc new-project my-dev
$ oc new-project my-qa
           
  1. 執行以下指令允許在“my-qa”項目中從“my-dev”拉鏡像。
$ oc policy add-role-to-group system:image-puller system:serviceaccounts:my-qa -n my-dev
           
  1. 在自己的Github Repositoy中fork一份https://github.com/liuxiaoyu-git/php-helloworld應用代碼。
  2. 在”my-dev”環境中以https://github.com/YOUR-GIT/php-helloworld為源建立名為php-helloworld的PHP應用。
$ oc new-app openshift/php~https://github.com/YOUR-GIT/php-helloworld -n my-dev
$ oc expose svc php-helloworld -n my-dev
$ curl $(oc get route php-helloworld -o template --template '{{.spec.host}}' -n my-dev)
           
  1. 執行以下指令檢視ImageStream,然後找到ImageId。
$ oc describe is php-helloworld -n my-dev
......
# 在輸出結果中的以下部分就是ImageId
[email protected]:93d61fe0832cdebae490278fc3b38ae4c6c43c399253a16a6e5aa4f7d65bfe95
           
  1. 運作以下指令對鏡像打一個新的标簽。
$ oc tag my-dev/php-helloworld:latest my-qa/php-helloworld:promote-qa -n my-dev
           
  1. 執行以下指令,根據my-qa項目中的容器鏡像在my-qa項目中建立一個新的應用。
$ oc new-app my-qa/php-helloworld:promote-qa -n my-qa
$ oc expose svc php-helloworld -n my-qa
$ curl $(oc get route php-helloworld -o template --template '{{.spec.host}}' -n my-qa)
           
  1. 檢視兩個項目php-helloworld的ImageStream配置,确認此時兩個ImageStream指向的ImageId是相同的。
$ oc describe is php-helloworld -n my-dev
$ oc describe is php-helloworld -n my-qa
           
  1. 修改YOUR-GIT上的應用源碼,然後在my-dev項目的php-helloworld啟動一個新的Build。在Build成功後可驗證此時my-dev境和my-qa環境部署的應用不會互相影響。
$ curl $(oc get route php-helloworld -o template --template '{{.spec.host}}' -n my-dev)
$ curl $(oc get route php-helloworld -o template --template '{{.spec.host}}' -n my-qa)
           
  1. 再次執行(8),确認此時兩個ImageStream指向的ImageId已經不相同了。