/hosted-tenant-rancher

Automated repo for deploying and managing a Hosted/Tenant Rancher setup using Jenkins or locally, leveraging S3 for Terraform state storage and offering efficient setup and cleanup processes.

Primary LanguageGo

Hosted/Tenant Rancher Guide

This README provides instructions for running and managing Hosted/Tenant Rancher instances through Jenkins, including setup, execution, cleanup, and local testing.

Running in Jenkins

Prerequisites

  • S3 Bucket: Ensure you have an S3 bucket exclusively for this purpose. It's a one-time setup, reusable for future runs. A Jenkins cleanup job will handle the Terraform state file deletion in this bucket.
  • Configuration File: Prepare a config.yml file as per the Config File Setup section below. This file is necessary for Jenkins job configuration.

Time Estimates

Expect the Jenkins job to take approximately 15 minutes, attributed mainly to the provisioning and deletion of RDS Aurora MySQL databases.

Job Execution Guidelines

  • S3 Bucket Limitation: Each S3 bucket can only be associated with one hosted/tenant job at a time.
  • Terraform State File: Presence of a Terraform state file in the S3 bucket necessitates running a cleanup job before initiating a new one.
  • Multiple Instances: For simultaneous hosted/tenant setups, use unique S3 bucket names for each and note them for subsequent cleanup.

Cleanup Process

Utilize the same config.yml for the Hosted/Tenant Cleanup Jenkins Job. This job initializes the state file in the S3 bucket to facilitate the terraform destroy command.

Config File Setup

The config.yml file is crucial for both local and Jenkins executions. Ensure it's present at the repository's root, alongside this README. The following template outlines the necessary configuration, where placeholders should be replaced with your specific details. For Jenkins execution, copy and paste the provided YAML into the job setup.

Repository URL: The rancher.repository_url can be adjusted to use the latest, alpha, or stable versions. Detailed information about choosing a Rancher version is available at the official Rancher documentation.

AWS RDS Password Requirements

The aws_rds_password in the YAML file must comply with AWS's criteria: a minimum of 8 printable ASCII characters, excluding /, ', ", and @ symbols. Non-compliance will result in Terraform provisioning failure.

s3:
  bucket: # Your dedicated S3 Bucket name in AWS us-east-2.
  region: us-east-2
aws:
  rsa_private_key: | 
    -----BEGIN RSA PRIVATE KEY-----
    # Your AWS PEM key contents here.
    -----END RSA PRIVATE KEY-----
rancher:
  repository_url: https://releases.rancher.com/server-charts/latest
  bootstrap_password: # Desired bootstrap password for Rancher.
  version: 2.8.1
  image: rancher/rancher
  image_tag: v2.8-head
  psp_enabled: false
  extra_env_name: ""
  extra_env_value: ""
k3s:
  version: v1.27.8+k3s2
tf_vars:
  aws_access_key: # Your AWS Access Key.
  aws_secret_key: # Your AWS Secret Key.
  aws_prefix: # A short prefix for labeling, preferably your initials.
  aws_vpc: # The VPC ID to use.
  aws_subnet_a: # Subnet A ID.
  aws_subnet_b: # Subnet B ID.
  aws_subnet_c: # Subnet C ID.
  aws_ami: # The AMI to use.
  aws_subnet_id: # The Subnet ID to use.
  aws_security_group_id: # The Security Group ID to use.
  aws_pem_key_name: # Your PEM key name in AWS (no file extension).
  aws_rds_password: # AWS RDS password following the specified criteria.
  aws_route53_fqdn: # Your Route53 FQDN.
  aws_ec2_instance_type: m5.xlarge
upgrade:
  version: ""
  image: rancher/rancher
  image_tag: v2.8-head
  extra_env_name: ""
  extra_env_value: ""

Local Execution and Upgrade

For local testing and upgrade processes, specific functions in /terratest/test/host_test.go facilitate the creation and upgrade of hosted and tenant Ranchers. Expect similar time frames (~15 minutes) due to Terraform and AWS operations, primarily for RDS Aurora MySQL database setups.

  • Creation: Execute TestCreateHostedTenantRancher to initiate a hosted Rancher and an imported tenant Rancher setup.
  • Upgrade: Run TestUpgradeHostRancher and TestUpgradeTenantRancher for upgrading existing setups.

Upon successful execution, URLs for both host and tenant Ranchers will be provided. sting and upgrade processes, specific functions in /terratest/test/host_test.go facilitate the creation and upgrade of hosted and tenant Ranchers. Expect similar time frames (~15 minutes) due to Terraform and AWS operations, primarily for RDS Aurora MySQL database setups.