How To Setup Local OpenShift 4 Cluster with Red Hat CodeReady Containers

You have probably heard a lot about openshift 4 and you’re wondering,
but until recently, local openshift 4 cluster installation was not possible. With Red Hat CodeReady Containers, it’s possible now.

Openshift 4

Prerequisites

Prerequisites and required packages are listed on ;

https://code-ready.github.io/crc/

On linux systems, following software packages are required:

  • NetworkManager
  • libvirt

Installation

You must have a redhat account to install openshift 4 on your local machine. If you have already one, login with your account the link below;

Once you logged in, copy your image secret with the “Copy Pull Secret” link at the bottom of the page. You will need it later

Then download and extract the CodeReady Containers archive.

wget https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz
tar -xvf crc-linux-amd64.tar.xz
cd crc-linux-1.0.0-beta.3-amd64/
export PATH=$PATH:$(pwd) //add current directory to path for crc binary usage

Set up host machine for CodeReady Containers:

crc setup
>INFO Checking if NetworkManager is installed      
>INFO Checking if NetworkManager service is running 
>INFO Caching oc binary                            
>INFO Setting up virtualization                    
>INFO Setting up KVM                               
>INFO Installing libvirt service and dependencies  
>INFO Adding user to libvirt group                 
>INFO Enabling libvirt                             
>INFO Starting libvirt service                     
>INFO Installing crc-driver-libvirt                
>INFO Removing older system-wide crc-driver-libvirt 
>INFO Setting up libvirt 'crc' network             
>INFO Starting libvirt 'crc' network               
>INFO Writing Network Manager config for crc       
>INFO Writing dnsmasq config for crc               
>INFO Unpacking bundle from the CRC binary

Starting Openshift 4 Cluster ( without — bundle flag, default system bundle used which is ~/.crc/crc_libvirt_4.1.11.crcbundle)

crc start
>INFO Checking if NetworkManager is installed      
>INFO Checking if NetworkManager service is running 
>INFO Checking if oc binary is cached              
>INFO Checking if Virtualization is enabled        
>INFO Checking if KVM is enabled                   
>INFO Checking if libvirt is installed             
>INFO Checking if user is part of libvirt group    
>INFO Checking if libvirt is enabled               
>INFO Checking if libvirt daemon is running        
>INFO Checking if crc-driver-libvirt is installed  
>INFO Checking if libvirt 'crc' network is available 
>INFO Checking if libvirt 'crc' network is active  
>INFO Checking if /etc/NetworkManager/conf.d/crc-nm-dnsmasq.conf exists 
>INFO Checking if /etc/NetworkManager/dnsmasq.d/crc.conf exists 
>INFO Checking if CRC bundle is cached in '$HOME/.crc' 
? Image pull secret [? for help]

When prompted to image pull secret, paste your pull secret that you copied in the previous step and press enter

>INFO Loading bundle: crc_libvirt_4.1.11.crcbundle ... 
>INFO Extracting bundle: crc_libvirt_4.1.11.crcbundle ... 
>INFO Creating VM ...                              
>INFO Verifying validity of the cluster certificates ... 
>INFO Check internal and public dns query ...      
>INFO Copying kubeconfig file to instance dir ...  
>INFO Adding user's pull secret and cluster ID ... 
>INFO Starting OpenShift cluster ... [waiting 3m]  
>INFO To access the cluster using 'oc', run 'eval $(crc oc-env) && oc login -u kubeadmin -p ***** https://api.crc.testing:6443' 
>INFO Access the OpenShift web-console here: https://console-openshift-console.apps-crc.testing 
>INFO Login to the console with user: kubeadmin, password: *****
>CodeReady Containers instance is running

If you get error like “ no such host“ please go to the end of the article and try the solution

Then you will be able to login with command given in the output

eval $(crc oc-env) && oc login -u kubeadmin -p ***** https://api.crc.testing:6443'

Verify that the OpenShift cluster operators are available

oc get co
Openshift 4

You will need to run the following command to access the console

crc console
Openshift 4

You can use the virtual machine manager to view the created virtual machine

Openshift 4

Note: For issues related dns like ;

  • Unable to connect to the server: dial tcp: lookup api.crc.testing: no such host
  • Error approving the node csr Not able to get csr names

You should add virtual machine ip to /etc/hosts file. Example;

192.168.130.11   api.crc.testing
192.168.130.11   oauth-openshift.apps-crc.testing
192.168.130.11   console-openshift-console.apps-crc.testing