Skip to content

Instantly share code, notes, and snippets.

@tamalsaha
Forked from sub-mod/crc_remote_laptop.md
Last active September 20, 2021 15:51
Show Gist options
  • Save tamalsaha/9b639410254e1109a399807a00dcca35 to your computer and use it in GitHub Desktop.
Save tamalsaha/9b639410254e1109a399807a00dcca35 to your computer and use it in GitHub Desktop.
Setup CodeReady Containers on Remote Server and connect from Laptop 4.2
dns upgrade
# https://centos.pkgs.org/7/epel-x86_64/tinyproxy-1.8.3-2.el7.x86_64.rpm.html
curl -O https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/t/tinyproxy-1.8.3-2.el7.x86_64.rpm
yum --nogpgcheck localinstall tinyproxy-1.8.3-2.el7.x86_64.rpm
dnf install ncurses
export USER=crc
sudo adduser $USER
sudo passwd $USER
rsync --archive --chown=$USER:$USER ~/.ssh /home/$USER
sudo usermod -aG wheel $USER
# https://serverfault.com/a/1041128/167143
# MUST login directly
ssh crc@<ip>
# su $USER
# cd ~
curl -O -fSL https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xz
tar -xvf crc-linux-amd64.tar.xz
./crc setup
$ crc start -c 20 -m 32768
To access the cluster, first set up your environment by following 'crc oc-env' instructions.
Then you can access it by running 'oc login -u developer -p developer https://api.crc.testing:6443'.
To login as an admin, run 'oc login -u kubeadmin -p hxYtC-KLeQC-kfNkm-ppi8i https://api.crc.testing:6443'.
You can now run 'crc console' and use these credentials to access the OpenShift web console.
$ ./crc console
Opening the OpenShift Web Console in the default browser...Failed to open the OpenShift Web Console, you can access it by opening https://console-openshift-console.apps-crc.testing in your web browser
------------------------------------------------------------------------------------------
- https://gist.github.com/sub-mod/ff999cb17940116a5ddea8d496c4b3f6
- http://mrdreambot.ddns.net/remote-access-to-your-personal-codeready-containers-openshift-environment/
- https://www.openshift.com/blog/accessing-codeready-containers-on-a-remote-server/
# On Dev Machine
-----------------
$ curl -O https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz
$ tar -xzvf openshift-client-linux.tar.gz
$ sudo mv oc /usr/local/bin/oc
For UI
[SSH Local Port Forwarding](https://linuxize.com/post/how-to-setup-ssh-tunneling/#local-port-forwarding)
sudo rsync --archive --chown=root:root /home/tamal/.ssh /root
sudo ssh [email protected] -L 443:console-openshift-console.apps-crc.testing:443
For oc:
export https_proxy=http://147.75.54.141:8888

Following steps work for F29 for F31 look here

On the remote host

cat /etc/redhat-release
Fedora release 29 (Twenty Nine)

Install packages

su -c 'yum install qemu-kvm libvirt NetworkManager tinyproxy'
sudo systemctl start libvirtd
sudo systemctl enable libvirtd
sudo systemctl start tinyproxy

Create a crcuser

adduser crcuser
passwd crcuser
usermod -aG wheel crcuser
sudo passwd -d crcuser
# test if crcuser needs password
$ su crcuser
$ whoami
crcuser

Setup CodeReady Containers

su crcuser
# Goto https://cloud.redhat.com/openshift/install/crc/installer-provisioned
# download 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
crc setup

# the pull secret is also available on https://cloud.redhat.com/openshift/install/crc/installer-provisioned
# Copy and paste it when prompted by crc start
crc start

Save the login details

''eval $(crc oc-env) && oc login -u kubeadmin -p e4FEb-9dxdF-9N2wH-Dj7B8 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: e4FEb-9dxdF-9N2wH-Dj7B8

Install oc client

# Go to https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/
wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-4.2.2.tar.gz

tar -xvf openshift-client-linux-4.2.2.tar.gz
cp oc /usr/local/bin

Setup tinyproxy

Edit the /etc/tinyproxy/tinyproxy.conf file. Comment out the Allow 127.0.0.1 line as it allows only access from within the VM Search for ConnectPort and add the following line:

ConnectPort 6443

Save the file and Start tinyproxy

systemctl start tinyproxy

On the Laptop

Install oc client

# Go to https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/

wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-4.1.13.tar.gz
tar -xvf openshift-client-linux-4.1.13.tar.gz
cp oc /usr/local/bin

BROWSER: Setup SSH tunneling to access OpenShift console from browser

Edit /etc/hosts

127.0.0.1 localhost console-openshift-console.apps-crc.testing oauth-openshift.apps-crc.testing
sudo ssh root@<REMOTE_HOST> -L 443:console-openshift-console.apps-crc.testing:443

Give laptop password first and then the remote system password.
OpenShift console is available at https://console-openshift-console.apps-crc.testing

TERMINAL: Setup for oc client to work

# in a new terminal
export https_proxy=http://vm_ip:8888
# test api endpoint
curl -k https://api.crc.testing:6443

Now you can login using oc client tool

oc login -u kubeadmin -p e4FEb-9dxdF-9N2wH-Dj7B8 https://api.crc.testing:6443

To access routes

# get the route 
oc get routes
NAME     HOST/PORT                                  PATH   SERVICES           PORT   TERMINATION   WILDCARD
tekton   myservice-mynamespace.apps-crc.testing          tekton-dashboard   http                 None

Add the route to /etc/hosts file as given below.

127.0.0.1 localhost console-openshift-console.apps-crc.testing oauth-openshift.apps-crc.testing myservice-mynamespace.apps-crc.testing

SSH tunnel in a new terminal

sudo ssh root@<REMOTE_HOST> -L 80:myservice-mynamespace.apps-crc.testing:80

the UI is available at https://myservice-mynamespace.apps-crc.testing

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