OpenShift Application Operations

From NovaOrdis Knowledge Base
Revision as of 19:47, 22 November 2017 by Ovidiu (talk | contribs) (→‎Rollout)
Jump to navigation Jump to search

Internal

Overview

oc new-app is a tool that generates an appropriate JSON configuration so OpenShift can build an image based on it. The configuration represents resources of an application, maintained inside a project.

For more details on projects and applications, see Projects and Applications.

The command is a shortcut to configure a project with common resources for a standard development workflow. Source code, images and templates are specified at this stage. The command looks for images on the new local Docker installation, if available, in the Docker registry and the OpenShift image stream.

If new-app finds a Dockerfile in the repository, it uses the "docker" build strategy. Otherwise it uses the "source" strategy. The strategy can be explicitly set with --strategy option.

It can also be used to instantiate a stored template:

oc new-app --template=example-template --param=USERNAME=somevalue

When new-app is executed, OpenShift tries to do the following:

1. Create a build configuration and build the source into a new version of the application.

2. As result of build configuration configuration execution, a new container image based on the image stream compatible with the source code is created.

3. Create a deployment configuration that deploys the new image.

4. Deploy a pod.

5. Configure a service.

6. Optionally, a route is create to expose the service externally.

Create a New Application

Examples:

oc new-app https://github.com/openshift/nodejs-ex.git

Source-to-Image application:

oc new-app nodejs:latest~https://github.com/wkulhanek/ocp-appdev-helloworld-nodejs.git --strategy=source --name=hello-nodejs

Application Life Cycle Events and State Monitoring

Remove an Application

To remove an application, all resources associated to the application must be deleted. The resources are:

  • routes
  • services
  • build configuration
  • deploy configuration
  • replication controller

Deleting a project deletes all resources associated with the project, even if they are associated with more than one application. If a project includes multiple applications, deleting the project deletes resources for all applications.

Scaling Up and Down the Number of Replicas associated with a DeploymentConfig

Scaling up and down an application means controlling the application pod replicas, via oc scale command. The command defines the number of replicas in the replication controller state. This procedure can be applied after a configuration change, such as a modification in the ConfigMap.

oc scale --replicas=<replica-count> dc <deployment-configuration-name>

or

oc scale -replicas=<replica-count> deploymentconfig/<deployment-configuration-name>

TODO: Investigate the relationship between the deployment configuration and the replication controller.

Procedure

Identify the name of the deployment config:

oc get dc -o name --selector=....

or

oc get dc

Then set the number of replicas to 0:

oc scale --replicas=0 deploymentconfig/<deploymentconfig-name> 

After all pods associated with deployment configuration have been stopped, scale it back up again.

oc scale --replicas=1 deploymentconfig/<deploymentconfig-name>

Rollout

A rollout is exposed as a replication controller, and the deployment process manages scaling down old replication controllers and scaling up new ones. Implements one of the deployment strategies.

oc rollout cancel|history|latest|pause|resume|retry|status|undo dc/<deployment-configuration-name>

If a deployment process is already in progress, the utility warns and a new replication controller is not deployed.

Subcommands

latest

history

Information about all available application revisions. To view details about a specific revision, use --revision=<revision-label>

oc rollout history dc/<deployment-configuration-name> --revision=<revision-label>

undo

Rolls back the application to the last successful deployment.

--to-revision forces a specific version to roll back to.

cancel

Cancellation is a "best-effort" operation. When canceled, the deployment configuration is automatically rolled back by scaling up the previous replication controller.