關於DeploymentConfig的思考


 為什么是deploymentconfig而不是Kubernetes的deployment

 在new-app的時候openshift直接創建了一個deploymentconfig並部署成rc,開始並不理解為什么要這么做,后來看到下面這個命令才大概明白,原因主要有兩點:

  • deploymentconfig在創建的時候通過new-app自動生成,避免直接從無到有去寫一個deployment的yaml文件,減少了出錯。
  • deployment並不具備回滾的功能,如果部署到一個版本就無法回滾到上一個版本或者更前一個版本了,而dc有個revision,同時保留了之前部署版本的配置。如下:

如果回滾可以通過下面命令

oc rollback openshift-tomcat --to-version=2
  • 創建new-app的時候除了創建dc,還會創建一個服務,名字和app名字一樣

 

如果需要在容器運行前就帶入環境變量

oc new-app openshift-tomcat --name=openshift-tomcat --env DEPLOY_MODE=stg

帶入多個

C:\minishift-1.26.1-windows-amd64>oc new-app openshift-tomcat --name=openshift-tomcat --env DEPLOY_MODE=stg  SITE=sz
warning: Cannot find git. Ensure that it is installed and in your path. Git is required to work with git repositories.
--> Found image a4dc2a4 (6 hours old) in image stream "myproject/openshift-tomcat" under tag "latest" for "openshift-tomcat"

    temp.builder.openshift.io/myproject/openshift-tomcat-3:d91ff45d
    ---------------------------------------------------------------
    Platform for building and running JEE applications on Tomcat

    Tags: builder, tomcat

    * This image will be deployed in deployment config "openshift-tomcat"
    * Port 8080/tcp will be load balanced by service "openshift-tomcat"
      * Other containers can access this service through the hostname "openshift-tomcat"

--> Creating resources ...
    deploymentconfig.apps.openshift.io "openshift-tomcat" created
    service "openshift-tomcat" created
--> Success
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/openshift-tomcat'
    Run 'oc status' to view your app.

 

容器運行中設置環境變量

C:\minishift-1.26.1-windows-amd64>oc set env dc/openshift-tomcat DEPLOY_MODE="prd"
deploymentconfig.apps.openshift.io/openshift-tomcat updated

列出環境變量

C:\minishift-1.26.1-windows-amd64>oc set env dc/openshift-tomcat --list
# deploymentconfigs/openshift-tomcat, container openshift-tomcat
DEPLOY_MODE=stg

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM