OpenShift从现有设置创建模板

时间:2017-06-22 14:30:52

标签: openshift openshift-origin

我试图使用

从我现有的设置中生成模板
oc export dc,svc,bc --selector="microservice=imagesvc" -o yaml --as-template=imagesvc

问题是模板将容器源指向我的reigstry。我想以构建配置从源构建容器的方式修改模板,然后将其附加到deploymentconfig。我怎样才能实现这样的目标呢?

这是我目前的配置。当我申请时,我得到各种错误。作为Builds中的一个例子,我得到“无效的输出引用”

对此的任何帮助将不胜感激。

apiVersion: v1
kind: Template
metadata:
  creationTimestamp: null
  name: imagesvc
objects:
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    generation: 1
    labels:
      app: gcsimageupload
      microservice: imagesvc
    name: gcsimageupload
  spec:
    replicas: 1
    selector:
      deploymentconfig: gcsimageupload
    strategy:
      activeDeadlineSeconds: 21600
      resources: {}
      rollingParams:
        intervalSeconds: 1
        maxSurge: 25%
        maxUnavailable: 25%
        timeoutSeconds: 600
        updatePeriodSeconds: 1
      type: Rolling
    template:
      metadata:
        creationTimestamp: null
        labels:
          app: gcsimageupload
          deploymentconfig: gcsimageupload
          microservice: imagesvc
      spec:
        containers:
        - imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          name: gcsimageupload
          ports:
          - containerPort: 8080
            protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources: {}
          terminationMessagePath: /dev/termination-log
          volumeMounts:
          - mountPath: /secret
            name: gcsimageupload-secret
            readOnly: true
        dnsPolicy: ClusterFirst
        restartPolicy: Always
        securityContext: {}
        terminationGracePeriodSeconds: 30
        volumes:
        - name: gcsimageupload-secret
          secret:
            defaultMode: 420
            secretName: gcsimageupload-secret
    test: false
    triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
        - gcsimageupload
        from:
          kind: ImageStreamTag
          name: gcsimageupload:latest
          namespace: web
      type: ImageChange
    - type: ConfigChange
  status:
    availableReplicas: 0
    latestVersion: 0
    observedGeneration: 0
    replicas: 0
    unavailableReplicas: 0
    updatedReplicas: 0
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    generation: 1
    labels:
      app: imagesvc
      microservice: imagesvc
    name: imagesvc
  spec:
    replicas: 1
    selector:
      deploymentconfig: imagesvc
    strategy:
      activeDeadlineSeconds: 21600
      resources: {}
      rollingParams:
        intervalSeconds: 1
        maxSurge: 25%
        maxUnavailable: 25%
        timeoutSeconds: 600
        updatePeriodSeconds: 1
      type: Rolling
    template:
      metadata:
        creationTimestamp: null
        labels:
          app: imagesvc
          deploymentconfig: imagesvc
          microservice: imagesvc
      spec:
        containers:
        - imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          name: imagesvc
          ports:
          - containerPort: 8080
            protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          resources: {}
          terminationMessagePath: /dev/termination-log
        dnsPolicy: ClusterFirst
        restartPolicy: Always
        securityContext: {}
        terminationGracePeriodSeconds: 30
    test: false
    triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
        - imagesvc
        from:
          kind: ImageStreamTag
          name: imagesvc:latest
          namespace: web
      type: ImageChange
    - type: ConfigChange
  status:
    availableReplicas: 0
    latestVersion: 0
    observedGeneration: 0
    replicas: 0
    unavailableReplicas: 0
    updatedReplicas: 0
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    generation: 1
    labels:
      app: imaginary
      microservice: imagesvc
    name: imaginary
  spec:
    replicas: 1
    selector:
      app: imaginary
      deploymentconfig: imaginary
    strategy:
      activeDeadlineSeconds: 21600
      resources: {}
      rollingParams:
        intervalSeconds: 1
        maxSurge: 25%
        maxUnavailable: 25%
        timeoutSeconds: 600
        updatePeriodSeconds: 1
      type: Rolling
    template:
      metadata:
        annotations:
          openshift.io/generated-by: OpenShiftWebConsole
        creationTimestamp: null
        labels:
          app: imaginary
          deploymentconfig: imaginary
          microservice: imagesvc
      spec:
        containers:
        - image: h2non/imaginary
          imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: 9000
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          name: imaginary
          ports:
          - containerPort: 9000
            protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /health
              port: 9000
              scheme: HTTP
            initialDelaySeconds: 60
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          resources: {}
          terminationMessagePath: /dev/termination-log
        dnsPolicy: ClusterFirst
        restartPolicy: Always
        securityContext: {}
        terminationGracePeriodSeconds: 30
    test: false
    triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
        - imaginary
        from:
          kind: ImageStreamTag
          name: imaginary:latest
          namespace: web
      type: ImageChange
  status:
    availableReplicas: 0
    latestVersion: 0
    observedGeneration: 0
    replicas: 0
    unavailableReplicas: 0
    updatedReplicas: 0
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    labels:
      app: gcsimageupload
      microservice: imagesvc
    name: gcsimageupload
  spec:
    ports:
    - name: 8080-tcp
      port: 8080
      protocol: TCP
      targetPort: 8080
    selector:
      deploymentconfig: gcsimageupload
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
      service.alpha.openshift.io/dependencies: '[{"name":"gcsimageupload","namespace":"","kind":"Service"},{"name":"imaginary","namespace":"","kind":"Service"}]'
    creationTimestamp: null
    labels:
      app: imagesvc
      microservice: imagesvc
    name: imagesvc
  spec:
    ports:
    - name: 8080-tcp
      port: 8080
      protocol: TCP
      targetPort: 8080
    selector:
      deploymentconfig: imagesvc
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    labels:
      app: imaginary
      microservice: imagesvc
    name: imaginary
  spec:
    ports:
    - name: 9000-tcp
      port: 9000
      protocol: TCP
      targetPort: 9000
    selector:
      deploymentconfig: imaginary
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: BuildConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    labels:
      app: gcsimageupload
      microservice: imagesvc
    name: gcsimageupload
  spec:
    nodeSelector: null
    output:
      to:
        kind: ImageStreamTag
        name: gcsimageupload:latest
    postCommit: {}
    resources: {}
    runPolicy: Serial
    source:
      git:
        ref: master
        uri: https://github.com/un1x86/openshift-ms-gcsFileUpload.git
      type: Git
    strategy:
      sourceStrategy:
        env:
        - name: GCS_PROJECT
          value: ${GCS_PROJECT_ID}
        - name: GCS_KEY_FILENAME
          value: ${GCS_KEY_FILENAME}
        - name: GCS_BUCKET
          value: ${GCS_BUCKET}
        from:
          kind: ImageStreamTag
          name: nodejs:4
          namespace: openshift
      type: Source
    triggers:
    - github:
        secret: f9928132855c5a30
      type: GitHub
    - generic:
        secret: 77ece14f810caa3f
      type: Generic
    - imageChange: {}
      type: ImageChange
    - type: ConfigChange
  status:
    lastVersion: 0
