OpenShift Create an Application from a Docker Image: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 80: Line 80:
         emptyDir: {}
         emptyDir: {}
   test: false
   test: false
   triggers:
   '''triggers''':
   - type: ConfigChange
   - '''type''': <font color='teal'>ConfigChange</font>
   - imageChangeParams:
   - '''type''': <font color='teal'>ImageChange</font>
    imageChangeParams:
       automatic: true
       automatic: true
       containerNames:
       containerNames:
Line 90: Line 91:
         name: nexus3:latest
         name: nexus3:latest
         namespace: production-nexus
         namespace: production-nexus
     type: ImageChange
      





Revision as of 02:57, 20 January 2018

Internal

Overview

A Docker image repository URL can be provided to oc new-app to create an application based on that image.

oc new-app <docker-repository-URL>

Example:

oc new-app docker.io/sonatype/nexus3:latest

Primitives

The utility creates an image stream, a deployment configuration and a service in the current project, and associate all of them with a single application by annotating them with the "app=<application-name>" label, where the application name is inferred from - and equal to - the name of the image repository given as argument.

1. Image Stream. The image stream name is set to the application name, and the object is associated with the application by the "app=<app-name> label.

apiVersion: v1
kind: ImageStream
metadata:
 labels:
   app: nexus3
 name: nexus3
spec:
 lookupPolicy:
   local: false
 tags:
   name: latest
   from:
     kind: DockerImage
     name: docker.io/sonatype/nexus3:latest
   referencePolicy:
     type: Source
Image Streams

2. Deployment Configuration The deployment configuration name is set to the application name and the object is associated with the application by the "app=<app-name> label.

apiVersion: v1
kind: DeploymentConfig
metadata:
 name: nexus3
 labels:
   app: nexus3
spec:
 selector:
   app: nexus3
   deploymentconfig: nexus3
 strategy:
   type: Rolling
   rollingParams:
     ...
   activeDeadlineSeconds: 21600
 template:
   metadata:
     labels:
       app: nexus3
       deploymentconfig: nexus3
   spec:
     containers:
     - name: nexus3
       image: docker.io/sonatype/nexus3@sha256:1b1a581c76bf2a43112d4eea0077a73aadf234bb34a7b56f76fd5f3c1634dcaf
       imagePullPolicy: Always
       ports:
       - containerPort: 8081
         protocol: TCP
       volumeMounts:
       - name: nexus3-volume-1
         mountPath: /nexus-data
     dnsPolicy: ClusterFirst
     restartPolicy: Always
     schedulerName: default-scheduler
     terminationGracePeriodSeconds: 30
     volumes:
     - name: nexus3-volume-1
       emptyDir: {}
 test: false
 triggers:
 - type: ConfigChange
 - type: ImageChange
   imageChangeParams:
     automatic: true
     containerNames:
     - nexus3
     from:
       kind: ImageStreamTag
       name: nexus3:latest
       namespace: production-nexus
   


3. Service

For more details on how to deploy a production-ready Nexus instance starting with oc new-app <nexus-image-url>, go to:

Deploy Nexus Based on a Standard Sonatype Docker Image