# OpenShift 4 Installation ## Pre-requisites ### On your local machine Install Terraform. ```sh cat > hashicorp.repo <<"EOF" [hashicorp] name=Hashicorp Stable - $basearch baseurl=https://rpm.releases.hashicorp.com/RHEL/8/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://rpm.releases.hashicorp.com/gpg EOF sudo dnf config-manager --add-repo hashicorp.repo sudo dnf -y install terraform ``` Install the libvirt terraform provider. ```sh curl -Lo /tmp/libvirt-provider.tgz https://github.com/dmacvicar/terraform-provider-libvirt/releases/download/v0.6.3/terraform-provider-libvirt-0.6.3+git.1604843676.67f4f2aa.Fedora_32.x86_64.tar.gz mkdir -p ~/.terraform.d/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64 tar xvf /tmp/libvirt-provider.tgz -C ~/.terraform.d/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64 ``` Install the Gandi terraform provider. ```sh git clone https://github.com/go-gandi/terraform-provider-gandi cd terraform-provider-gandi make make install ``` ### On the hypervisor ```sh curl https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.7/4.7.0/rhcos-4.7.0-x86_64-qemu.x86_64.qcow2.gz |gunzip -c > /var/lib/libvirt/images/rhcos-4.7.0-x86_64-qemu.x86_64.qcow2 curl -Lo /var/lib/libvirt/images/centos-stream-8.qcow2 http://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2 ``` ## Install Define the cluster name and the bastion. ```sh cluster=ocp4 bastion=nicolas@hp-ml350.itix.fr ``` Install **openshift-installer** and **oc** on the bastion. ```sh ssh -A "$bastion" curl -Lo /tmp/openshift-installer.tgz https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest-4.7/openshift-install-linux.tar.gz ssh -A "$bastion" sudo tar zxvf /tmp/openshift-installer.tgz -C /usr/local/bin openshift-install ssh -A "$bastion" curl -Lo /tmp/oc.tgz https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest-4.7/openshift-client-linux.tar.gz ssh -A "$bastion" sudo tar zxvf /tmp/oc.tgz -C /usr/local/bin oc kubectl ``` Create the cluster configuration files. ```sh mkdir "$cluster" cp install-config.yaml.sample "$cluster/install-config.yaml" openshift-install create manifests --dir="$cluster" openshift-install create ignition-configs --dir="$cluster" ``` Customize the terraform variables. ```sh cat > terraform.tfvars <> terraform.tfvars terraform apply ``` Approve the pending CSRs. ```sh for i in {0..120}; do ssh -A "$bastion" oc --kubeconfig="$cluster/auth/kubeconfig" get csr --no-headers \ | awk '/Pending/ {print $1}' \ | xargs --no-run-if-empty ssh -A "$bastion" oc --kubeconfig="$cluster/auth/kubeconfig" adm certificate approve sleep 15 done & ``` Make sure all CSRs have been issued. ```sh ssh -A "$bastion" oc --kubeconfig="$cluster/auth/kubeconfig" get csr --no-headers ``` Provision storage for the registry. ```sh ssh -A "$bastion" oc apply --kubeconfig="$cluster/auth/kubeconfig" -f - < "$cluster/registry-pv.yaml" ``` Patch the registry to use the new storage. ```sh ssh -A "$bastion" oc patch --kubeconfig="$cluster/auth/kubeconfig" configs.imageregistry.operator.openshift.io cluster --type='json' --patch-file=/dev/fd/0 < router.yaml ssh -A "$bastion" oc apply -f - -n openshift-ingress < router.yaml ``` Update the ingress configuration. ```sh ssh -A "$bastion" oc patch ingresscontroller default -n openshift-ingress-operator --type=merge --patch-file=/dev/fd/0 < api.yaml ssh -A "$bastion" oc apply -f - -n openshift-config < api.yaml ``` Update the apiserver configuration. ```sh oc patch apiserver cluster --type=merge --patch-file=/dev/fd/0 <