- apiVersion: v1
  kind: BuildConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftWebConsole
    creationTimestamp: null
    labels:
      app: imagesvc
      microservice: imagesvc
    name: imagesvc
  spec:
    nodeSelector: null
    output:
      to:
        kind: ImageStreamTag
        name: imagesvc:latest
    postCommit: {}
    resources: {}
    runPolicy: Serial
    source:
      git:
        ref: master
        uri: https://github.com/un1x86/openshift-ms-imagesvc.git
      type: Git
    strategy:
      sourceStrategy:
        env:
        - name: IMAGINARY_APPLICATION_DOMAIN
          value: http://imaginary:9000
        - name: GCSIMAGEUPLOAD_APPLICATION_DOMAIN
          value: http://gcsimageupload:8080
        from:
          kind: ImageStreamTag
          name: nodejs:4
          namespace: openshift
      type: Source
    triggers:
    - generic:
        secret: 945da12357ef35cf
      type: Generic
    - github:
        secret: 18106312cfa8e2d1
      type: GitHub
    - imageChange: {}
      type: ImageChange
    - type: ConfigChange
  status:
    lastVersion: 0
parameters:
    - description: "GCS Project ID"
      name: GCS_PROJECT_ID
      value: ""
      required: true
    - description: "GCS Key Filename"
      name: GCS_KEY_FILENAME
      value: /secret/keyfile.json
      required: true
    - description: "GCS Bucket name"
      name: GCS_BUCKET
      value: ""
      required: true

1 个答案:

答案 0 :(得分:0)

您需要创建两个名为“imagesvc”和“gcsimageupload”的图像流。你可以通过cli“oc create is”或通过添加到模板来实现:

- kind: ImageStream
  apiVersion: v1
  metadata:
    name: <name>
  spec:
    lookupPolicy:
      local: false