Skip to content

Instantly share code, notes, and snippets.

@fmount
Last active May 2, 2022
Embed
What would you like to do?
A few notes to setup a development environment based on Code Ready Containers platform

Expose CodeReady container Platform on CentOS

Sizing

  • 4 physical CPU cores
  • 8 GB of free memory
  • 35 GB of storage space

Update and install some required packages

  1. sudo yum update -y ; sudo yum upgrade -y
  2. sudo yum install -y wget libvirt haproxy policycoreutils-python-utils libguestfs-tools

[OPTIONAL] - Setup the firewall on the host for crc

sudo systemctl status firewalld
sudo firewall-cmd --add-port={80/tcp,443/tcp,6443/tcp} --permanent
sudo systemctl restart firewalld

Make sure Selinux is happy

sudo semanage port -a -t http_port_t -p tcp 6443

Download both crc and oc tools on the host

wget https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz
wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz
sudo tar -xJvf crc-linux-amd64.tar.xz
sudo mv crc-linux-2.2.2-amd64/crc /usr/local/bin/
sudo tar zxf openshift-client-linux.tar.gz -C /usr/local/bin/

Setup and bootstrap the crc instance

crc config set skip-check-daemon-systemd-sockets true
crc config set skip-check-daemon-systemd-unit true
crc config set enable-cluster-monitoring false
crc config set consent-telemetry no
# Pull the secret from: https://console.redhat.com/openshift/create/local
# and set it to the crc instance config
crc config set pull-secret-file ~/.pull-secret.txt
crc config view
crc setup
crc start

[OPTIONAL] - SSH Access to the CRC instance

ssh -i ~/.crc/machines/crc/id_ecdsa core@"$(crc ip)"

[OPTIONAL] - Adding more resources to CRC/OCP

  • Allocate more vCPU: crc config set cpus 6
  • Allocate additional memory: crc config set memory 16384

[OPTIONAL] - ODF / ROOK: Add more disks

Thin provisioned disks for ODF/ROOK:

sudo -S qemu-img create -f raw ~/.crc/vdb 100G
sudo -S qemu-img create -f raw ~/.crc/vdc 100G

Attach these devices to CRC VM

crc stop
sudo virsh list --all
sudo virsh dumpxml crc > ~/crc.xml
vim ~/crc.xml

Add the following section to crc.xml Make sure to set the correct disk path

<disk type='file' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source file='$HOME/.crc/vdb' index='1'/>
  <backingStore/>
  <target dev='vdb' bus='virtio'/>
  <alias name='virtio-disk1'/>
  <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</disk>
<disk type='file' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source file='$HOME/.crc/vdc' index='2'/>
  <backingStore/>
  <target dev='vdc' bus='virtio'/>
  <alias name='virtio-disk2'/>
  <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
</disk>

Apply XML file and start CRC

sudo virsh define ~/crc.xml
crc start

List devices to verify

ssh -i ~/.crc/machines/crc/id_ecdsa core@"$(crc ip)" lsblk

[Optional] - Extend the CRC VM root disk size

ssh -i ~/.crc/machines/crc/id_ecdsa core@"$(crc ip)" lsblk

# Identify partition name of /sysroot
vda    252:0    0   31G  0 disk
|-vda1 252:1    0    1M  0 part
|-vda2 252:2    0  127M  0 part
|-vda3 252:3    0  384M  0 part /boot
`-vda4 252:4    0 30.5G  0 part /sysroot
vdb    252:16   0  100G  0 disk
vdc    252:32   0  100G  0 disk

crc stop
CRC_MACHINE_IMAGE=${HOME}/.crc/machines/crc/crc.qcow2

# This resize is thin-provisioned
sudo qemu-img resize ${CRC_MACHINE_IMAGE} +20G
sudo cp ${CRC_MACHINE_IMAGE} ${CRC_MACHINE_IMAGE}.ORIGINAL

#increase the /dev/sda4 (known as vda4 in the VM) disk partition size by an additional 20GB
sudo virt-resize --expand /dev/sda4 ${CRC_MACHINE_IMAGE}.ORIGINAL ${CRC_MACHINE_IMAGE}
sudo rm ${CRC_MACHINE_IMAGE}.ORIGINAL
crc start

Expose CRC outside via haproxy

Gather some info required to configure HAProxy:

SERVER_IP=$(hostname --ip-address)
CRC_IP=$(crc ip)
cd /etc/haproxy
sudo cp haproxy.cfg haproxy.cfg.orig

Customize haproxy.cfg with the info retrieved. Copy the following content in haproxy.cfg

global
debug

defaults
log global
mode http
timeout connect 10s
timeout client 1m
timeout server 1m

frontend apps
bind $SERVER:80
bind $SERVER:443
mode tcp
default_backend apps

backend apps
mode tcp
option ssl-hello-chk
balance roundrobin
server crc_vm $CRC:443 check

frontend api
bind $SERVER:6443
mode tcp
default_backend api

backend api
mode tcp
balance roundrobin
option ssl-hello-chk
server crc_vm $CRC:6443 check

and replace the IP addresses by running:

sudo sed -i "s/SERVER_IP/$SERVER_IP/g" haproxy.cfg
sudo sed -i "s/CRC_IP/$CRC_IP/g" haproxy.cfg

Finally, check the resulting config and start haproxy:

sudo setsebool -P haproxy_connect_any=1 # selinux enabled (hosts only)
sudo systemctl enable haproxy
sudo systemctl start haproxy

Configure your local machine and access CRC

Add DNS entries to /etc/hosts on your local machine (optional)

echo $SERVER console-openshift-console.apps-crc.testing oauth-openshift.apps-crc.testing api.crc.testing >> /etc/hosts

Get from the crc host the following info useful to access the environment from your laptop.

Find the console : crc console --url Reprint the default credentials : crc console --credentials

[OPTIONAL] - Add DNS entries to /etc/hosts on the local machine

echo $SERVER console-openshift-console.apps-crc.testing oauth-openshift.apps-crc.testing api.crc.testing >> /etc/hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment