-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LXD-1337] Microcloud demo folder #366
base: main
Are you sure you want to change the base?
[LXD-1337] Microcloud demo folder #366
Conversation
VariableDeclared
commented
Aug 5, 2024
- Demo for Microcloud on a single node (e.g. Laptop or Workstation)
- Demo for Microcloud on a single node (e.g. Laptop or Workstation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
I was halfway through the PR until I realized it's not a tutorial for how to use MicroCloud together with Terraform/OpenTofu to deploy resources (like in the roadshow repo) but instead it shows how to deploy a MicroCloud using Terraform.
So it's essentially the same as https://canonical-microcloud.readthedocs-hosted.com/en/latest/microcloud/tutorial/get_started/ but running non-interactively.
@mseralessandri Going forward I am wondering if we should advocate this way of setting up MicroCloud as part of the official docs?
Thank you @roosterfish I will make those adjustments shortly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @VariableDeclared, left some general comments about how we can tackle this in regard to the used tooling.
To allow having additional demos in the future, I think it would be worth creating the following directory structure:
demos/
\_ terraform/
\_ nested-deployment/ <- you can place your *.tf files here
\_ templates
This would make use of the general Terraform way of adding *.tf
files into a .../terraform/...
folder.
It will also allow to add other Terraform demos in the future that create actual workload on top of a MicroCloud.
Also please include the changes in multiple commits, one for each type of resource.
E.g. there should be a commit which adds the additions to the doc and another one that adds the Terraform code.
demos/microcloud-deploy/main.tf
Outdated
required_providers { | ||
lxd = { | ||
source = "terraform-lxd/lxd" | ||
version = "2.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already is a 2.3.0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
demos/microcloud-deploy/main.tf
Outdated
version = "2.0.0" | ||
} | ||
ssh = { | ||
source = "loafoe/ssh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not using the built-in remote-exec
provisioner from Terraform directly? https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a opentofu requirement - I can switch back to the terraform built-in - what do you think?
demos/microcloud-deploy/main.tf
Outdated
# Configuration options | ||
} | ||
locals { | ||
cloud_init = <<EOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't the MicroCloud preseed file also be included in the cloud init? You can then use runcmd
to execute the microcloud init --preseed
command.
This way you won't need either SSH or the provisioner (and a key pair) to connect to the machine and to run the command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could still use the templating engine from Terraform to generate the preseed.yml
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - it can be included - the issue is that cloud-init is going to run on all three nodes, so you're writing the file out on all three unnecessarily. The issue is without some custom logic in cloud-init, there's no way to decide to pick a 'leader' to run the init phase of this, so I'm not sure what we'd be saving here - do you have some way which we could remove the ssh remote exec and only run init on the leader via cloud-init?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After #383 is being merged, you would need to put the preseed file on all of the nodes anyway.
Also a initiator/leader has to be picked as part of crafting the preseed file (see https://github.com/canonical/microcloud/pull/383/files#diff-14d3c025154c62cbd2816232e7d56a1d80c9389b77d2eebdac004c646af8783d for reference).
With cloud-init you would then run microcloud preseed
on all nodes and MicroCloud will pick the selected initiator/leader automatically.
# The names and values of each key correspond to the YAML field names for the `api.ResouresStorageDisk` | ||
# struct here: | ||
# https://github.com/canonical/lxd/blob/c86603236167a43836c2766647e2fac97d79f899/shared/api/resource.go#L591 | ||
# Supported operands: &&, ||, <, >, <=, >=, ==, !=, ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To cleanup the template, it would be worth removing the comments from the official docs together with any unsused keys.
If you want to learn more about the keys, you can always consult the official docs.
Maybe having a link to the docs at the beginning of the file would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense
demos/microcloud-deploy/variables.tf
Outdated
@@ -0,0 +1,42 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required newline at the beginning of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
sudo lxd init --auto | ||
``` | ||
|
||
## Init tofu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still says tofu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed this
## Apply the plan | ||
|
||
``` | ||
tofu apply |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still tofu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed this
|
||
| Variable Name | Purpose | | ||
| ------------------------ | ----------------------------------------------------- | | ||
| pro_token | Can be ignored for now | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth including it if it's not used or ignored?
tofu apply | ||
``` | ||
|
||
## Init Microcloud |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into the apply
section above explaining what is actually happening at this stage? As this is where the deployment is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved up
The terraform will automatically trigger an initialisation, via the non-interactive method - more information can be found here: https://canonical-microcloud.readthedocs-hosted.com/en/latest/how-to/initialise/#non-interactive-configuration | ||
|
||
|
||
## TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should be removed before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
thank you @roosterfish will pop it on the stack for review |
thank you @roosterfish for your review - maybe just some feedback on the remote exec part & ssh provisioner. The issue is that we need some logic there for the leader - looking forward to digging into your perspective on that |
- Restructure folders - Remove tofu references
20034e3
to
ea47d6c
Compare
afternoon @roosterfish any chance of getting your view here? |
@VariableDeclared @roosterfish is away for a week, so I'll try to take a look as well :) |
hehe fair enough! thank you @masnax ! |
@VariableDeclared Hi, after looking at this PR again and the comment about removing the SSH resource, I am wondering if it would still make sense to keep Terraform in the mix for the base deployment. You can achieve the same by running the If I understood right, the use case here would be to show how to easily deploy a test setup of MicroCloud using Terraform. Maybe instead of showing how to deploy a MicroCloud using Terraform (which is already documented step by step here and parts of it (e.g. bridge creation) are also required for this Terraform example), instead the Terraform tutorial should focus on the actual workload creation inside of MicroCloud (like it's done in the roadshow repo). This would provide real world examples to customers which can be used not only for test setups but also for production grade MicroCloud clusters. What do you think? |
hello @roosterfish - yes you can create these by hand but the process is actually more involved than three commands, the process is more aligned to the link you sent (https://canonical-microcloud.readthedocs-hosted.com/en/latest/microcloud/tutorial/get_started/) - but if im a user who wants to play around with Microcloud, or create a dev microcloud - I'm not going to run those steps every time. Or in the case of field - we need to execute those steps for customer demos, for example. Running them every time is laborious and error prone. This is why the terraform was created. Can you demonstrate microcloud creation with three |
I am fully with you that running all the things in the cloud init file is tedious if you just want to have a small and working MicroCloud.
I was mainly talking about the process of spawning the machines and configuring the cloud init file on them. My recommendation would be to wait until #383 is merged so we can make use of this and identify the minimal required set of commands. On another node the naming of resources etc. should be closely aligned with the already existing guide so it's easy for a user to switch between the concepts. |
Hi @VariableDeclared, coming back to this (sorry it took some time). With MicroCloud 2 you can now run the #!/bin/bash
preseed="lookup_subnet: 10.87.144.0/24
initiator: micro01
session_passphrase: foo
systems:
- name: micro01
ovn_uplink_interface: enp6s0
storage:
ceph:
- path: /dev/sdb
- name: micro02
ovn_uplink_interface: enp6s0
storage:
ceph:
- path: /dev/sdb
- name: micro03
ovn_uplink_interface: enp6s0
storage:
ceph:
- path: /dev/sdb
ovn:
ipv4_gateway: 10.1.123.1/24
ipv4_range: 10.1.123.10-10.1.123.100"
for i in $(seq 1 3); do
lxc exec "micro0$i" -- microcloud preseed <<< "$preseed" &
done
wait See also the init docs here https://canonical-microcloud.readthedocs-hosted.com/en/latest/microcloud/how-to/initialise/#non-interactive-configuration. |
Hello @roosterfish - no problem. Will add it to the stack, please give me some time to revert to you :) |