Chapter 7. Interacting with OpenShift
7.1. OpenShift Interaction Overview
Minishift creates a virtual machine (VM) and provisions a local, single-node OpenShift cluster in this VM. The following sections describe how Minishift can assist you in interacting with and configuring your local OpenShift instance.
For details about managing the Minishift VM, see the Managing Minishift section.
7.2. Using the OpenShift Client Binary (oc)
The minishift start
command creates an OpenShift instance using the cluster up approach.
For this purpose it copies the oc
binary onto your host. You will find it under ~/.minishift/cache/oc/3.5/oc
, provided you use Minishift’s default version of OpenShift.
You can add this binary to your PATH
using minishift oc-env
which displays the command you need to type into your shell. The output of oc-env
will differ depending on OS and shell type.
~]$ minishift oc-env
export PATH="/Users/john/.minishift/cache/oc/v1.5.0:$PATH"
# Run this command to configure your shell:
# eval $(minishift oc-env)
Users who have already installed the executables minishift
or oc
need to ensure that the new executables that minishift provides do not conflict with those already installed. This is handled by default with oc-env
, by putting the new Minishift executables in PATH
first. To access the previous version, run which oc
or which minishift
and use the output to specify the absolute filename including directory.
As part of the minishift start
command there is also a minishift
oc context created. This context contains the configuration to communicate with your OpenShift cluster.
Minishift activates this context automatically, but if you need to switch back to it after for example, logging into another OpenShift instance, you can run:
~]$ oc config use-context minishift
For an introduction to oc
usage, refer to the Get Started with the CLI topic in the OpenShift documentation.
7.3. Logging Into the Cluster
By default, cluster up uses AllowAllPasswordIdentityProvider to authenticate against the local cluster. This means any non-empty user name and password can be used to login to the local cluster. The recommended user name and password combination is developer/developer, because it already has a default project myproject and also can impersonate the administrator user. This allows to run administrator commands using the --as system:admin
parameter.
To login as administrator, use the system account:
~]$ oc login -u system:admin
In this case, client certificates are used. The certificates are stored in ~/.kube/config
. The cluster up
command installs the appropriate certificates as a part of the bootstrap.
If you run the command oc login -u system -p admin
, you will log in but not as an administrator. Instead, you will be logged in as an unprivileged user with no particular rights.
To view the currently available login contexts, run:
~]$ oc config view
7.4. Accessing the Web Console
To access the OpenShift console, you can run this command in a shell after starting Minishift to get the URL of the Web console:
~]$ minishift console --url
Alternatively, after starting Minishift, you can use the following command to directly open the console in a browser:
~]$ minishift console
7.5. Accessing OpenShift Services
To access a service exposed with a node port, run this command in a shell after starting Minishift to get the address:
~]$ minishift openshift service [-n <NAMESPACE>] [--url] <NAME>
7.6. Viewing OpenShift Logs
To access OpenShift logs, run the logs
command after starting Minishift:
~]$ minishift logs
7.7. Updating OpenShift configuration
While OpenShift is running, you can view and change the master or the node configuration of your cluster.
To view the current OpenShift master configuration master-config.yaml
, run the following command:
~]$ minishift openshift config view
To show the node configuration instead of the master configuration, specify the target
flag.
After you update the OpenShift configuration, OpenShift will transparently restart.
7.8. Example: Configuring Cross-origin Resource Sharing
In this example, you configure cross-origin resource sharing (CORS) by updating the OpenShift master configuration to allow additional IP addresses to request resources.
By default, OpenShift only allows cross-origin resource requests from the IP address of the cluster or from localhost. This setting is stored in the corsAllowedOrigins property of the master configuration file master-config.yaml
.
To change the property value and allow cross-origin requests from all domains, run the following command:
~]$ minishift openshift config set --patch '{"corsAllowedOrigins": ["."]}'*
If you get the error The specified patch need to be a valid JSON.
when you run the above command, you need to modify the above command depending on your Operating System, your shell environment and its interpolation behavior.
For example, if you use PowerShell on Microsoft Windows 10 modify the above command to:
$ .\minishift.exe --% openshift config set --patch "{\"routingConfig\": {\"subdomain\": \"192.168.99.101.nip.io\"}}"
If you use Command Prompt you may need to use:
$ .\minishift.exe openshift config set --patch "{\"routingConfig\": {\"subdomain\": \"192.168.99.101.nip.io\"}}"
7.8.1. Example: Changing the OpenShift routing suffix
In this example, you change the OpenShift routing suffix in the master configuration.
If you use a static routing suffix, you can set the routing-suffix
flag as part of the start
command. By default, Minishift uses a dynamic routing prefix based on nip.io, in which the IP address of the VM is a part of the routing suffix, for example 192.168.99.103.nip.io.
If you experience issues with nip.io
, you can use xip.io, which is based on the same principles.
To set the routing suffix to xip.io
, run the following command:
~]$ minishift openshift config set --patch '{"routingConfig": {"subdomain": "<IP-ADDRESS>.xip.io"}}'
Make sure to replace <IP-ADDRESS> in the above example with the IP address of your Minishift VM. You can retrieve the IP address by running the ip
command.