= OpenShift "oc cluster up" Wrapper script
oc cluster up is a great tool for doing local development in openshift, but it lacks some really interesting features to be productive from a developer's perspective. This script helps developers with their casual/daily worksflows while using oc cluster as the internal tool.
== Installing The easiest way is to clone this repository, so you can just update the script via a "git pull" command. But you can always get one of the releases available at link:https://github.com/openshift-evangelists/oc-cluster-wrapper/releases[oc-cluster releases].
=== Linux On linux (tested on fedora 25):
If you want to add bash completion (you might need to execute this as sudo):
=== Mac OS
On mac (tested on El Capitan and Sierra):
If you want to add bash completion and are using Homebrew:
If you're not using Homebrew, source a completion file:
Note that bash completion will not work until your first "oc-cluster up" populates $HOME/.oc/profiles.
== What it provides This script provides the following enhancements:
== Cluster profiles As a developer, you do not always want to work on the same project, with the same code. Sometimes you need to be able to switch between different clusters. For that, we provide a profile concept. How does this work? To learn how this works, see the following example:
As you've realized the clusters by default are persistent. That means that you can create as many clusters (profiles) as you want, and bring them up and down at will. But what do I do once I'm finished with a cluster? For that there is a cluster management lifecycle.
== Cluster management lifecycle Again, we'll use some examples to ilustrate:
$ oc-cluster up example oc cluster up --public-hostname 127.0.0.1 --host-data-dir /Users/jmorales/.oc/profiles/example/data --host-config-dir /Users/jmorales/.oc/profiles/example/config --use-existing-config -- Checking OpenShift client ... OK -- Checking Docker client ... OK -- Checking Docker version ... OK -- Checking for existing OpenShift container ... OK -- Checking for openshift/origin:v1.3.0 image ... OK -- Checking Docker daemon configuration ... OK -- Checking for available ports ... OK -- Checking type of volume mount ... Using Docker shared volumes for OpenShift volumes -- Creating host directories ... OK -- Finding server IP ... Using public hostname IP 127.0.0.1 as the host IP Using 127.0.0.1 as the server IP -- Starting OpenShift container ... Creating initial OpenShift configuration Starting OpenShift using container 'origin' Waiting for API server to start listening OpenShift server started -- Installing registry ... OK -- Installing router ... OK -- Importing image streams ... OK -- Importing templates ... OK -- Login to server ... OK -- Creating initial project "myproject" ... OK -- Server Information ... OpenShift server started. The server is accessible via web console at: https://127.0.0.1:8443
You are logged in as: User: developer Password: developer
To login as administrator: oc login -u system:admin
Now, let's work with the cluster:
I'm gone for a while, I need to know if my cluster is running:
I need to get some information on my clusters:
$ oc-cluster list Profiles:
I need to log in to the origin container, to check something:
I'm done, let's get rid of this cluster:
$ oc-cluster destroy
Are you sure you want to destroy cluster with profile
=== How this works? For the profiles to work, by default a subdirectory will be created in $HOME/.oc/profiles with the profile name. A file called $HOME/.oc/active_profile will hold also the name of the active profile, if there is a cluster up. Removing the cluster will remove the subdirectory holding all the profile data.
We're using --host-data-config and --host-data-dir to retain the configuration of the cluster, as we understand this is basic for daily use of the tool. And we use --keep-config to retain this information.
We're also binding the cluster to 127.0.0.1 as this is the way to make the cluster secure, and reproducible, as the ip address changes when you move from network to network. Also, anyone can log into your running cluster if you had a cluster up, since it's using AnyPasswd identity provider.
We also do two really convenient things for developers:
== Plugins The tool provides a plugin mechanism to add functionality. There's 2 types of plugins:
Plugins are files in the link:.plugins.d/[plugins.d] directory of the tool. They need to have a name following the pattern
You can:
=== Global plugins These plugins provide methods that augment the functionality of the tool.
They are always available (installed).
There is a template for these plugins available link:.plugins.d/new-plugin.global.plugin[here]
It has to have a method called
=== Local plugins These plugins provide methods that augment the functionality of the tool, or install software on the cluster.
These plugins need to be installed.
There is a template for these plugins available link:.plugins.d/new-plugin.local.plugin[here]
These plugins need to have at list these methods:
Can contain additional methods providing commands, like the global plugins.
By default, a local plugin needs to always call
== Plugin list
And the list os constantly growing. Check what's available link:.plugins.d/[here] or get a list of plugins.
== Convenience methods for working with persistent volumes (Provided as global plugin) Most users will need to work with persistent services, so we have added two convenience methods for working with volumes. One for cluster-specific volumes, and another for shared volumes (similating NFS server behaviors).
=== oc-cluster create-volume This command will create a volume in the cluster's profile. That means that if the cluster is removed, the volume and the data stored in the volume will be removed as well. This will create a PV of type hostPath, with the specified size (or 10Gi by default), on the specified path (or the default for the profile) and a Retain policy for the data.
=== oc-cluster create-shared-volume This command will create a volume in a shared location. That means that every cluster will have access to the data, and the data will not be removed if the cluster is removed. For the applications to be able to use this data, the created PV will be prebound to a specific project/namespace, with the same name for the volume as for the claim. This will create a PV of type hostPath, with the specified size (or 10Gi by default), on the specified path (or the default for the profile). With this second mechanism, we can, as an example, share the storage for our nexus deployment between all our clusters, and use nexus for java dependency management in a very convenient way.
== Convenience methods for adding common software to your cluster (Provided as a local plugin) Right now, as this tool is created to boost my productivity (and one of my colleagues), we have some additional methods (that we will convert into plugins) to deploy commons stuff that we use in most of our clusters. In this way, we have a method to deploy nexus in a project called ci, and soon we will have one for gitlab, workshops, etc...
== Bind to a reproducible IP In systems like linux or mac, you can create a link-local interface, with a static ip, that you can reuse in any place you go. There's a system environment variable that you can define to use this ip to bind the cluster to. Otherwise it will default to 127.0.0.1
Example:
== Use alternate oc version If you want to have an alternate oc client/version than the one on the path, the script uses an environment variable OC_BINARY that let you replace the client used.
$ OC_CLIENT=oc-1.4.1 oc-cluster up
== Faster s2i builds oc-cluster has the ability to bind_mount any local directory or binary to any container. I you mount your $M2_REPOSITORY or $HOME/.m2/repository to your java based s2i builder images, you'll be giving all the dependencies you have locally to your build container, which will greatly speed builds.
You just need to create a mounts-template.json file in the directory of the tool and have the rules to inject you .m2/repository (or node, python, ruby) into the image. oc-cluster will detect automatically that you want to inject that folder when the file is present and if it has rules for oc injection.
Here's an example of the content of the file to inject the oc binary into the origin container:
By default, M2_HOME will point to $HOME/.m2/repository. You can export a different value, which will take effect.
== Developing openshift With oc-cluster it's very easy to inject a oc binary into any image. You just need to create a mounts-template.json file in the directory of the tool and have the rules to inject you oc binary into the image. oc-cluster will detect automatically that you want to inject an oc binary when the file is present and if it has rules for oc injection.
Here's an example of the content of the file to inject the oc binary into the origin container:
Make sure that the variable $OPENSHIFT_BINARY points to your oc binary, or use the fully qualified value.
== Prerequisites If you can run oc cluster up you can run this tool. This works anywhere that oc cluster up runs, so any limitation really will be more a oc cluster limitation than this tool's.
NOTE: This tool assumes you run oc cluster with Docker native and not docker-machine.
== ROADMAP Find here a list of things we would like to include in the tool. These will be tracked via issues to allow for feature discussion (https://github.com/openshift-evangelists/oc-cluster-wrapper/labels/enhancement):
Any idea you might have, share it with us.
== Known Issues
== Contributing Pull Request, and issues to make the tool are welcome. Please help us make this tool better by contributing your use cases. Once we have the plugin mechanism, this will be easier to do. Also, we would love all of these use cases to be in official oc cluster tool but until that happens, we will keep using and maintaining this tool.
This work is done by the OpenShift Evangelist team