This topic describes how to deploy OpenShift by using Terraform.

Prerequisites

Before you begin, ensure that you have completed the following operations:

Background information

OpenShift is an open-source container platform based on container resource orchestration engines Kubernetes and Docker. Enterprises can build an internal PaaS platform based on the OpenShift platform. This helps offer the CI/CD process, improve IT efficiency, and implement DevOps and agile development. You can deploy the OpenShift platform with one click on Alibaba Cloud by using the Terraform module (OpenShift).

Procedure

  1. Write the Terraform code. This topic uses an example of running Terraform in Cloud Shell.
    1. Log on to Cloud Shell.
    2. Generate an AccessKey pair for the current user.
      ssh-keygen
    3. Reference the module in main.tf.
      vim main.tf

      Press the i key to enter the edit mode of vim. Add the following content:

      module "openshift" {
        source  = "zzxwill/openshift/alicloud"
        version = "0.0.4"
        // The region.
        region = "cn-hangzhou"
        // The zone.
        availability_zone = "cn-hangzhou-i"
        // Enter your local public key.
        public_key = "ssh-rsa xxx"
      }

      public_key is the local public key. You can run the following command to view this key:

      cat ~/.ssh/id_rsa.pub
    4. Write the OKD installation script.
      vim okd.sh

      Press the i key to enter the edit mode of vim. Add the following content:

      #! /usr/bin/env bash
      
      set -x
      cd /opt/
      wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
      tar -zxvf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
      cd openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit
       export PATH=/opt/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit:$PATH
      
      yum install -y docker
      service docker start
      
      oc cluster up --skip-registry-check=true  --public-hostname=$1
  2. Run the terraform init command to initialize Terraform configuration files.
    terraform init

    A similar output is displayed:

    Initializing modules...
    Downloading zzxwill/openshift/alicloud 0.0.4 for openshift...
    - openshift in .terraform/modules/openshift
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "null" (hashicorp/null) 2.1.2...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.71.0...
    
    The following providers do not have any version constraints in configuration,
    so the latest version was installed.
    
    To prevent automatic upgrades to new major versions that may contain breaking
    changes, it is recommended to add version = "..." constraints to the
    corresponding provider blocks in configuration, with the constraint strings
    suggested below.
    
    * provider.alicloud: version = "~> 1.71"
    * provider.null: version = "~> 2.1"
    
    Terraform has been successfully initialized!
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Run the terraform apply command to create resources.
    terraform apply

    The resources are created if the following output is displayed:

    Apply complete! Resources: 11 added, 0 changed, 0 destroyed.
    
    Outputs:
    
    OpenShift = https://x.x.x.x:8443/console
    Password = 123456
    Username = admin
  4. Log on to the OpenShift platform.
    1. After the resources are created, enter https://x.x.x.x:8443/console (replace x.x.x.x with your IP address) in the address bar of the browser. The OpenShift logon page is displayed.
      okd_login
    2. On the logon page that appears, enter admin and 123456 in the Username and Password fields. The following page appears after a successful logon.
      okd_console