fbpx

What is OpenShift?

Red Hat OpenShift is an open source container application platform based on the Kubernetes container orchestrator, and is designed to ease the development and deployment for enterprise applications.

OpenShift is a PaaS (Platform as a service) solution, and it includes two major distributions: 

OpenShift Origin – The first is the Open Source version
RedHat OpenShift – Red Hat’s version of OpenShift

OpenShift adds various layers such as the Service Catalog and Application Lifecycle Management on top of it.

“Serverless Containers” on top of RedHat OpenShift

By Integrating Red Hat OpenShift with Spotinst, you will benefit from all the features that Open Shift offers, including a complete infrastructure management capabilities: Provisioning of compute resources, auto scaling clusters, patching and upgrading nodes, as well as right sizing the nodes based on the containers’ usage.

Integration Prerequisites:

  • Ansible server (to deploy & manage OpenShift from)
  • python
  • Pip
  • boto
  • jq
  • awscli

Configuring the Integration

Step 1:

Make sure that all your OpenShift AWS resources are tagged with the following tags:

  • Key:kubernetes.io/cluster/<cluster-name> Value:<shared/owned>
    The values are shared/owned – Set the corresponding value to owned in case the node belongs exclusively to the cluster or to shared in case the resource is shared with other systems, these are important in order to deploy OpenShift on top of AWS.
  • Key:openshift-role Value:<openshift-role>
    openshift-role should be one of the following: master, etcd, node, new_node, if the master includes the etcd, use master as the role.
    This is mandatory in order for the script to build the inventory for the ansible scale-up process.

Step 2

Import an existing ASG/Instance of OpenShift node/s to Elastigroup, add the cluster tag and specify the openshift-role tag to be new_node (as shown in the image below).
In case your AMI is RHEL which is not BYOL (Bring your own License), please consider replacing it with other Linux OS.

Step 3

Download the spotinst-openshift.py script to your Ansible server and update the openshift_ansible_path:

(the path to the openshift-ansible directory, use full path) variable in the script.

wget -O wget -O <openshift_ansible_path>/inventory/dynamic/aws/spotinst-openshift.py https://spotinst-public.s3.amazonaws.com/integrations/kubernetes/openshift/scripts/spotinst-openshift.py

Make spotinst-openshift.py executable:

chmod +x <openshift_ansible_path>/inventory/dynamic/aws/spotinst-openshift.py

Step 4

Download the AWS dynamic inventory scripts:

wget -O <openshift_ansible_path>/inventory/dynamic/aws/ec2.ini https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
wget -O <openshift_ansible_path>/inventory/dynamic/aws/ec2.py https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py

Make ec2.py executable

chmod +x <openshift_ansible_path>/inventory/dynamic/aws/ec2.py

Edit ec2.ini:

Add instance_filters as described below (update the <cluster-name>, <shared/owned> fields as configured in your tags).

instance_filters = tag:kubernetes.io/cluster/<cluster-name>=<shared/owned>&tag:openshift-role=master,tag:kubernetes.io/cluster/<cluster-name>=<shared/owned>&tag:openshift-role=etcd,tag:kubernetes.io/cluster/<cluster-name>=<shared/owned>&tag:openshift-role=new_node,tag:kubernetes.io/cluster/<cluster-name>=<shared/owned>&tag:openshift-role=node

For example:

instance_filters = tag:kubernetes.io/cluster/spotinst-openshift=owned&tag:openshift-role=master,tag:kubernetes.io/cluster/spotinst-openshift=owned&tag:openshift-role=etcd,tag:kubernetes.io/cluster/spotinst-openshift=owned&tag:openshift-role=new_node,tag:kubernetes.io/cluster/spotinst-openshift=owned&tag:openshift-role=node

Configure the vpc_destination_variable as following:

vpc_destination_variable = private_ip_address

Step 5

Create/edit /etc/ansible/ansible.cfg, and configure the following:

[defaults]
host_key_checking = False

Step 6

Create a configuration inventory file for your OpenShift deployment that will hold all the configurations from [OSEv3:vars] to the end of the inventory file and save it under
openshift-ansible/inventory/dynamic/aws/conf_inv.ini

For example – for the following inventory file:

https://github.com/openshift/openshift-ansible/blob/master/inventory/hosts.example

The conf_inv.ini should be:

https://spotinst-public.s3.amazonaws.com/integrations/kubernetes/openshift/configs/conf_inv.ini

Step 7

Create a crontab to run this script every minute

crontab -e

Add the following line:

* * * * * <spotinst_openshift.py full path>

Save the file.

Make sure service crond is running

service crond status
service crond start

Step 8 

After the instances created by Elastigroup were registered to OpenShift, please scale down the original ASG in AWS.

Step 9

In case AutoScaling is required, please install Spotinst K8S Controller on top of the cluster and specify the k8s integration section in the Elastigroup configuration.

Please notice the following:

Replacement/Scale-up procedure takes a few minutes (varies between different operating systems).

Diagram of the Script’s process: