Skip to content

Instantly share code, notes, and snippets.

@pottava
Last active February 13, 2023 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pottava/2def6bba3a12a476ee42cf89dcfdb45e to your computer and use it in GitHub Desktop.
Save pottava/2def6bba3a12a476ee42cf89dcfdb45e to your computer and use it in GitHub Desktop.
CodeReady Containers (crc)

Setup a CRC instance on Google Cloud

1. Create a VM

vm_name=
gcloud compute instances create \
    "${vm_name}" --zone asia-northeast1-c \
    --image-project=ubuntu-os-cloud --image-family=ubuntu-2004-lts \
    --machine-type "n1-custom-14-36864" --boot-disk-size 300G --boot-disk-type pd-standard \
    --enable-nested-virtualization --metadata=enable-oslogin=TRUE
gcloud compute ssh "${vm_name}" --zone asia-northeast1-c

without OS login,

ssh-keygen -t ed25519 -N "" -f "id_rsa_crc"
sed "s/ssh-ed25519/$(whoami):ssh-ed25519/" "id_rsa_crc.pub" > ssh-metadata
gcloud compute instances add-metadata "${vm_name}" \
    --zone asia-northeast1-c --metadata-from-file ssh-keys=ssh-metadata
gcloud compute ssh "${vm_name}" --ssh-key-file="id_rsa_crc" --tunnel-through-iap

2. Install CRC

sudo apt-get update
sudo apt install -y qemu-kvm libvirt-daemon libvirt-daemon-system network-manager
wget https://developers.redhat.com/content-gateway/rest/mirror/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz
tar -xvf crc-linux-amd64.tar.xz
sudo mv crc-linux-*/crc /usr/local/bin/
crc config set cpus 10
crc config set memory 30517
crc config set disk-size 200
crc config set network-mode user
crc config set consent-telemetry no
crc config view
crc cleanup
crc setup
exit

3. Reset the VM

gcloud compute instances reset "${vm_name}" --zone asia-northeast1-c
gcloud compute ssh "${vm_name}" --zone asia-northeast1-c

4. Start the CRC server

You have to prepare a pull secret on https://cloud.redhat.com/openshift/create/local in advance.

crc setup
crc daemon &
crc start

5. Connect to the server

Open the /etc/hosts, and add the following 3 lines. (@see https://code-ready.github.io/crc/#dns-configuration-linux_gsg)

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

Login as an administrator, then request the resources.

eval $(crc oc-env)
oc login -u kubeadmin https://api.crc.testing:6443
oc get co
oc get po --all-namespaces | wc -l

Try kubectl as well.

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
export KUBECONFIG=$HOME/.crc/machines/crc/kubeconfig
kubectl get po --all-namespaces | wc -l

6. Make a StorageClass

@see https://github.com/code-ready/crc/wiki/Dynamic-volume-provisioning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment