Software and Systems How-To's, Tutorials, Demos, Notes

How to Install OpenShift 4.x on Bare Metal

Assumptions

The steps to install OpenShift 4.1.0 can be found here. This documents some things I needed to do in order to install it on a cluster of Intel NUCS connected to my Mac Book Pro for internet access.

Creating the entries in DNSmasq

Create the following entries in /etc/hosts. The etc nodes will be collocated with the master nodes.

# nodes
192.168.2.3 bootstrap-0.ocp4.example.com
192.168.2.4 master-0.ocp4.example.com
192.168.2.5 master-1.ocp4.example.com
192.168.2.6 master-2.ocp4.example.com
192.168.2.7 compute-0.ocp4.example.com

# etcd 
192.168.2.4 etcd-0.ocp4.example.com
192.168.2.5 etcd-1.ocp4.example.com
192.168.2.6 etcd-2.ocp4.example.com

# api load balancer
192.168.2.3 api.ocp4.example.com
192.168.2.4 api.ocp4.example.com
192.168.2.5 api.ocp4.example.com
192.168.2.6 api.ocp4.example.com

# api-int load balancer
192.168.2.3 api-int.ocp4.example.com
192.168.2.4 api-int.ocp4.example.com
192.168.2.5 api-int.ocp4.example.com
192.168.2.6 api-int.ocp4.example.com

# important urls that is not documented in the official docs.
192.168.2.7 oauth-openshift.apps.ocp4.example.com
192.168.2.7 console-openshift-console.apps.ocp4.example.com

In the /etc/hosts entries above, the bootstrap node is initially part of the loadbalancer with url api.ocp4.example.com and api-int.ocp4.example.com

Download the pull secret

Access the OpenShift Infrastructure Page and log-in using your Red Hat account.

Click on Download Pull Secret

Generate the ssh-keys

ssh-keygen -t rsa

to produce the id_rsa and id_rsa.pub keys.

Creating the install-config.yaml

Customize the install-config.yaml found here. Paste the pull secret and the SSH public key.

apiVersion: v1
baseDomain: example.com 
compute:
- hyperthreading: Enabled   
  name: worker
  replicas: 0 
controlPlane:
  hyperthreading: Enabled   
  name: master 
  replicas: 3 
metadata:
  name: ocp4
networking:
  clusterNetworks:
  - cidr: 10.128.0.0/14 
    hostPrefix: 23 
  networkType: OpenShiftSDN
  serviceNetwork: 
  - 172.30.0.0/16
platform:
  none: {}
pullSecret: ''
sshKey: ''

Paste the pull secret and the ssh public key in the above file.

Create the install directory

Generate the Ignition files

Execute the following commands to generate the ignition files.

openshift-install create ignition-configs --dir=ocp4_install

This will generate the following files:

Copy the files to your web server directory

In my case, I copied the files to /Library/Webserver/Documents. Here’s the contents of this directory:

bootstrap.ign
master.ign
metadata.json
rhcos-4.1.0-x86_64-installer-initramfs.img
rhcos-4.1.0-x86_64-installer-kernel
rhcos-4.1.0-x86_64-installer.iso
rhcos-4.1.0-x86_64-metal-bios.raw.gz
rhcos-4.1.0-x86_64-metal-uefi.raw.gz
rhcos-4.1.0-x86_64-vmware.ova
worker.ign

First create a directory that will

Installing the CoreOS

http://192.168.2.1/rhcos-4.1.0-x86_64-metal-uefi.raw.gz

http://192.168.2.1/bootstrap.ign

http://192.168.2.1/master.ign

http://192.168.2.1/worker.ign

openshift-install --dir=ocp4_install  wait-for bootstrap-complete --log-level debug

Login to OpenShift

export KUBECONFIG=<full path of ocp4_install directory> 
oc whoami

It should give you

system:admin

Configure the Image Registry

The next steps is just following the guide from here

Since this is not a production instance, I just did the following:

oc patch configs.imageregistry.operator.openshift.io cluster --type merge --patch '{"spec":{"storage":{"emptyDir":{}}}}'

Add a New User

To add a new user, do the following:

htpasswd -nb admin <password> |tee /path/to/users.htpasswd
oc create secret generic htpass-secret --from-file=htpasswd=</path/to/users.htpasswd> -n openshift-config
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
  name: cluster
spec:
  identityProviders:
  - name: my_htpasswd_provider 
    mappingMethod: claim 
    type: HTPasswd
    htpasswd:
      fileData:
        name: htpass-secret 
oc apply -f /path/to/htpasswd.cr
oc adm policy add-cluster-role-to-user cluster-admin admin

Here’s a screenshot of the OpenShift 4.1.0 web console.

/assets/img/how-to-install-ocp4-bare-metal/ocp4-1.png-cards.png