diff --git a/internal/cli/cmd/infrastructure/create.go b/internal/cli/cmd/infrastructure/create.go index 582c13d2e35..2d432a9148f 100644 --- a/internal/cli/cmd/infrastructure/create.go +++ b/internal/cli/cmd/infrastructure/create.go @@ -28,6 +28,7 @@ import ( "github.com/spf13/cobra" versionutil "k8s.io/apimachinery/pkg/util/version" "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubeblocks/internal/cli/cmd/infrastructure/constant" "github.com/apecloud/kubeblocks/internal/cli/cmd/infrastructure/tasks" @@ -49,8 +50,69 @@ type createOptions struct { outputKubeconfig string } -var createExamples = ` -` +var createExamples = templates.Examples(` + # Create kubernetes cluster with specified config yaml + kbcli infra create -c cluster.yaml + + # example cluster.yaml + cat cluster.yaml +metadata: + name: kb-k8s-test-cluster +user: + name: user1 + privateKeyPath: ~/.ssh/test.pem +nodes: + - name: kb-infra-node-0 + address: 1.1.1.1 + internalAddress: 10.128.0.19 + - name: kb-infra-node-1 + address: 1.1.1.2 + internalAddress: 10.128.0.20 + - name: kb-infra-node-2 + address: 1.1.1.3 + internalAddress: 10.128.0.21 + options: + hugePageFeature: + hugePageSize: 10GB +roleGroup: + etcd: + - kb-infra-node-0 + - kb-infra-node-1 + - kb-infra-node-2 + master: + - kb-infra-node-0 + worker: + - kb-infra-node-1 + - kb-infra-node-2 + +kubernetes: + containerManager: containerd + # apis/kubeadm/types.Networking + networking: + plugin: cilium + dnsDomain: cluster.local + podSubnet: 10.233.64.0/18 + serviceSubnet: 10.233.0.0/18 + controlPlaneEndpoint: + domain: lb.kubeblocks.local + port: 6443 + cri: + containerRuntimeType: "containerd" + containerRuntimeEndpoint: "unix:///run/containerd/containerd.sock" + sandBoxImage: "k8s.gcr.io/pause:3.8" +addons: + - name: openebs + namespace: kube-blocks + sources: + chart: + name: openebs + version: 3.7.0 + repo: https://openebs.github.io/charts + options: + values: + - "localprovisioner.basePath=/mnt/disks" + - "localprovisioner.hostpathClass.isDefaultClass=true" +`) func (o *createOptions) Run() error { const minKubernetesVersion = "v1.24.0" diff --git a/internal/cli/cmd/infrastructure/delete.go b/internal/cli/cmd/infrastructure/delete.go index 02da66b6911..2c0f27c6cd0 100644 --- a/internal/cli/cmd/infrastructure/delete.go +++ b/internal/cli/cmd/infrastructure/delete.go @@ -28,6 +28,7 @@ import ( "github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/pipeline" "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/kubectl/pkg/util/templates" "github.com/apecloud/kubeblocks/internal/cli/util" ) @@ -39,6 +40,11 @@ type deleteOptions struct { debug bool } +var deleteExamples = templates.Examples(` + # delete kubernetes cluster with specified config yaml + kbcli infra delete -c cluster.yaml +`) + func (o *deleteOptions) Run() error { o.Cluster.Kubernetes.AutoDefaultFill() cluster, err := createClusterWithOptions(&gotemplate.TplValues{ @@ -99,7 +105,7 @@ func NewDeleteKubernetesCmd(streams genericclioptions.IOStreams) *cobra.Command cmd := &cobra.Command{ Use: "delete", Short: "delete kubernetes cluster.", - Example: createExamples, + Example: deleteExamples, Run: func(cmd *cobra.Command, args []string) { util.CheckErr(o.Complete()) util.CheckErr(o.Validate())