ionos-cloud / ionosctl

The IONOS Cloud CLI (ionosctl) gives the ability to manage IONOS Cloud infrastructure directly from Command Line.
Apache License 2.0
28 stars 6 forks source link

Allow to pass networks while creating k8s nodepool #298

Closed Programie closed 9 months ago

Programie commented 1 year ago

Use-cases

When creating a new nodepool, it is possible to define the LAN IDs which should be attached to the worker nodes. Unfortunately, it is not possible to also define the networks and gateways for them.

Therefore, when creating a new nodepool, we have to first create the nodepool without the attached private LAN, wait for it to become ready and after that attach the private LAN which results in recreating the nodepool (which takes some time depending on the size of the nodepool).

Attempted Solutions

Nothing so far.

Proposal

Allow to also define the networks to be routed to the LAN while creating the nodepool.

I know, the command line might be really cluttered doing it that way. And you might also have to think about a way how to define the networks for each LAN to be attached.

One quite ugly option to define it would be to allow giving --lan-ids multiple times (maybe then renamed to --lan-id as it is only a single LAN) listing the LAN ID followed by the networks and gateways. Something like the following:

ionosctl k8s nodepool create \
    --datacenter-id DATACENTER_ID \
    --cluster-id CLUSTER_ID \
    --name NAME \
    --lan-id "1|10.0.0.0/9,10.128.0.0/10,10.192.0.0/12|10.70.80.1,10.70.80.1,10.70.80.1" \
    --lan-id "2|192.168.0.0/16|192.168.1.1"

Another approach might be to define the properties in a config file which also supports nesting (i.e. JSON or YAML) and then simply provide the config file on the command line.

Example:

ionosctl k8s nodepool create /path/to/options.json

options.json:

{
    "datacenter-id": "DATACENTER_ID",
    "cluster-id": "CLUSTER_ID",
    "name": "NAME",
    "lan-ids": [
        {
            "id": 1,
            "networks": [
                "10.0.0.0/9",
                "10.128.0.0/10",
                "10.192.0.0/12"
            ],
            "gateways": [
                "10.70.80.1",
                "10.70.80.1",
                "10.70.80.1"
            ]
        },
        {
            "id": 2,
            "networks": [
                "192.168.0.0/16"
            ],
            "gateways": [
                "192.168.1.1"
            ]
        }
    ]
}

The config variant might be also useful for the other create commands.

avirtopeanu-ionos commented 1 year ago

Firstly, thank you for your detailed issue. I have also thought of this config/options json file approach. In my opinion it's a very streamlined approach and it's a pretty clear/structured way to define resources.

However, have you considered IaC tools such as https://github.com/ionos-cloud/terraform-provider-ionoscloud/ or https://github.com/ionos-cloud/module-ansible ? They are designed for use cases such as the one you describe

Regarding the --lan-id approach, even though it is not the most user-friendly and I'm not a big fan of it, it could be a feasible workaround.

Thanks for opening the issue, I'll update this thread as soon we've made a decision regarding this proposal, have a nice day!

Programie commented 1 year ago

Yes, we've already evaluated Terraform. Unfortunately, it doesn't exactly fit our use-case as we just want to create Kubernetes clusters and nodepools without actually keeping the state somewhere. Therefore we want to use ionosctl for that.

avirtopeanu-ionos commented 9 months ago

Hi! Since #391 you can now use --json-properties-example and --json-properties <JSON-FILE-PATH> to create k8s nodepools. Set the properties.lans array to pass networks to the command.

This functionality will be available since v6.7.2. If you encounter any problems, please open a new issue or we can re-open this one.

Programie commented 9 months ago

I just tested the new functionality but for me it is not working.

I used the JSON returned by ionosctl k8s nodepool create --json-properties-example, dumped it to a file and modified some values to match our setup. But it seems like the file is not used at all as ionosctl complains about an unsupported CPU family "AMD_OPTERON" even if I specified "INTEL_SKYLAKE" in the file.

Removing the cpuFamily property from the file and manually specifying it as --cpu-family INTEL_SKYLAKE works and then confirmed my guess about the file not being used at all as everything in the file is just ignored. For example, the nodepool does not contain the amount of nodes, the configured CPU cores, RAM, HDD size, etc.