Skip to content

Commit d98ca65

Browse files
committed
Updated Reviewed Changes
1 parent b19d929 commit d98ca65

File tree

21 files changed

+346
-346
lines changed

21 files changed

+346
-346
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# _TF: IBM K8s s390x Build Cluster_
2+
These terraform resources define a IBM Cloud project containing a s390xVS cluster intended to serve as a "build cluster" for prow.k8s.io.
3+
4+
---
5+
## Initial Setup
6+
7+
### Supporting infrastructure
8+
9+
#### Deploy k8s-infra-setup resources
10+
11+
- this covers things like Resource Group, s390x Virtual Server Instances, Virtual Private Cloud, IBM Cloud Secret Manager Secrets, etc.
12+
- Once the deployment successfully completes, the `secrets_manager_id` will be generated and should be used in the subsequent steps.
13+
14+
---
15+
#### Deploy k8s-s390x-build-cluster resources
16+
17+
**1. Navigate to the correct directory**
18+
<br> You need to be in the `k8s-s390x-build-cluster` directory to run the automation.
19+
20+
**2. Export COS Secrets**
21+
<br> Export `access_key` and `secret_key` as environment variables.
22+
```
23+
export AWS_ACCESS_KEY_ID="<HMAC_ACCESS_KEY_ID>"
24+
export AWS_SECRET_ACCESS_KEY="<HMAC_SECRET_ACCESS_KEY>"
25+
```
26+
27+
**3. Initialize Terraform**
28+
<br> Execute the following command to initialize Terraform in your project directory. This command will download the necessary provider plugins and prepare the working environment.
29+
```
30+
terraform init -reconfigure
31+
```
32+
33+
**4. Check the `variables.tf` file**
34+
<br> Open the `variables.tf` file to review all the available variables. This file lists all customizable inputs for your Terraform configuration.
35+
36+
`ibmcloud_api_key`, `secrets_manager_id` are the only required variables that you must set in order to proceed. You can set this key either by adding it to your `var.tfvars` file or by exporting it as an environment variable.
37+
38+
**Option 1:** Set in `var.tfvars` file
39+
Create `var.tfvars` file and set the following variables in `var.tfvars` file:
40+
```
41+
ibmcloud_api_key = "<YOUR_API_KEY>"
42+
secrets_manager_id = "<SECRETS_MANAGER_ID>"
43+
```
44+
Tip: To get the secrets_manager_id (GUID) for IBM Cloud Secrets Manager instance:
45+
```
46+
ibmcloud resource service-instances --service-name secrets-manager --output JSON | \
47+
jq -r '.[] | select(.name | contains("k8s-s390x")) | .guid'
48+
```
49+
**Option 2:** Export as an environment variable
50+
Alternatively, you can export above as an environment variable before running Terraform:
51+
```
52+
export TF_VAR_ibmcloud_api_key="<YOUR_API_KEY>"
53+
export TF_VAR_secrets_manager_id=$(ibmcloud resource service-instances --service-name secrets-manager --output JSON | \
54+
jq -r '.[] | select(.name | contains("k8s-s390x")) | .guid')
55+
```
56+
57+
**5. Run Terraform Apply**
58+
<br> After setting the necessary variables (particularly the API_KEY), execute the following command to apply the Terraform configuration and provision the infrastructure:
59+
```
60+
terraform apply -var-file var.tfvars
61+
```
62+
Terraform will display a plan of the actions it will take, and you'll be prompted to confirm the execution. Type `yes` to proceed.
63+
64+
**6. Get Output Information**
65+
<br> Once the infrastructure has been provisioned, use the terraform output command to list details about the provisioned resources.
66+
```
67+
terraform output
68+
```
69+
70+
**7. Set up the Kubernetes cluster using ansible**
71+
Clone the repository `https://github.com/kubernetes-sigs/provider-ibmcloud-test-infra` and change the directory to `kubetest2-tf/data/k8s-ansible`:
72+
```
73+
cd kubetest2-tf/data/k8s-ansible
74+
```
75+
76+
**8. Install ansible on the deployer VM**
77+
```
78+
dnf install ansible -y
79+
```
80+
81+
**9. Update the fields under `group_vars/all` to include the Kubernetes version to install**
82+
<br> The following lines will update the version to the latest stable release of Kubernetes. You can modify it accordingly to set up the CI (alpha) version.
83+
```
84+
K8S_VERSION=$(curl -Ls https://dl.k8s.io/release/stable.txt)
85+
LOADBALANCER_EP=<mention the loadbalancer endpoint obtained from terraform output>
86+
sed -i \
87+
-e "s/^directory: .*/directory: release/" \
88+
-e "s/build_version: .*/build_version: $K8S_VERSION/" \
89+
-e "s/release_marker: .*/release_marker: $K8S_VERSION/" \
90+
-e "s/loadbalancer: .*/loadbalancer: $LOADBALANCER_EP/" group_vars/all
91+
```
92+
93+
**10. Update the fields under `examples/k8s-build-cluster/hosts.yml` to contain IP addresses of the VMs to set up Kubernetes**
94+
```
95+
For example:
96+
97+
[bastion]
98+
56.77.34.6
99+
100+
[masters]
101+
192.168.100.3
102+
192.168.100.4
103+
104+
[workers]
105+
192.168.100.5
106+
192.168.100.6
107+
192.168.100.7
108+
109+
[workers:vars]
110+
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -i <path/to/private-key> -q [email protected]" -i <path/to/private-key>'
111+
112+
[masters:vars]
113+
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -i <path/to/private-key> -q [email protected]" -i <path/to/private-key>'
114+
```
115+
116+
**11. Update the fields under `group_vars/bastion_configuration` to contain the information of the private network.**
117+
```
118+
For example:
119+
120+
bastion_private_gateway: 192.168.100.1
121+
bastion_private_ip: 192.168.100.2
122+
```
123+
124+
**12. Trigger the installation using ansible**
125+
```
126+
ansible-playbook -v -i examples/k8s-build-cluster/hosts.yml install-k8s-ha.yaml -e @group_vars/bastion_configuration --extra-vars @group_vars/all
127+
```

