Chapter 3. Using CodeReady Containers


3.1. About presets

CodeReady Containers presets represent a managed container runtime and the lower bounds of system resources required by the instance to run it. CodeReady Containers offers presets for OpenShift Container Platform and the Podman container runtime.

On Microsoft Windows and macOS, the CodeReady Containers guided installer prompts you for your desired preset. On Linux, the OpenShift Container Platform preset is selected by default. You can change this selection using the crc config command before running the crc setup command. You can change your selected preset from the system tray on Microsoft Windows and macOS or from the command line on all supported operating systems. Only one preset can be active at a time.

Additional resources

3.2. Setting up CodeReady Containers

The crc setup command performs operations to set up the environment of your host machine for the CodeReady Containers instance.

The crc setup command creates the ~/.crc directory if it does not already exist.

Warning

If you are setting up a new version, capture any changes made to the instance before setting up a new CodeReady Containers release.

Prerequisites

  • On Linux or macOS, ensure that your user account has permission to use the sudo command. On Microsoft Windows, ensure that your user account can elevate to Administrator privileges.
Note

Do not run the crc executable as the root user or an administrator. Always run the crc executable with your user account.

Procedure

  1. (Optional) On Linux, the OpenShift Container Platform preset is selected by default. To select the the Podman container runtime preset:

    $ crc config set preset podman
  2. Set up your host machine for CodeReady Containers:

    $ crc setup

Additional resources

  • For more information about the available container runtime presets, see About presets.

3.3. Starting the instance

The crc start command starts the CodeReady Containers instance and configured container runtime.

Prerequisites

  • To avoid networking-related issues, ensure that you are not connected to a VPN and that your network connection is reliable.
  • You set up the host machine using the crc setup command. For more information, see Setting up CodeReady Containers.
  • On Microsoft Windows, ensure that your user account can elevate to Administrator privileges.
  • For the OpenShift preset, ensure that you have a valid OpenShift user pull secret. Copy or download the pull secret from the Pull Secret section of the CodeReady Containers page on the Red Hat Hybrid Cloud Console.

    Note

    Accessing the user pull secret requires a Red Hat account.

Procedure

  1. Start the CodeReady Containers instance:

    $ crc start
  2. For the OpenShift preset, supply your user pull secret when prompted.

    Note

    The cluster takes a minimum of four minutes to start the necessary containers and Operators before serving a request.

Additional resources

3.4. Accessing the OpenShift cluster

Access the OpenShift cluster running in the CodeReady Containers instance by using the OpenShift web console or OpenShift CLI (oc).

3.4.1. Accessing the OpenShift web console

Access the OpenShift web console by using your web browser.

Access the cluster by using either the kubeadmin or developer user. Use the developer user for creating projects or OpenShift applications and for application deployment. Use the kubeadmin user only for administrative tasks such as creating new users or setting roles.

Prerequisites

Procedure

  1. To access the OpenShift web console with your default web browser, run the following command:

    $ crc console
  2. Log in as the developer user with the password printed in the output of the crc start command. You can also view the password for the developer and kubeadmin users by running the following command:

    $ crc console --credentials

See Troubleshooting CodeReady Containers if you cannot access the CodeReady Containers OpenShift cluster.

Additional resources

3.4.2. Accessing the OpenShift cluster with the OpenShift CLI

Access the OpenShift cluster by using the OpenShift CLI (oc).

Prerequisites

Procedure

  1. Run the crc oc-env command to print the command needed to add the cached oc executable to your $PATH:

    $ crc oc-env
  2. Run the printed command.
  3. Log in as the developer user:

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

    The crc start command prints the password for the developer user. You can also view it by running the crc console --credentials command.

  4. You can now use oc to interact with your OpenShift cluster. For example, to verify that the OpenShift cluster Operators are available, log in as the kubeadmin user and run the following command:

    $ oc config use-context crc-admin
    $ oc whoami
    kubeadmin
    $ oc get co
    Note

    CodeReady Containers disables the Cluster Monitoring Operator by default.

See Troubleshooting CodeReady Containers if you cannot access the CodeReady Containers OpenShift cluster.

Additional resources

3.4.3. Accessing the internal OpenShift registry

The OpenShift cluster running in the CodeReady Containers instance includes an internal container image registry by default. This internal container image registry can be used as a publication target for locally developed container images. To access the internal OpenShift registry, follow these steps.

Prerequisites

Procedure

  1. Check which user is logged in to the cluster:

    $ oc whoami
    Note

    For demonstration purposes, the current user is assumed to be kubeadmin.

  2. Log in to the registry as that user with its token:

    $ podman login -u kubeadmin -p $(oc whoami -t) default-route-openshift-image-registry.apps-crc.testing --tls-verify=false
  3. Create a new project:

    $ oc new-project demo
  4. Pull an example container image:

    $ podman pull quay.io/libpod/alpine
  5. Tag the image, including namespace details:

    $ podman tag alpine:latest default-route-openshift-image-registry.apps-crc.testing/demo/alpine:latest
  6. Push the container image to the internal registry:

    $ podman push default-route-openshift-image-registry.apps-crc.testing/demo/alpine:latest --tls-verify=false
  7. Get imagestreams and verify that the pushed image is listed:

    $ oc get is
  8. Enable image lookup in the imagestream:

    $ oc set image-lookup alpine

    This setting allows the imagestream to be the source of images without having to provide the full URL to the internal registry.

  9. Create a pod using the recently pushed image:

    $ oc run demo --image=alpine --command -- sleep 600s

3.5. Deploying a sample application with odo

You can use odo to create OpenShift projects and applications from the command line. This procedure deploys a sample application to the OpenShift cluster running in the CodeReady Containers instance.

Prerequisites

  • You have installed odo. For more information, see Installing odo in the odo documentation.
  • The CodeReady Containers instance is running. For more information, see Starting the instance.

Procedure

  1. Log in to the running CodeReady Containers OpenShift cluster as the developer user:

    $ odo login -u developer -p developer
  2. Create a project for your application:

    $ odo project create sample-app
  3. Create a directory for your components:

    $ mkdir sample-app
    $ cd sample-app
  4. Create a component from a sample application on GitHub:

    $ odo create nodejs --s2i --git https://github.com/openshift/nodejs-ex
    Note

    Creating a component from a remote Git repository will rebuild the application each time you run the odo push command. To create a component from a local Git repository, see Creating a single-component application with odo in the odo documentation.

  5. Create a URL and add an entry to the local configuration file:

    $ odo url create --port 8080
  6. Push the changes:

    $ odo push

    Your component is now deployed to the cluster with an accessible URL.

  7. List the URLs and check the desired URL for the component:

    $ odo url list
  8. View the deployed application using the generated URL.

Additional resources

3.6. Stopping the instance

The crc stop command stops the running CodeReady Containers instance and container runtime. The stopping process takes a few minutes while the cluster shuts down.

Procedure

  • Stop the CodeReady Containers instance and container runtime:

    $ crc stop

3.7. Deleting the instance

The crc delete command deletes an existing CodeReady Containers instance.

Procedure

  • Delete the CodeReady Containers instance:

    $ crc delete
    Warning

    The crc delete command results in the loss of data stored in the CodeReady Containers instance. Save any desired information stored in the instance before running this command.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.