kubeconfig/docs: clarify kubeconfig get/print/show and merge/write

This commit is contained in:
iwilltry42 2020-08-05 12:25:06 +02:00
parent 960723fca4
commit 1422a87945
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
6 changed files with 14 additions and 12 deletions

View File

@ -99,9 +99,9 @@ func NewCmdClusterCreate() *cobra.Command {
fmt.Printf("kubectl config use-context %s\n", fmt.Sprintf("%s-%s", k3d.DefaultObjectNamePrefix, cluster.Name)) fmt.Printf("kubectl config use-context %s\n", fmt.Sprintf("%s-%s", k3d.DefaultObjectNamePrefix, cluster.Name))
} else if !updateCurrentContext { } else if !updateCurrentContext {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
fmt.Printf("$env:KUBECONFIG=(%s kubeconfig get %s)\n", os.Args[0], cluster.Name) fmt.Printf("$env:KUBECONFIG=(%s kubeconfig write %s)\n", os.Args[0], cluster.Name)
} else { } else {
fmt.Printf("export KUBECONFIG=$(%s kubeconfig get %s)\n", os.Args[0], cluster.Name) fmt.Printf("export KUBECONFIG=$(%s kubeconfig write %s)\n", os.Args[0], cluster.Name)
} }
} }
fmt.Println("kubectl cluster-info") fmt.Println("kubectl cluster-info")

View File

@ -52,8 +52,9 @@ func NewCmdKubeconfigGet() *cobra.Command {
// create new command // create new command
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "get [CLUSTER [CLUSTER [...]] | --all]", Use: "get [CLUSTER [CLUSTER [...]] | --all]",
Short: "Get kubeconfig from cluster(s).", Short: "Print kubeconfig(s) from cluster(s).",
Long: `Get kubeconfig from cluster(s).`, Long: `Print kubeconfig(s) from cluster(s).`,
Aliases: []string{"print", "show"},
ValidArgsFunction: util.ValidArgsAvailableClusters, ValidArgsFunction: util.ValidArgsAvailableClusters,
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
if (len(args) < 1 && !getKubeconfigFlags.all) || (len(args) > 0 && getKubeconfigFlags.all) { if (len(args) < 1 && !getKubeconfigFlags.all) || (len(args) > 0 && getKubeconfigFlags.all) {
@ -100,7 +101,7 @@ func NewCmdKubeconfigGet() *cobra.Command {
} }
// add flags // add flags
cmd.Flags().BoolVarP(&getKubeconfigFlags.all, "all", "a", false, "Get kubeconfigs from all existing clusters") cmd.Flags().BoolVarP(&getKubeconfigFlags.all, "all", "a", false, "Output kubeconfigs from all existing clusters")
// done // done
return cmd return cmd

View File

@ -55,8 +55,8 @@ func NewCmdKubeconfigMerge() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "merge [CLUSTER [CLUSTER [...]] | --all]", Use: "merge [CLUSTER [CLUSTER [...]] | --all]",
Aliases: []string{"write"}, Aliases: []string{"write"},
Long: `Merge/Write kubeconfig(s) from cluster(s) into existing kubeconfig/file.`, Long: `Write/Merge kubeconfig(s) from cluster(s) into new or existing kubeconfig/file.`,
Short: "Merge/Write kubeconfig(s) from cluster(s) into existing kubeconfig/file.", Short: "Write/Merge kubeconfig(s) from cluster(s) into new or existing kubeconfig/file.",
ValidArgsFunction: util.ValidArgsAvailableClusters, ValidArgsFunction: util.ValidArgsAvailableClusters,
Args: cobra.MinimumNArgs(0), Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {

View File

@ -51,9 +51,9 @@ k3d
list NODENAME list NODENAME
--no-headers # do not print headers --no-headers # do not print headers
kubeconfig kubeconfig
get (CLUSTERNAME [CLUSTERNAME ...] | --all) # get kubeconfig from cluster(s) and save it into a file in $HOME/.k3d get (CLUSTERNAME [CLUSTERNAME ...] | --all) # get kubeconfig from cluster(s) and write it to stdout
-a, --all # get kubeconfigs from all clusters -a, --all # get kubeconfigs from all clusters
merge (CLUSTERNAME [CLUSTERNAME ...] | --all) # get kubeconfig from cluster(s) and merge it/them into an existing kubeconfig merge | write (CLUSTERNAME [CLUSTERNAME ...] | --all) # get kubeconfig from cluster(s) and merge it/them into into a file in $HOME/.k3d (or whatever you specify via the flags)
-a, --all # get kubeconfigs from all clusters -a, --all # get kubeconfigs from all clusters
--output # specify the output file where the kubeconfig should be written to --output # specify the output file where the kubeconfig should be written to
--overwrite # [Careful!] forcefully overwrite the output file, ignoring existing contents --overwrite # [Careful!] forcefully overwrite the output file, ignoring existing contents

View File

@ -18,7 +18,7 @@ Therefore, we have to create the cluster in a way, that the internal port 80 (wh
2. Get the kubeconfig file 2. Get the kubeconfig file
`#!bash export KUBECONFIG="$(k3d kubeconfig get k3s-default)"` `#!bash export KUBECONFIG="$(k3d kubeconfig write k3s-default)"`
3. Create a nginx deployment 3. Create a nginx deployment

View File

@ -12,9 +12,10 @@ To get a kubeconfig set up for you to connect to a k3d cluster, you can go diffe
## Getting the kubeconfig for a newly created cluster ## Getting the kubeconfig for a newly created cluster
1. Create a new kubeconfig file **after** cluster creation 1. Create a new kubeconfig file **after** cluster creation
- `#!bash k3d kubeconfig get mycluster` - `#!bash k3d kubeconfig write mycluster`
- *Note:* this will create (or update) the file `$HOME/.k3d/kubeconfig-mycluster.yaml` - *Note:* this will create (or update) the file `$HOME/.k3d/kubeconfig-mycluster.yaml`
- *Tip:* Use it: `#!bash export KUBECONFIG=$(k3d kubeconfig get mycluster)` - *Tip:* Use it: `#!bash export KUBECONFIG=$(k3d kubeconfig write mycluster)`
- *Note 2*: alternatively you can use `#!bash k3d kubeconfig get mycluster > some-file.yaml`
2. Update your default kubeconfig **upon** cluster creation 2. Update your default kubeconfig **upon** cluster creation
- `#!bash k3d cluster create mycluster --update-kubeconfig` - `#!bash k3d cluster create mycluster --update-kubeconfig`
- *Note:* this won't switch the current-context (append `--switch-context` to do so) - *Note:* this won't switch the current-context (append `--switch-context` to do so)