oc new‐app VS oc apply several YAML files . - unix1998/technical_notes GitHub Wiki

oc new-app command is a convenient way to streamline the process that would otherwise require you to manually create and apply separate YAML configuration files for the build, service, and route. The steps you mentioned using YAML files accomplish the same outcome but involve more manual steps. Here's how the procedures compare:

Procedure with oc new-app Command:

  1. Create the application using S2I:

    oc new-app <builder-image>~<source-code-url>
    

    This command automatically generates and applies the necessary configurations.

  2. Expose the service to create a route:

    oc expose svc/<service-name>
    
  3. Get the route information:

    oc get route
    

Procedure with YAML Configuration Files:

  1. Create a build-config.yml for the build configuration:

    apiVersion: build.openshift.io/v1
    kind: BuildConfig
    metadata:
      name: your-app
    spec:
      source:
        git:
          uri: https://github.com/your-repo/your-app.git
      strategy:
        sourceStrategy:
          from:
            kind: ImageStreamTag
            name: python:3.8
    
  2. Create a service.yml for the service:

    apiVersion: v1
    kind: Service
    metadata:
      name: your-app
    spec:
      ports:
        - port: 8080
          targetPort: 8080
      selector:
        app: your-app
    
  3. Create a route.yml for the route:

    apiVersion: route.openshift.io/v1
    kind: Route
    metadata:
      name: your-app
    spec:
      to:
        kind: Service
        name: your-app
    
  4. Apply the YAML files:

    oc apply -f build-config.yml
    oc apply -f service.yml
    oc apply -f route.yml
    
  5. Get the route information (if needed):

    oc get route
    

Key Points:

  • oc new-app simplifies the process by automatically generating the necessary configurations for build, deployment, and service creation. It combines multiple steps into a single command, making it quicker and less error-prone for simple use cases.
  • Manual YAML configuration gives you more control and is useful for complex setups where you need to customize each aspect of the deployment. It involves creating and managing individual YAML files for each resource (BuildConfig, Service, Route).

Both approaches achieve the same end result: an application built using S2I, deployed in OpenShift, and accessible from outside the cluster. The choice between them depends on your specific needs and preferences for automation versus customization.