infra/ibmcloud/terraform/k8s-s390x-build-cluster/bastion.tf

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,37 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
17+
locals {
18+
bastion_nodes = {
19+
"primary" = {
20+
profile = var.bastion_profile
21+
boot_volume = {
22+
size = var.bastion_boot_volume_size
23+
}
24+
}
25+
}
26+
}
27+
1628
resource "ibm_is_instance" "bastion" {
17-
count = var.bastion.count
18-
name = "bastion-s390x-${count.index + 1}"
29+
for_each = local.bastion_nodes
30+
name = "bastion-s390x-${each.key}"
1931
vpc = data.ibm_is_vpc.vpc.id
2032
zone = var.zone
21-
profile = var.bastion.profile
33+
profile = each.value.profile
2234
image = var.image_id
2335
keys = [ibm_is_ssh_key.k8s_ssh_key.id]
2436
resource_group = data.ibm_resource_group.resource_group.id
37+
2538
primary_network_interface {
26-
name = "public-nic"
39+
name = "public-nic-${each.key}"
2740
subnet = data.ibm_is_subnet.subnet.id
28-
security_groups = [data.ibm_is_security_group.bastion_sg.id]
41+
security_groups = [data.ibm_is_security_group.bastion.id]
2942
}
3043

3144
boot_volume {
32-
name = "boot-vol-bastion-${count.index}"
33-
size = var.bastion.boot_volume.size
45+
name = "boot-vol-bastion-${each.key}"
46+
size = each.value.boot_volume.size
3447
}
3548

3649
user_data = <<-EOF
@@ -70,60 +83,16 @@ resource "ibm_is_instance" "bastion" {
7083
- [netfilter-persistent, save]
7184
- [systemctl, restart, systemd-networkd]
7285
- [systemctl, restart, sshd]
73-
- [hostnamectl, set-hostname, "bastion-s390x-${count.index + 1}.s390x-vpc.cloud.ibm.com"]
74-
- [echo, "bastion-s390x-${count.index + 1}.s390x-vpc.cloud.ibm.com", ">", /etc/hostname]
75-
- [sed, -i, "s/^127.0.1.1.*/127.0.1.1\tbastion-s390x-${count.index + 1}.s390x-vpc.cloud.ibm.com/", /etc/hosts]
86+
- [hostnamectl, set-hostname, "bastion-s390x-${each.key}.s390x-vpc.cloud.ibm.com"]
87+
- [echo, "bastion-s390x-${each.key}.s390x-vpc.cloud.ibm.com", ">", /etc/hostname]
88+
- [sed, -i, "s/^127.0.1.1.*/127.0.1.1\tbastion-s390x-${each.key}.s390x-vpc.cloud.ibm.com/", /etc/hosts]
89+
- [touch, /var/lib/cloud/instance/bastion-setup-success]
7690
EOF
7791
}
7892

7993
resource "ibm_is_floating_ip" "bastion_fip" {
80-
count = var.bastion.count
81-
name = "bastion-fip-${count.index}"
82-
target = ibm_is_instance.bastion[count.index].primary_network_interface[0].id
94+
for_each = ibm_is_instance.bastion
95+
name = "bastion-fip-${each.key}"
96+
target = each.value.primary_network_interface[0].id
8397
resource_group = data.ibm_resource_group.resource_group.id
8498
}
85-
86-
resource "time_sleep" "wait_for_bastion" {
87-
count = var.bastion.count
88-
depends_on = [ibm_is_floating_ip.bastion_fip]
89-
90-
create_duration = "180s" # Wait 3 minutes for full initialization
91-
}
92-
93-
resource "null_resource" "bastion_setup" {
94-
count = var.bastion.count
95-
depends_on = [time_sleep.wait_for_bastion]
96-
97-
connection {
98-
type = "ssh"
99-
user = "root"
100-
host = ibm_is_floating_ip.bastion_fip[count.index].address
101-
private_key = data.ibm_sm_arbitrary_secret.ssh_private_key.payload
102-
timeout = "5m"
103-
}
104-
105-
provisioner "remote-exec" {
106-
inline = [
107-
# Network verification
108-
"echo '=== Network Interfaces ==='",
109-
"ip -4 addr show",
110-
"echo '=== Routing Table ==='",
111-
"ip route",
112-
"echo '=== NAT Configuration ==='",
113-
"iptables -t nat -L -n -v",
114-
"echo '=== IP Forwarding ==='",
115-
"sysctl net.ipv4.ip_forward",
116-
117-
# Hostname verification
118-
"echo '=== Hostname ==='",
119-
"hostname",
120-
"hostnamectl",
121-
"cat /etc/hostname",
122-
123-
# Final security updates
124-
"command -v apt-get >/dev/null && apt-get update -y && apt-get upgrade -y --security || true",
125-
"command -v yum >/dev/null && yum update -y --security || true",
126-
"command -v dnf >/dev/null && dnf update -y --security || true"
127-
]
128-
}
129-
}

infra/ibmcloud/terraform/k8s-s390x-build-cluster/data.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ data "ibm_is_subnet" "subnet" {
2525
name = "k8s-s390x-subnet"
2626
}
2727

28-
data "ibm_is_security_group" "bastion_sg" {
28+
data "ibm_is_security_group" "bastion" {
2929
name = "k8s-vpc-s390x-bastion-sg"
3030
vpc = data.ibm_is_vpc.vpc.id
3131
}
3232

33-
data "ibm_is_security_group" "master_sg" {
34-
name = "k8s-vpc-s390x-master-sg"
33+
data "ibm_is_security_group" "control_plane_sg" {
34+
name = "k8s-vpc-s390x-control-plane-sg"
3535
vpc = data.ibm_is_vpc.vpc.id
3636
}
3737

infra/ibmcloud/terraform/k8s-s390x-build-cluster/load_balancer.tf

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,39 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
resource "ibm_is_lb" "k8s_load_balancer" {
17-
name = "k8s-s390x-lb"
16+
resource "ibm_is_lb" "public" {
17+
name = "k8s-s390x-ci"
1818
type = "public"
1919
subnets = [data.ibm_is_subnet.subnet.id]
2020
resource_group = data.ibm_resource_group.resource_group.id
21-
security_groups = [data.ibm_is_security_group.master_sg.id]
21+
security_groups = [data.ibm_is_security_group.control_plane_sg.id]
2222
}
2323

2424
resource "ibm_is_lb_pool" "k8s_api_pool" {
2525
name = "k8s-api-server-pool"
26-
lb = ibm_is_lb.k8s_load_balancer.id
26+
lb = ibm_is_lb.public.id
2727
protocol = "tcp"
2828
algorithm = "round_robin"
2929
health_delay = 5
3030
health_retries = 2
3131
health_timeout = 2
3232
health_type = "tcp"
3333
health_monitor_url = "/"
34-
health_monitor_port = 6443
34+
health_monitor_port = var.api_server_port
3535
}
3636

3737
resource "ibm_is_lb_listener" "k8s_api_listener" {
38-
lb = ibm_is_lb.k8s_load_balancer.id
38+
lb = ibm_is_lb.public.id
3939
protocol = "tcp"
40-
port = 6443
40+
port = var.api_server_port
4141
default_pool = ibm_is_lb_pool.k8s_api_pool.pool_id
4242
}
4343

4444
resource "ibm_is_lb_pool_member" "k8s_api_members" {
45-
count = var.control_plane.count
46-
lb = ibm_is_lb.k8s_load_balancer.id
45+
for_each = ibm_is_instance.control_plane
46+
47+
lb = ibm_is_lb.public.id
4748
pool = ibm_is_lb_pool.k8s_api_pool.pool_id
48-
port = 6443
49-
target_address = ibm_is_instance.control_plane[count.index].primary_network_interface[0].primary_ipv4_address
49+
port = var.api_server_port
50+
target_address = each.value.primary_network_interface[0].primary_ipv4_address
5051
}

0 commit comments

Comments
 (0)