Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

VariableDeclared
Copy link

  • Demo for Microcloud on a single node (e.g. Laptop or Workstation)

- Demo for Microcloud on a single node (e.g. Laptop or Workstation)
@VariableDeclared VariableDeclared changed the title Microcloud demo [LXD-1337] Microcloud demo folder Aug 6, 2024
Copy link
Contributor

@roosterfish roosterfish left a 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?

@VariableDeclared
Copy link
Author

Thank you @roosterfish I will make those adjustments shortly

Copy link
Contributor

@roosterfish roosterfish left a 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.

required_providers {
lxd = {
source = "terraform-lxd/lxd"
version = "2.0.0"
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

version = "2.0.0"
}
ssh = {
source = "loafoe/ssh"
Copy link
Contributor

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

Copy link
Author

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?

# Configuration options
}
locals {
cloud_init = <<EOT
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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: &&, ||, <, >, <=, >=, ==, !=, !
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

@@ -0,0 +1,42 @@

Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still says tofu.

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still tofu.

Copy link
Author

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 |
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Author

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:
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@VariableDeclared
Copy link
Author

thank you @roosterfish will pop it on the stack for review

@VariableDeclared
Copy link
Author

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
@VariableDeclared VariableDeclared force-pushed the variabledeclared/mc-demos branch from 20034e3 to ea47d6c Compare September 11, 2024 18:11
@VariableDeclared
Copy link
Author

afternoon @roosterfish any chance of getting your view here?

@masnax
Copy link
Contributor

masnax commented Sep 19, 2024

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 :)

@VariableDeclared
Copy link
Author

hehe fair enough! thank you @masnax !

@roosterfish
Copy link
Contributor

@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 lxc launch command three times with the appropriate cloud-init configuration which would save you from using Terraform at all for the deployment.

If I understood right, the use case here would be to show how to easily deploy a test setup of MicroCloud using Terraform.
But as Terraform might be solely used to spawn three machines, in my opinion having it makes the process more complex than just spawning the machines using LXD. Or do I miss anything here?

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?

@VariableDeclared
Copy link
Author

VariableDeclared commented Oct 7, 2024

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 lxc launch commands (and only three commands?) In which case, lets drop this PR and use that.

@roosterfish
Copy link
Contributor

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

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.
Therefore my suggestion was to keep cloud init in the mix but don't require the extra SSH resource to run it.

Can you demonstrate microcloud creation with three lxc launch commands (and only three commands?) In which case, lets drop this PR and use that.

I was mainly talking about the process of spawning the machines and configuring the cloud init file on them.
The Terraform files in this PR also include the setup of three additional storage disks ("sdb") but you could also achieve this by adding another device to the used (I assume default) profile to keep the overall number of commands low.

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.

@roosterfish
Copy link
Contributor

Hi @VariableDeclared, coming back to this (sorry it took some time).

With MicroCloud 2 you can now run the microcloud preseed command on all the members that should join into the cluster using the exact same preseed file (as before). If necessary the preseed file could also be set via cloud-init as part of starting the instances:

#!/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.

@VariableDeclared
Copy link
Author

Hello @roosterfish - no problem. Will add it to the stack, please give me some time to revert to you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants