Basics
Workflow
- After you create a new app (see below for instructions), OpenShift will first build it
- OpenShift spins up a new build container. Because this container is just for building, its resources will be listed under compute-resources-timebound if you go to Resources > Quota
- OpenShift will choose an appropriate Docker image based on the framework/DB you picked from the catalog
- For example, if you picked Nodejs, a Docker image with Node.js will automatically be selected (e.g. openshift/nodejs:latest)
- Once the build container is running, it performs the build by taking your git repository and combining it with the Docker image into a new Docker image using a process called S2I (Source-to-Image)
- You can see this image by going to Builds > Images. The image stream will be something like project/appname:tag
- OpenShift will then deploy your app
- OpenShift will now create a deployment container. This container will create and start the container that’s actually responsible for running your application, based on the new Docker image it created during the build step
- The deployment container, like the build container, will use terminating resources and will be listed under compute-resources-timebound if you go to Resources > Quota
- The application container will use non-terminating resources and will be listed under compute-resources if you go to Resources > Quota
- OpenShift will now create a deployment container. This container will create and start the container that’s actually responsible for running your application, based on the new Docker image it created during the build step
Terminology
- A project can have multiple applications
- An application can have multiple pods
- A pod is built from a docker image plus a repo, then deployed
- An Image Stream is an abstract, flexible way to reference an actual Docker Image
Applications
Set up a new app
- Create a new project
- Add to Project > Browse Catalog
- Pick a framework, etc
- Continue to fill out the form as instructed
- You’ll typically at a minimum need to provide the application name and git repository
Stop an app
- Go to Applications > Deployments
- Click on the build number of the application you wish to stop
- Find the circle that shows how many pods are running, and click the down arrow until it says 0 pods
Builds
Get webhook URL
-
Using
oc
, get the build configurationoc describe buildconfig
-
Look for Webhook GitHub or Webhook Generic and copy the URL
-
In the OpenShift web interface, go to Applications > Builds > click the build for your application > Actions > Edit > Show advanced options
-
Scroll down to Triggers > click the toggle button next to the secret for the webhook (GitHub or Generic) > copy the secret
-
Replace the secret in the webhook URL with the secret you copied and configure it in your Git/build server as desired
Secrets
Configure SSH keys for a private Git repository
https://blog.openshift.com/private-git-repositories-part-2a-repository-ssh-keys/
CLI reference
Set up CLI tools
https://docs.openshift.com/online/cli_reference/get_started_cli.html
Login
In the web interface click ? > Command Line Tools and copy the line starting with oc login
SSH to a pod
-
List pods
oc get pods
-
SSH to the desired pod
oc rsh podname
List everything in a project
oc get all
Delete everything in a project
-
Delete everything except secrets and persistent volume claims
oc delete all --all
-
Delete any secrets
oc get secrets oc delete secrets ...
-
Delete persistent volume claims
oc delete pvc --all
Delete an app
Note: this can be done from the Web UI, you’d just have to delete all the components individually
- Get the label for the app you want to delete (look in the
LABELS
column)oc get all --show-labels
- Delete the app by deleting everything with that label
oc delete all -l app=APPLABEL
- Delete secrets and persistent volume claims
oc get secrets oc delete secrets ... oc get pvc oc delete pvc ...
Templates
Create a template from an existing project
Follow the steps here: https://github.com/bmaupin/kleanup#usage
See also: https://docs.openshift.com/container-platform/latest/dev_guide/templates.html#export-as-template
Common Problems
Build is pending and never starts
Builds seem to frequently hang. Provided there are no errors this can often be fixed by manually redoing the build:
- Go to Builds > Builds and click the build number
- Go to Events and make sure there are no errors
- Go to Details and make sure the Duration is greater than 5 minutes. If not, wait a little bit longer.
- If there are no errors, at the top click Cancel Build > Rebuild