OpenShift Local

You need an OpenShift cluster to deploy to. There are two free options for learning:

  • OpenShift Local (formerly CodeReady Containers, crc) runs a single-node OpenShift cluster in a virtual machine on your own computer. It needs a reasonably powerful machine: at least 4 CPU cores, 10.5 GB of memory and 35 GB of disk, and more is better.
  • Developer Sandbox for Red Hat OpenShift is a hosted OpenShift, free for 30 days, with nothing to install. You get a project to work in, but not administrator access.

Both need a free Red Hat Developer account. This section sets up OpenShift Local. If you use the Developer Sandbox instead, skip to logging in with oc, and see the notes in the following sections.

Install#

Head to https://console.redhat.com/openshift/create/local, download OpenShift Local for Linux, and download your pull secret, which lets the cluster download Red Hat’s images. Save it as, for example, ~/openshift/pull-secret.txt.

Extract the archive:

tar -xvf crc-linux-amd64.tar.xz

And move the crc binary to a directory on your PATH:

mkdir -p ~/.local/bin
mv crc-linux-*-amd64/crc ~/.local/bin/

On Fedora, ~/.local/bin is already on the PATH. Check that crc is working:

crc version

Set up and start#

Run the setup, which checks your system and installs what it needs (it asks for your password to configure virtualisation and networking):

crc setup

Give the cluster enough resources. These values work well for this guide, on a machine with 16 cores and 32 GB of memory:

crc config set cpus 8
crc config set memory 16384
crc config view

Start OpenShift Local, giving it your pull secret (the first start takes a while):

crc start -p ~/openshift/pull-secret.txt

When it’s ready, it prints the web console address, https://console-openshift-console.apps-crc.testing, and two logins: kubeadmin, the cluster administrator, and developer, an ordinary user. You can show them again with:

crc console --credentials

The oc command#

OpenShift’s command line tool is oc, which does everything kubectl does plus OpenShift’s extras. OpenShift Local includes it; add it to your shell’s PATH with:

eval $(crc oc-env)

Log in as the developer user:

oc login -u developer https://api.crc.testing:6443

On the Developer Sandbox, log in to the web console, choose your user name at the top right, then Copy login command, which gives you an oc login --token=... command to paste. You can download oc from the console’s ? menu, under Command line tools.

Exposing the image registry#

OpenShift has a built-in image registry. To push images to it from your computer, it needs a public route, which the administrator can turn on:

oc login -u kubeadmin https://api.crc.testing:6443
oc patch configs.imageregistry.operator.openshift.io/cluster --type merge --patch '{"spec":{"defaultRoute":true}}'

Then log back in as developer, for everything else:

oc login -u developer https://api.crc.testing:6443

When you’ve finished for the day, crc stop shuts the cluster down, and crc start starts it again.