Skip to content

Commit 8c2f77d

Browse files
authored
Merge pull request #48 from ibm-cloud-architecture/ocp46
Fixing multiple issues with repo - see detail; close #35 close #41 close #45
2 parents 3122ef0 + 0a0cf4d commit 8c2f77d

26 files changed

+624
-709
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
# .tfvars files
99
*.tfvars
10+
openshift_pull_secret.json
11+
.terraform.lock.hcl
1012

1113
# OS X files
12-
.DS_Store
14+
.DS_Store

README.md

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Automated OpenShift v4 installation on AWS
22

3-
---
4-
**Important**: use branch ocp46 to install OpenShift version 4.6.x or later
5-
---
6-
7-
This project automates the Red Hat OpenShift Container Platform 4.x installation on Amazon AWS platform. It focuses on the OpenShift User-provided infrastructure installation (UPI) where implementers provide pre-existing infrastructure including VMs, networking, load balancers, DNS configuration etc.
3+
This project automates the Red Hat OpenShift Container Platform 4.6 (for previous releases - checkout `pre46` branch) installation on Amazon AWS platform. It focuses on the OpenShift User-provided infrastructure installation (UPI) where implementers provide pre-existing infrastructure including VMs, networking, load balancers, DNS configuration etc.
84

95
* [Terraform Automation](#terraform-automation)
106
* [Infrastructure Architecture](#infrastructure-architecture)
@@ -19,7 +15,7 @@ This project uses mainly Terraform as infrastructure management and installation
1915

2016
### Prerequisites
2117

22-
1. To use Terraform automation, download the Terraform binaries [here](https://www.terraform.io/). The code here supports Terraform 0.12 - 0.12.13; there are warning messages to run this on 0.12.14 and later.
18+
1. To use Terraform automation, download the Terraform binaries [here](https://www.terraform.io/). The code here supports Terraform 0.15 or later.
2319

2420
On MacOS, you can acquire it using [homebrew](brew.sh) using this command:
2521

@@ -58,19 +54,21 @@ This project uses mainly Terraform as infrastructure management and installation
5854
zypper install wget
5955
```
6056
61-
4. Get the Terraform code
57+
5. Install jq: see [https://stedolan.github.io/jq/download/](https://stedolan.github.io/jq/download/)
58+
59+
6. Get the Terraform code
6260
6361
```bash
6462
git clone https://github.com/ibm-cloud-architecture/terraform-openshift4-aws.git
6563
```
6664

67-
5. Prepare the DNS
65+
7. Prepare the DNS
6866

69-
OpenShift requires a valid DNS domain, you can get one from AWS Route53 or using existing domain and registrar. The DNS must be registered as a Public Hosted Zone in Route53. (Even if you plan to use an airgapped environment)
67+
OpenShift requires a valid public Route53 hosted zone. (Even if you plan to use an airgapped environment)
7068

71-
6. Prepare AWS Account Access
69+
8. Prepare AWS Account Access
7270

73-
Please reference the [Required AWS Infrastructure components](https://docs.openshift.com/container-platform/4.1/installing/installing_aws_user_infra/installing-aws-user-infra.html#installation-aws-user-infra-requirements_installing-aws-user-infra) to setup your AWS account before installing OpenShift 4.
71+
Please reference the [Required AWS Infrastructure components](https://docs.openshift.com/container-platform/4.6/installing/installing_aws/installing-aws-account.html) to setup your AWS account before installing OpenShift 4.
7472

7573
We suggest to create an AWS IAM user dedicated for OpenShift installation with permissions documented above.
7674
On the bastion host, configure your AWS user credential as environment variables:
@@ -85,8 +83,7 @@ This project uses mainly Terraform as infrastructure management and installation
8583

8684
For detail on OpenShift UPI, please reference the following:
8785

88-
* [https://docs.openshift.com/container-platform/4.1/installing/installing_aws_user_infra/installing-aws-user-infra.html](https://docs.openshift.com/container-platform/4.1/installing/installing_aws_user_infra/installing-aws-user-infra.html)
89-
* [https://github.com/openshift/installer/blob/master/docs/user/aws/install_upi.md](https://github.com/openshift/installer/blob/master/docs/user/aws/install_upi.md)
86+
* [https://docs.openshift.com/container-platform/4.6/installing/installing_aws/installing-aws-customizations.html](https://docs.openshift.com/container-platform/4.6/installing/installing_aws/installing-aws-customizations.html)
9087

9188
The terraform code in this repository supports 3 installation modes:
9289

@@ -105,14 +102,15 @@ This project installs the OpenShift 4 in several stages where each stage automat
105102
1. The deployment assumes that you run the terraform deployment from a Linux based environment. This can be performed on an AWS-linux EC2 instance. The deployment machine has the following requirements:
106103

107104
- git cli
108-
- terraform 0.12 or later
105+
- terraform 0.15 or later
109106
- wget command
107+
- jq command
110108

111109
2. Deploy the OpenShift 4 cluster using the following modules in the folders:
112110

113111
- route53: generate a private hosted zone using route 53
114-
- vpc: Create the VPC, subnets, security groups and load balancers for the OpenShift cluster
115112
- install: Build the installation files, ignition configs and modify YAML files
113+
- vpc: Create the VPC, subnets, security groups and load balancers for the OpenShift cluster
116114
- iam: define AWS authorities for the masters and workers
117115
- bootstrap: main module to provision the bootstrap node and generates OpenShift installation files and resources
118116
- master: create master nodes manually (UPI)
@@ -122,17 +120,15 @@ This project installs the OpenShift 4 in several stages where each stage automat
122120
Create a `terraform.tfvars` file with following content:
123121

124122
```
125-
cluster_id = "ocp4-9n2nn"
126-
clustername = "ocp4"
123+
cluster_name = "ocp4"
127124
base_domain = "example.com"
128125
openshift_pull_secret = "./openshift_pull_secret.json"
129-
openshift_installer_url = "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest"
126+
openshift_installer_url = "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.6.28"
130127
131128
aws_access_key_id = "AAAA"
132129
aws_secret_access_key = "AbcDefGhiJkl"
133130
aws_ami = "ami-06f85a7940faa3217"
134131
aws_extra_tags = {
135-
"kubernetes.io/cluster/ocp4-9n2nn" = "owned",
136132
"owner" = "admin"
137133
}
138134
aws_azs = [
@@ -146,14 +142,13 @@ aws_publish_strategy = "External"
146142

147143
|name | required | description and value |
148144
|----------------|------------|--------------|
149-
| `cluster_id` | yes | This id will be prefixed to all the AWS infrastructure resources provisioned with the script - typically using the clustername as its prefix. |
150-
| `clustername` | yes | The name of the OpenShift cluster you will install |
145+
| `cluster_name` | yes | The name of the OpenShift cluster you will install |
151146
| `base_domain` | yes | The domain that has been created in Route53 public hosted zone |
152-
| `openshift_pull_secret` | no | The value refers to a file name that contain downloaded pull secret from https://cloud.redhat.com/openshift/install; the default name is `openshift_pull_secret.json` |
147+
| `openshift_pull_secret` | no | The value refers to a file name that contain downloaded pull secret from https://cloud.redhat.com/openshift/pull-secret; the default name is `openshift_pull_secret.json` |
153148
| `openshift_installer_url` | no | The URL to the download site for Red Hat OpenShift installation and client codes. |
154149
| `aws_region` | yes | AWS region that the VPC will be created in. By default, uses `us-east-2`. Note that for an HA installation, the AWS selected region should have at least 3 availability zones. |
155150
| `aws_extra_tags` | no | AWS tag to identify a resource for example owner:myname |
156-
| `aws_ami` | yes | Red Hat CoreOS ami for your region (see [here](https://docs.openshift.com/container-platform/4.2/installing/installing_aws_user_infra/installing-aws-user-infra.html#installation-aws-user-infra-rhcos-ami_installing-aws-user-infra)). Other platforms images information can be found [here](https://github.com/openshift/installer/blob/master/data/data/rhcos.json) |
151+
| `aws_ami` | yes | Red Hat CoreOS ami for your region (see [here](https://docs.openshift.com/container-platform/4.6/installing/installing_aws/installing-aws-user-infra.html#installation-aws-user-infra-rhcos-ami_installing-aws-user-infra)). Other platforms images information can be found [here](https://github.com/openshift/installer/blob/master/data/data/rhcos.json) |
157152
| `aws_secret_access_key` | yes | adding aws_secret_access_key to the cluster |
158153
| `aws_access_key_id` | yes | adding aws_access_key_id to the cluster |
159154
| `aws_azs` | yes | list of availability zones to deploy VMs |
@@ -221,9 +216,9 @@ Setting up the mirror repository using AWS ECR:
221216
3. Mirror quay.io and other OpenShift source into your repository
222217
223218
```
224-
export OCP_RELEASE="4.3.5-x86_64"
219+
export OCP_RELEASE="4.6.28-x86_64"
225220
export LOCAL_REGISTRY='1234567812345678.dkr.ecr.us-east-1.amazonaws.com'
226-
export LOCAL_REPOSITORY='ocp435'
221+
export LOCAL_REPOSITORY='ocp46'
227222
export PRODUCT_REPO='openshift-release-dev'
228223
export LOCAL_SECRET_JSON='/home/ec2-user/openshift_pull_secret.json'
229224
export RELEASE_NAME="ocp-release"
@@ -234,20 +229,20 @@ Setting up the mirror repository using AWS ECR:
234229
--to-release-image=${LOCAL_REGISTRY}/${LOCAL_REPOSITORY}:${OCP_RELEASE}
235230
```
236231
232+
4. Provide the certificate(s) for the registry in a file and refers that from the vars to be included in the `install-config.yaml`.
233+
237234
Once the mirror registry is created - use the terraform.tfvars similar to below:
238235
239236
```
240-
cluster_id = "ocp4-9n2nn"
241-
clustername = "ocp4"
237+
cluster_name = "ocp4"
242238
base_domain = "example.com"
243239
openshift_pull_secret = "./openshift_pull_secret.json"
244-
openshift_installer_url = "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest"
240+
openshift_installer_url = "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.6.28"
245241
246242
aws_access_key_id = "AAAA"
247243
aws_secret_access_key = "AbcDefGhiJkl"
248244
aws_ami = "ami-06f85a7940faa3217"
249245
aws_extra_tags = {
250-
"kubernetes.io/cluster/ocp4-9n2nn" = "owned",
251246
"owner" = "admin"
252247
}
253248
aws_azs = [
@@ -260,31 +255,21 @@ aws_publish_strategy = "Internal"
260255
airgapped = {
261256
enabled = true
262257
repository = "1234567812345678.dkr.ecr.us-east-1.amazonaws.com/ocp435"
258+
cabundle = "./cabundle"
263259
}
264260
```
265261
266-
**Note**: To use `airgapped.enabled` of `true` must be done with `aws_publish_strategy` of `Internal` otherwise the deployment will fail.
262+
**Note**: To use `airgapped.enabled` of `true` must be done with `aws_publish_strategy` of `Internal` otherwise the deployment will fail. Also ECR does not allow for unauthenticated image pulls, additional IAM policies must be defined and attached to the nodes to be able to pull from ECR.
267263
268264
Create your cluster and then associate the private Hosted Zone Record in Route53 with the loadbalancer for the `*.apps.<cluster>.<domain>`.
269265
270-
## Removal Procedure
271-
272-
For the removal of the cluster, there are several considerations for removing AWS resources that are created by the cluster directly, but not using Terraform. These resources are unknown to terraform and must be deleted manually from AWS console.
273-
Some of these resources also hamper the ability to run `terraform destroy` as it becomes a dependent resource that prevent its parent resource to be deleted.
274-
275-
The cluster created resources are:
276-
277-
- Resources that prevents `terraform destroy` to be completed:
278-
- Worker EC2 instances
279-
- Application Load Balancer (classic load balancer) for the `*.apps.<cluster>.<domain>`
280-
- Security Group for the application load balancer
281-
- Other resources that are not deleted:
282-
- S3 resource for image-registry
283-
- IAM users for the cluster
284-
- Public Route53 Record set associated with the application load balancer
285-
266+
## Removal procedure
286267
287-
**Update 11/2020**: A `delocp.sh` is added to remove resources - if you have the aws CLI; however the script does not account for timing just yet.
268+
To delete the cluster - `terraform destroy` can be implemented.
269+
The following items are not deleted (and may stop destroy from being successful):
270+
- EBS volumes from the gp2 storage classes
271+
- Public zone DNS updates
272+
- Custom compute nodes that are not the initial worker nodes
288273
289274
## Advanced topics
290275

bootstrap/main.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@ locals {
22
public_endpoints = var.publish_strategy == "External" ? true : false
33
}
44

5+
terraform {
6+
required_providers {
7+
ignition = {
8+
source = "community-terraform-providers/ignition"
9+
version = "2.1.2"
10+
}
11+
}
12+
}
13+
14+
data "aws_partition" "current" {}
15+
16+
data "aws_ebs_default_kms_key" "current" {}
17+
518
resource "aws_s3_bucket" "ignition" {
19+
# bucket = var.ignition_bucket
620
acl = "private"
721

822
tags = merge(
@@ -60,7 +74,7 @@ resource "aws_iam_role" "bootstrap" {
6074
{
6175
"Action": "sts:AssumeRole",
6276
"Principal": {
63-
"Service": "ec2.amazonaws.com"
77+
"Service": "ec2.${data.aws_partition.current.dns_suffix}"
6478
},
6579
"Effect": "Allow",
6680
"Sid": ""
@@ -140,6 +154,8 @@ resource "aws_instance" "bootstrap" {
140154
volume_type = var.volume_type
141155
volume_size = var.volume_size
142156
iops = var.volume_type == "io1" ? var.volume_iops : 0
157+
encrypted = true
158+
kms_key_id = var.volume_kms_key_id == "" ? data.aws_ebs_default_kms_key.current.key_arn : var.volume_kms_key_id
143159
}
144160

145161
volume_tags = merge(

bootstrap/variables.tf

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ variable "ignition" {
1313
description = "The content of the bootstrap ignition file."
1414
}
1515

16+
#variable "ignition_bucket" {
17+
# type = string
18+
# description = "The S3 bucket where the ignition configuration is stored"
19+
#}
20+
1621
variable "instance_type" {
17-
type = string
22+
type = string
1823
description = "The instance type of the bootstrap node."
1924
}
2025

2126
variable "subnet_id" {
22-
type = string
27+
type = string
2328
description = "The subnet ID for the bootstrap node."
2429
}
2530

2631
variable "tags" {
27-
type = map(string)
28-
default = {}
32+
type = map(string)
33+
default = {}
2934
description = "AWS tags to be applied to created resources."
3035
}
3136

3237
variable "target_group_arns" {
33-
type = list(string)
34-
default = []
38+
type = list(string)
39+
default = []
3540
description = "The list of target group ARNs for the load balancer."
3641
}
3742

@@ -40,41 +45,46 @@ variable "target_group_arns_length" {
4045
}
4146

4247
variable "volume_iops" {
43-
type = string
44-
default = "100"
48+
type = string
49+
default = "100"
4550
description = "The amount of IOPS to provision for the disk."
4651
}
4752

4853
variable "volume_size" {
49-
type = string
50-
default = "30"
54+
type = string
55+
default = "30"
5156
description = "The volume size (in gibibytes) for the bootstrap node's root volume."
5257
}
5358

5459
variable "volume_type" {
55-
type = string
56-
default = "gp2"
60+
type = string
61+
default = "gp2"
5762
description = "The volume type for the bootstrap node's root volume."
5863
}
5964

65+
variable "volume_kms_key_id" {
66+
type = string
67+
description = "The KMS key id that should be used to encrypt the bootstrap node's root block device."
68+
}
69+
6070
variable "vpc_id" {
61-
type = string
71+
type = string
6272
description = "VPC ID is used to create resources like security group rules for bootstrap machine."
6373
}
6474

6575
variable "vpc_cidrs" {
66-
type = list(string)
67-
default = []
76+
type = list(string)
77+
default = []
6878
description = "VPC CIDR blocks."
6979
}
7080

7181
variable "vpc_security_group_ids" {
72-
type = list(string)
73-
default = []
82+
type = list(string)
83+
default = []
7484
description = "VPC security group IDs for the bootstrap node."
7585
}
7686

7787
variable "publish_strategy" {
78-
type = string
88+
type = string
7989
description = "The publishing strategy for endpoints like load balancers"
8090
}

0 commit comments

Comments
 (0)