How to start an openshift local cluster using oc utility

The OpenShift client utility named oc can start a local OpenShift cluster, which includes all of the required services, such as an internal registry, a router, templates, and so on. This is one of the easiest ways to start a development environment. oc cluster up creates a default user and project, and once it is complete, it will allow you to use any commands to work with the OpenShift environment, such as oc new-app.

This method provides a containerized OpenShift environment that can easily be run on a number of platforms.

System requirements and prerequisites

The oc cluster up method supports Linux, macOS, and Windows-based workstations. By default, the method requires an environment with a Docker machine installed. However, the command can create a Docker machine by itself. The following table shows the available deployment scenarios:

Operating system Docker implementation
Linux Default docker daemon for OS
macOS Docker for macOS
macOS Docker Toolbox
Windows Docker for Windows
Windows Docker Toolbox

Starting an Openshift Cluster on Linux

The deployment process involves several steps:

1. Install Docker

2. Configure an insecure registry

3. Allow ports on the firewall

4. Download the OpenShift client utility

5. Start a cluster

Note that this method can also be used on Fedora or RHEL-based hosts.

Here are the steps in detail:

1. Docker installation: This doesn’t involve anything special, and was described in the previous chapters. The following commands must be run under the root account:

$ sudo -i
# sudo yum -y install docker
# systemctl enable docker

2. Configuring an insecure registry: This is required to be able to use an internal Docker registry, which comes with the OpenShift installation. If this is not configured, oc cluster up will fail.

To allow for an insecure OpenShift registry, run the following commands under the root user:

# cat << EOF >/etc/docker/daemon.json
{
   "insecure-registries": [
     "172.30.0.0/16"
   ]
}
EOF

# systemctl start docker

Note that this requires restarting the Docker daemon so as to apply the new configuration.

3. Configuring the firewall: The default firewall configuration doesn’t enable all of the ports required for an OpenShift cluster. You need to adjust the settings using firewall-cmd:

# firewall-cmd --permanent --new-zone dockerc
# firewall-cmd --permanent --zone dockerc --add-source 172.17.0.0/16
# firewall-cmd --permanent --zone dockerc --add-port 8443/tcp
# firewall-cmd --permanent --zone dockerc --add-port 53/udp
# firewall-cmd --permanent --zone dockerc --add-port 8053/udp
# firewall-cmd --reload

4. Downloading the oc utility: The OpenShift client utility named oc is available in standard repositories; however, you can download the utility from https://github.com/openshift/origin/releases. It is recommended that you use the standard CentOS repositories:

# yum -y install centos-release-openshift-origin39
# yum -y install origin-clients

5. Starting an OpenShift cluster: Once all the prerequisites are met, you will be able to start the cluster by running oc cluster up. The command will download all the required Docker images from public repositories, and then run all of the required containers:

# oc cluster up --version=v3.9.0

Starting OpenShift using openshift/origin:v3.9.0 ...
  • ..
  • ..
The server is accessible via web console at:
    https://127.0.0.1:8443

You are logged in as:
    User: developer
    Password: <any value>

To login as administrator:
    oc login -u system:admin

In the above example, the version of the OpenShift cluster has been statically bound to v3.9.0. In most cases, you don’t have to specify a version. So, you just need oc cluster up without any arguments.

As you can see, oc cluster up deployed a ready-to-use, one-node OpenShift environment.

By default, this OpenShift environment was configured to listen on the loopback interface (127.0.0.1). This means that you may connect to the cluster using https://127.0.0.1:8443. This behavior can be changed by adding special parameters, such as –public-hostname=. A full list of available options can be shown by using the following command:

# oc cluster up --help

6. Verification: Once the cluster has been deployed, you can verify that it is ready to use. The default OpenShift configuration points you to an unprivileged user, named developer. You may raise your permissions by using the following commands:

# oc login -u system:admin
Logged into "https://127.0.0.1:8443" as "system:admin" using existing credentials.

You have access to the following projects and can switch between them with 'oc project <projectname>':

    default
    kube-public
    kube-system
  * myproject
    openshift
    openshift-infra
    openshift-node

Using project "myproject".

Once you have admin access rights, you can verify the node configuration with oc get node:

# oc get node
NAME      STATUS  AGE     VERSION
localhost Ready   9m       v1.7.6+a08f5eeb62

7. Shutting down: Once an oc cluster up environment has been deployed, it can be shut down with oc cluster down.

Starting an Openshift Cluster on macOS

The installation and configuration process for macOS assumes that Docker for macOS is being used. The deployment process involves the following:

1. Docker for macOS installation and configuration

2. Installation of openshift-cli and required packages

3. Starting a cluster

The oc cluster up command requires Docker to be installed on your system because, essentially, it creates a Docker container and runs OpenShift inside that Docker container. It is a very elegant and clean solution. The Docker for macOS installation process is described at the official portal, https://docs.docker.com/docker-for-mac.

Once the Docker service is running, you need to configure the insecure registry (172.30.0.0/16). From the Docker menu in the toolbar, you need to select the Preferences menu and click on the Daemon icon. In the Basic tab of the configuration dialog, click on the + icon under Insecure registries and add the following new entry: 172.30.0.0/16.

How to start an openshift local cluster using oc utility

When finished, click on Apply & Restart. 

Once the Docker service is configured, you need to install all the required software and start the cluster using the following steps:

1. OpenShift client installation: Install the socat and openshift-cli packages on your system as follows:

$ brew install openshift-cli socat --force

2. Starting and stopping the OpenShift cluster: The cluster can be started like this:

$ oc cluster up
Starting OpenShift using registry.access.redhat.com/openshift3/ose:v3.7.23 ...
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: <any value>

To login as administrator:
oc login -u system:admin

An installation verification can be performed by the OpenShift admin user, as follows:

$ oc login -u system:admin
Logged into "https://127.0.0.1:8443" as "system:admin" using existing credentials.

You have access to the following projects and can switch between them with 'oc project <projectname>':

default
kube-public
kube-system
* myproject
openshift
openshift-infra
openshift-node

Using project "myproject".

The Openshift cluster is up and ready for work. We may check the status of the cluster using the following command:

$ oc get nodes
NAME      STATUS AGE VERSION
localhost Ready 20h  v1.7.6+a08f5eeb62

The cluster can be stopped as follows:

$ oc cluster down

Starting an Openshift Cluster on Windows

The OpenShift environment can be deployed on Windows on a machine that supports Docker for Windows. The Docker for Windows installation process is described at https://docs.docker.com/docker-for-windows.

Once Docker is running, you will need to configure the insecure registry settings, as follows:

1. Right-click on the Docker icon in the notification area, and select Settings.

2. Click on Docker Daemon in the Settings dialog. 

3. Edit the Docker daemon configuration by adding 172.30.0.0/16 to the “insecure-registries” setting:

{
"registry-mirrors": [],
"insecure-registries": [ "172.30.0.0/16" ]
}

4. Click on Apply, and Docker will restart.

Once the Docker service is configured, the OpenShift client oc can be installed as shown below. The example also shows how to start the cluster:

OpenShift client installation: Download the Windows oc.exe binary from https://github.com/openshift/origin/releases/download/v3.7.1/openshift-origin-client-tools-v3.7.1-ab0f056-mac.zip and place it in C:\Windows\system32 or another path folder.

You can also download the latest code from https://github.com/openshift/origin/releases under Assets.

Starting/stopping a cluster: The Windows version of the OpenShift client can also start and stop the cluster, as follows:

C:\> oc cluster up

The Openshift cluster is up. You may want to check the status of the cluster using the following:

C:\> oc get node
NAME STATUS AGE
origin Ready 1d

Accessing OpenShift through a web browser

Whether you use oc cluster up or any other solution, when OpenShift is up and running, you can access it via a web browser. OpenShift is available on port 8443 by default. In the case of oc cluster up, you can reach the OpenShift login page at https://localhost:8443/:

How to start an openshift local cluster using oc utility

Use the developer login to log in to OpenShift. Once you log in, you will be presented with the service catalog, which lets you to choose from the available language runtimes:

How to start an openshift local cluster using oc utility

Projects in OpenShift extend the concept of namespaces from Kubernetes and serve as a means of separating teams and individual users working with the same OpenShift cluster. Another term often used for projects is tenant (for example, in OpenStack). You can create projects from the web console by clicking on the Create Project button and specifying its name.

After the project is created, you can click on its name on the right side of the screen. You will be redirected to the project’s overview page, from where you can create applications and other resources:

How to start an openshift local cluster using oc utility

Just to give you the basic understanding of how to navigate through OpenShift web console, see the short guide below:

The Applications menu is used to access resources directly responsible for your application, like Deployments, Pods, Services, Stateful Sets, and Routes.

The Builds menu lets you manage the configuration of Builds and build strategies, such as Pipelines, as well as the Images used to build your application from the source code.

The Resources menu gives you access to other secondary resources that can be used by your application in advanced use cases, such as Quota, Config Maps, Secrets, and Other Resources. You can also use this menu to view and manage the Membership for your project.

The Storage menu is used to request persistent storage by creating persistent storage claims.

The Monitoring menu provides you with access to various metrics collected by OpenShift on CPU, RAM, and network bandwidth utilization (if you have metrics enabled), as well as Events going on in real time.

Finally, the Catalog menu is a shortcut you can take to access service catalog directly from the project you are currently in without having to go back to the first page. This was introduced in OpenShift Origin 3.9.

The oc utility is a very elegant method to start a development environment. It makes the entire process seamless and hassle-free, while starting the utility in itself can be achieved with incredible ease.

If you found this article helpful and want to learn more in detail about container management with OpenShift, you can explore Learn Open Shift, an end-to-end OpenShift guide sysadmins, DevOps engineers and solution architects.

Found the article helpful? if so please follow us on Socials