配置好用戶權限以後就能夠部署應用了oc經常使用的兩種部署方式:node
Deploy Image方式nginx
優勢:這種方式是最簡單的部署方式,你只須要有一個容器鏡像就好了或者公開的docker hub 鏡像git
缺點:可是這種方式的肯定是不能隨時變動,也不能提早定義其餘配置web
比較適合部署那些不常常變動的第三方服務docker
catalog方式(template)數據庫
優勢:能夠基於模板提早定義各類配置包括build、service、deployments等vim
缺點:一個類型的應用須要獨立的模板api
比較適合本身開發的應用使用,使用template能夠省去上線新應用的時間app
oc的catalog裏面包括大量的模板經常使用的一些數據庫一些開發環境都有dom
下面主要說一下自定義個模板怎麼建立
# vim nginx-openresty.yaml apiVersion: template.openshift.io/v1 kind: Template metadata: annotations: description: OpenResty(又稱:ngx_openresty) 是一個基於 NGINX 的可伸縮的 Web 平臺,由中國人章亦春發起,提供了不少高質量的第三方模塊。 tags: nodejs creationTimestamp: 2018-10-10T07:17:57Z name: nginx-openresty namespace: openshift resourceVersion: "71699318" selfLink: /apis/template.openshift.io/v1/namespaces/openshift/templates/nginx-openresty uid: 9d1b5626-cc5c-11e8-a187-00163e0e008f objects: - apiVersion: v1 kind: Route metadata: name: ${APP_NAME} spec: host: ${DOMAIN_NAME} to: kind: Service name: ${APP_NAME} - apiVersion: v1 kind: Service metadata: name: ${APP_NAME} spec: ports: - name: ${APP_NAME} port: 8080 targetPort: 8080 selector: name: ${APP_NAME} type: ClusterIP - apiVersion: v1 kind: ImageStream metadata: name: ${APP_NAME} - apiVersion: v1 kind: BuildConfig metadata: labels: name: ${APP_NAME} name: ${APP_NAME} spec: output: to: kind: ImageStreamTag name: ${APP_NAME}:latest postCommit: {} resources: {} runPolicy: Serial source: contextDir: / git: ref: ${APP_SOURCE_REPOSITORY_REF} uri: ${APP_SOURCE_REPOSITORY_URL} sourceSecret: name: gitlab-user type: Git strategy: sourceStrategy: env: - name: env value: ${ENV} - name: Project_Name value: ${APP_NAME} from: kind: ImageStreamTag name: ${APP_BUILDER_IMAGE} namespace: openshift type: Source triggers: - imageChange: {} - type: ImageChang - apiVersion: v1 kind: DeploymentConfig metadata: labels: name: ${APP_NAME} name: ${APP_NAME} spec: replicas: 1 selector: name: ${APP_NAME} strategy: customParams: command: - /bin/sh - -c - sleep 5; echo slept for 5; /usr/bin/openshift-deploy type: Rolling template: metadata: labels: name: ${APP_NAME} spec: containers: - env: - name: ETCD_URL value: ${ETCD_URL} - name: env value: ${ENV} - name: NODE_ENV value: container image: ${APP_NAME}:latest livenessProbe: failureThreshold: 3 httpGet: path: /status port: 80 scheme: HTTP initialDelaySeconds: 20 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 3 name: ${APP_NAME} ports: - containerPort: 8080 protocol: TCP readinessProbe: failureThreshold: 3 httpGet: path: /status port: 80 scheme: HTTP initialDelaySeconds: 10 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 3 resources: limits: cpu: ${CPU_LIMIT} memory: ${MEMORY_LIMIT} requests: cpu: 50m memory: 64Mi volumeMounts: - mountPath: /opt/configration name: configration - mountPath: /etc/localtime name: localtime - mountPath: /etc/timezone name: timezone volumes: - configMap: defaultMode: 420 name: configration name: configration - hostPath: path: /etc/localtime name: localtime - hostPath: path: /etc/timezone name: timezone test: false triggers: - imageChangeParams: automatic: true containerNames: - ${APP_NAME} from: kind: ImageStreamTag name: ${APP_NAME}:latest type: ImageChange - type: ConfigChange parameters: - description: 項目名 displayName: Name name: APP_NAME required: true - description: 對外暴露域名 displayName: Project domain name name: DOMAIN_NAME required: true - description: 請輸入Git地址.僅支持HTTP方式. displayName: Source Repository URL name: APP_SOURCE_REPOSITORY_URL required: true value: http://git.xxx.cn/ops/nginx-config.git - description: git倉庫的默認分支或者版本號 displayName: Git Reference name: APP_SOURCE_REPOSITORY_REF required: true value: config-a - description: git倉庫的路徑 displayName: Context Directory name: CONTEXT_DIR value: / - description: 設定當前環境,好比test、bts displayName: ENV name: ENV required: true - description: build 時使用的基礎鏡像 displayName: Base builder image of your app name: APP_BUILDER_IMAGE required: true value: openresty:1.11.2.3 - description: 超過此請求額度會被強制重啓.單位Mi/Gi. displayName: Memory Limits name: MEMORY_LIMIT required: true value: 64Mi - description: 超過此請求額度會被強制重啓.單位m/g. displayName: CPU Limits name: CPU_LIMIT required: true value: 50m
下一步導入到oc catalog裏面
# oc project openshift
# oc oc create -f nginx-openresty.yaml
在登錄oc的web console 就可使用nginx-openresty模板部署應用了
deployment顧名思義是最終部署應用的重要環節,包括了變動策略、最終POD的運行配置等關鍵信息
這個是部署應用是的變動策略一共有三種策略
Rolling(滾動升級)
spec: strategy: rollingParams: intervalSeconds: 1 maxSurge: 25% maxUnavailable: 25% timeoutSeconds: 600 updatePeriodSeconds: 1 type: Rolling
Recreate(從新建立)
spec:
strategy:
type: Recreate
Custom(自定義)
不經常使用
這個配置決定了什麼狀況下Deployment 纔會觸發
ImageChange 鏡像變動
ConfigChange Deployment 配置變動
spec: triggers: - imageChangeParams: automatic: true containerNames: - nginx-template from: kind: ImageStreamTag name: 'nginx-template:latest' namespace: test type: ImageChange - type: ConfigChange
triggers: - imageChangeParams: automatic: true containerNames: - nginx-template from: kind: ImageStreamTag name: 'nginx-template:latest' namespace: test type: ImageChange #鏡像更新 - type: ConfigChange #Deployment 配置更新