Installing OpenShift on Ubuntu — 2021
Dockerized MERN on OpenShift — Part 1
In my spare time I’ve been wising up on React. As part of my learnings I decided to port my Rails website to a MERN stack. I find it useful to share my knowledge in order to further my understanding, so this is part one in my guide to create a dockerized MERN application that can be deployed to OpenShift.
Setting up Docker repository
The first thing to do is to set up Docker on your Ubuntu instance.
- First, import the Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
2. Setup the stable Docker repository
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Note:
lsb_release -cs
will return the name of your Ubuntu distribution. In my case it’s focal.
3. Update your apt package index and install Docker Engine and containerd
sudo apt-get install docker-ce docker-ce-cli containerd.io
Note: Containerd is a container lifecycle manager
4. Verify that all of the above has completed successfully by running
sudo docker run hello-world
This should output the following (or something similar):
5. Add your user to the docker group
sudo usermod -aG docker $USER
Setting up OpenShift
Now that Docker is installed we need to install OpenShift.
- First, download and extract the latest OpenShift Origin
wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gztar xvzf openshift*.tar.gz
2. Move kubectl and oc binaries
cd openshift-origin-client-tools*/
sudo mv oc kubectl /usr/local/bin/
4. Verify that OpenShift has installed correctly
oc version
This should output detail on the OpenShift install
> oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth GSSAPI Kerberos SPNEGO
5. Insecure the registry and restart Docker
cat << EOF | sudo tee /etc/docker/daemon.json
{
"insecure-registries" : ["172.30.0.0/16"]
}
EOFsudo systemctl restart docker
6. Bringing OpenShift up and down
sudo oc cluster up --public-hostname=<server_ip>
sudo oc cluster down
7. Configure hosting server IP address
a. Edit the kubeconfig file
sudo nano ./openshift.local.clusterup/openshift-controller-manager/openshift-master.kubeconfig
b. Replace the default server address with the host address
server: https://<server_ip>:8443
Note: <server_ip> should be the IP address of your Ubuntu instance
9. After saving the file start the cluster
sudo oc cluster up --public-hostname=<server_ip>
10. Verify you can access the cluster by heading to the web console https://<server_ip>:8443/console
You should be able to see the following page to verify success:
If loading the console redirects you to 127.0.0.1 or you run into issues logging in as admin you might have started it without the public-hostname flag. In this case, bring the cluster down, remove the stored configuration and re-run:
sudo oc cluster down
rm -rf openshift.local.clusterup/
sudo oc cluster up --public-hostname=<server_ip>
Using OpenShift
Now that both Docker and OpenShift are installed lets go over the basics.
- Log in through the CLI
sudo oc login -u USERNAME -p PASSWORD
Note: Set USERNAME to something memorable, as well as PASSWORD
Alternatively to logon as an administrator
sudo oc login -u system:admin
Note: Logging in as a system administrator will give you access to the built in projects, the password is:
2. It’s easy to switch between the different projects
sudo oc project <project_name>
Note: <project_name> should be the name of the project you wish to switch to
3. Logging in as your own user create your first project
sudo new-project dev --display-name="<project_name>" --description="<project_description>"
4. This project can be verified by checking the web console and logging in as the dev user you used to create the project.