Skip to content

Commit

Permalink
generate automatically the k3k cli doc, update readme and advanced-us…
Browse files Browse the repository at this point in the history
…age doc
  • Loading branch information
jp-gouin committed Feb 26, 2025
1 parent 9c417c4 commit 12720a7
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 186 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This section provides instructions on how to install K3k and the `k3kcli`.
* An existing [RKE2](https://docs.rke2.io/install/quickstart) Kubernetes cluster (recommended).
* A configured storage provider with a default storage class.

**Note:** If you do not have a storage provider, you can configure the cluster to use ephemeral or static storage. Please consult the [CLI documentation](./docs/cli.md#examples-for-no-storage-provider) for instructions on using these options.
**Note:** If you do not have a storage provider, you can configure the cluster to use ephemeral or static storage. Please consult the [k3kcli advance usage](./docs/advanced-usage.md#using-the-cli) for instructions on using these options.

### Install the K3k controller

Expand Down
34 changes: 33 additions & 1 deletion docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This document provides advanced usage information for k3k, including detailed us

The `Cluster` resource provides a variety of fields for customizing the behavior of your virtual clusters. You can check the [CRD documentation](./crds/crd-docs.md) for the full specs.

**Note:** Most of these customization options can also be configured using the `k3kcli` tool. Refer to the `k3kcli` documentation for more details.
**Note:** Most of these customization options can also be configured using the `k3kcli` tool. Refer to the [k3kcli](./cli/cli-docs.md) documentation for more details.



Expand Down Expand Up @@ -112,3 +112,35 @@ The `clusterDNS` field specifies the IP address for the CoreDNS service. It need
### `serverArgs`

The `serverArgs` field allows you to specify additional arguments to be passed to the K3s server pods.

## Using the cli

You can check the [k3kcli documentation](./cli/cli-docs.md) for the full specs.

### Examples for no storage provider:

* Ephemeral Storage:

```bash
k3kcli cluster create my-cluster --persistence-type ephemeral
```

* Static Storage (Requires pre-provisioned PVs):

```bash
k3kcli cluster create my-cluster --persistence-type static
```

(You will need to ensure that persistent volumes that match the requirements of your k3k cluster exist before creation)

*Important Notes:*

* When using `--persistence-type static`, you must manually create PersistentVolumes (PVs) that match the storage requirements of your K3K cluster.

* Using `--persistence-type ephemeral` will result in data loss if the nodes are restarted.

* It is highly recommended to use `--persistence-type dynamic` with a configured storage class.
184 changes: 0 additions & 184 deletions docs/cli.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/cli/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: gendoc

gendoc:
@go run ./genclidoc.go
98 changes: 98 additions & 0 deletions docs/cli/cli-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# NAME

k3kcli - CLI for K3K

# SYNOPSIS

k3kcli

```
[--debug]
```

**Usage**:

```
k3kcli [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
```

# GLOBAL OPTIONS

**--debug**: Turn on debug logs


# COMMANDS

## cluster

cluster command

### create

Create new cluster

>k3kcli cluster create [command options] NAME
**--agent-args**="": agents extra arguments

**--agents**="": number of agents (default: 0)

**--cluster-cidr**="": cluster CIDR

**--kubeconfig**="": kubeconfig path (default: "/home/jpgouin/.kube/config")

**--kubeconfig-server**="": override the kubeconfig server host

**--mode**="": k3k mode type (shared, virtual) (default: "shared")

**--namespace**="": namespace to create the k3k cluster in

**--persistence-type**="": persistence mode for the nodes (ephemeral, static, dynamic) (default: "dynamic")

**--server-args**="": servers extra arguments

**--servers**="": number of servers (default: 1)

**--service-cidr**="": service CIDR

**--storage-class-name**="": storage class name for dynamic persistence type

**--token**="": token of the cluster

**--version**="": k3s version

### delete

Delete an existing cluster

>k3kcli cluster delete [command options] NAME
**--kubeconfig**="": kubeconfig path (default: "/home/jpgouin/.kube/config")

**--namespace**="": namespace to create the k3k cluster in

## kubeconfig

Manage kubeconfig for clusters

### generate

Generate kubeconfig for clusters

**--altNames**="": altNames of the generated certificates for the kubeconfig

**--cn**="": Common name (CN) of the generated certificates for the kubeconfig (default: "system:admin")

**--config-name**="": the name of the generated kubeconfig file

**--expiration-days**="": Expiration date of the certificates used for the kubeconfig (default: 356)

**--kubeconfig**="": kubeconfig path (default: "/home/jpgouin/.kube/config")

**--kubeconfig-server**="": override the kubeconfig server host

**--name**="": cluster name

**--namespace**="": namespace to create the k3k cluster in

**--org**="": Organization name (ORG) of the generated certificates for the kubeconfig
40 changes: 40 additions & 0 deletions docs/cli/genclidoc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"
"os"

"github.com/rancher/k3k/cli/cmds"
"github.com/rancher/k3k/cli/cmds/cluster"
"github.com/rancher/k3k/cli/cmds/kubeconfig"
"github.com/rancher/k3k/pkg/buildinfo"
"github.com/urfave/cli/v2"
)

func main() {
// Instantiate the CLI application
app := cmds.NewApp()
app.Version = buildinfo.Version
cli.VersionPrinter = func(cCtx *cli.Context) {
fmt.Println("k3kcli Version: " + buildinfo.Version)
}

app.Commands = []*cli.Command{
cluster.NewCommand(),
kubeconfig.NewCommand(),
}

// Generate the Markdown documentation
md, err := app.ToMarkdown()
if err != nil {
fmt.Println("Error generating documentation:", err)
os.Exit(1)
}
err = os.WriteFile("./cli-docs.md", []byte(md), 0644)
if err != nil {
fmt.Println("Error generating documentation:", err)
os.Exit(1)
}

fmt.Println("Documentation generated at docs/cli/cli-docs.md")
}

0 comments on commit 12720a7

Please sign in to comment.