Newer
Older
# meta-metaseminar-hands-on-2023-04-28 Infrastructure as Code demo
There are presented two simple approaches:
* [infrastructure using terraform (best practice)](./terraform_group_project)
* [infrastructure using command-line openstack client](./commandline)
## Hands-on container
```sh
docker pull registry.gitlab.ics.muni.cz:443/246254/metaseminar-hands-on-2023-04-28/hands-on-tools:latest
```
## Hands-on Horizon
Using the OpenStack personal project.
### 1. Generate SSH keypair
You may need to have testing SSH key pair
```sh
# docker run -it --rm registry.gitlab.ics.muni.cz:443/246254/metaseminar-hands-on-2023-04-28/hands-on-tools:latest
# generate in-container ssh keypair
ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
### 2. [Horizon UI login](https://dashboard.cloud.muni.cz)
### 3. Register new SSH pubkey ([Compute -> Key Pairs](https://dashboard.cloud.muni.cz/project/key_pairs))
### 4. Create VM ([Compute -> Instances -> Launch instance](https://dashboard.cloud.muni.cz/project/instances/))
1. Details subpage: Specify Instance name.
1. Source subpage: Select boot source image or existing bootable volume.
1. Flavor subpage: Pick one of available (standard) flavors.
1. Networks subpage: Pick one of the pre-created personal project networks. 147-251-115-pers-proj-net
1. Network ports subpage: skip
1. Security groups subpage: Pick default.
1. Key Pair subpage: Pick created above keypair.
1. Configuration subpage allows to define cloud-init configuration. Skip and Launch instance.
### 5. VM inspection Compute -> Instances -> Pick instance
* Overview
* Name & ID
* Spec i.e. flavor
* Security Groups, verify existing ingress rules
* Volumes attached
* Interfaces
* selected network
* (Console) Log
* inspect cloud-init modifications
### 6. Associating FIP public IPv4 address
### 7. Associating public IPv6 address
### 8. Generating Application Credentials ([Identity -> Application Credentials](https://dashboard.cloud.muni.cz/identity/application_credentials/))
## Hands-on command-line client in group project
```sh
# docker run -it --rm registry.gitlab.ics.muni.cz:443/246254/metaseminar-hands-on-2023-04-28/hands-on-tools:latest
# read-in the openstack credentials
source /tmp/ac/prod-metaseminar-hands-on-2023-04-28-openrc.sh.inc
# test whether cloud is accessible
cd openstack-infrastructure-as-code-automation/clouds/g1/brno/meta-metaseminar-hands-on-2023-04-28/commandline/
./cmdline-demo-group-project.sh freznicek-demo # use your own name as custom infrastructure prefix in the single hands-on project
```
## Hands-on terraform
```sh
# docker run -it --rm registry.gitlab.ics.muni.cz:443/246254/metaseminar-hands-on-2023-04-28/hands-on-tools:latest
# generate in-container ssh keypair, if not done already
[ -e ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub
...
# read-in the openstack credentials
source /tmp/ac/prod-metaseminar-hands-on-2023-04-28-openrc.sh.inc
# test whether cloud is accessible
openstack version show | grep identity
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# enter terraform workspace
cd openstack-infrastructure-as-code-automation/clouds/g1/brno/meta-metaseminar-hands-on-2023-04-28/terraform_group_project/
# change infrastructure prefix
mcedit main.tf # kusername = freznicek
# initial deploy via terraform
terraform init
terraform validate
terraform plan --out plan
terraform apply plan
# login to VM
ncat -z <ip-address> 22
ssh ubuntu@<ip-address>
# doublecheck in horizon in meta-metaseminar-hands-on-2023-04-28 project
# https://dashboard.cloud.muni.cz
# scaling 1->3 VMs
# https://gitlab.ics.muni.cz/cloud/g2/openstack-infrastructure-as-code-automation/-/blob/8c66c1502f2cba26cf9dd51e89c118966ba5e6ed/clouds/g1/brno/meta-metaseminar-hands-on-2023-04-28/terraform_group_project/main.tf#L25
mcedit main.tf # nodes_count = 3
terraform validate
terraform plan --out plan
terraform apply plan
# doublecheck in horizon in meta-metaseminar-hands-on-2023-04-28 project
# https://dashboard.cloud.muni.cz
# delete VM via Horizon, and re-deploy via Horizon
# * point out idential internal IP address
terraform validate && terraform plan --out plan && terraform apply plan
# scaling 3->1 VMs
# https://gitlab.ics.muni.cz/cloud/g2/openstack-infrastructure-as-code-automation/-/blob/8c66c1502f2cba26cf9dd51e89c118966ba5e6ed/clouds/g1/brno/meta-metaseminar-hands-on-2023-04-28/terraform_group_project/main.tf#L25
mcedit main.tf # nodes_count = 1
terraform validate && terraform plan --out plan && terraform apply plan
# doublecheck in horizon in meta-metaseminar-hands-on-2023-04-28 project
# https://dashboard.cloud.muni.cz
# two disks /dev/sd[ab]
ssh ubuntu@<ip-address> 'lsblk'
# add additional volume (not enough data)
mcedit main.tf # sdc_volume = 1
terraform validate && terraform plan --out plan && terraform apply plan
# two disks /dev/sd[abc]
ssh ubuntu@<ip-address> 'lsblk'
# remove original volume
mcedit main.tf # sdb_volume = 0
terraform validate && terraform plan --out plan && terraform apply plan
# two disks /dev/sd[ac]
ssh ubuntu@<ip-address> 'lsblk'
# destroy whole infrastructure
terraform destroy
```