kubeconfig: improved flag names and bug fixes

pull/288/head
iwilltry42 4 years ago
parent c00f8952ba
commit 846aefeb40
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 4
      cmd/create/createCluster.go
  2. 8
      cmd/get/getKubeconfig.go
  3. 2
      docs/internals/defaults.md
  4. 6
      docs/usage/commands.md
  5. 14
      docs/usage/kubeconfig.md

@ -88,7 +88,7 @@ func NewCmdCreateCluster() *cobra.Command {
if updateDefaultKubeconfig || updateCurrentContext {
log.Debugf("Updating default kubeconfig with a new context for cluster %s", cluster.Name)
if _, err := k3dCluster.GetAndWriteKubeConfig(cmd.Context(), runtimes.SelectedRuntime, cluster, "", &k3dCluster.WriteKubeConfigOptions{UpdateExisting: true, OverwriteExisting: false, UpdateCurrentContext: updateCurrentContext}); err != nil {
log.Fatalln(err)
log.Warningln(err)
}
}
@ -121,7 +121,7 @@ func NewCmdCreateCluster() *cobra.Command {
cmd.Flags().BoolVar(&createClusterOpts.WaitForMaster, "wait", true, "Wait for the master(s) to be ready before returning. Use '--timeout DURATION' to not wait forever.")
cmd.Flags().DurationVar(&createClusterOpts.Timeout, "timeout", 0*time.Second, "Rollback changes if cluster couldn't be created in specified duration.")
cmd.Flags().BoolVar(&updateDefaultKubeconfig, "update-default-kubeconfig", false, "Directly update the default kubeconfig with the new cluster's context")
cmd.Flags().BoolVar(&updateCurrentContext, "switch", false, "Directly switch the default kubeconfig's current-context to the new cluster's context (implies --update-default-kubeconfig)")
cmd.Flags().BoolVar(&updateCurrentContext, "switch-context", false, "Directly switch the default kubeconfig's current-context to the new cluster's context (implies --update-default-kubeconfig)")
cmd.Flags().BoolVar(&createClusterOpts.DisableLoadBalancer, "no-lb", false, "Disable the creation of a LoadBalancer in front of the master nodes")
/* Image Importing */

@ -68,7 +68,7 @@ func NewCmdGetKubeconfig() *cobra.Command {
var err error
if getKubeconfigFlags.targetDefault && getKubeconfigFlags.output != "" {
log.Fatalln("Cannot use both '--output' and '--default' at the same time")
log.Fatalln("Cannot use both '--output' and '--merge-default-kubeconfig' at the same time")
}
// generate list of clusters
@ -127,9 +127,9 @@ func NewCmdGetKubeconfig() *cobra.Command {
if err := cmd.MarkFlagFilename("output"); err != nil {
log.Fatalln("Failed to mark flag --output as filename")
}
cmd.Flags().BoolVarP(&getKubeconfigFlags.targetDefault, "default-kubeconfig", "d", false, fmt.Sprintf("Update the default kubeconfig ($KUBECONFIG or %s)", clientcmd.RecommendedHomeFile))
cmd.Flags().BoolVarP(&writeKubeConfigOptions.UpdateExisting, "update", "u", true, "Update conflicting fields in existing KubeConfig")
cmd.Flags().BoolVarP(&writeKubeConfigOptions.UpdateCurrentContext, "switch", "s", true, "Switch to new context")
cmd.Flags().BoolVarP(&getKubeconfigFlags.targetDefault, "merge-default-kubeconfig", "d", false, fmt.Sprintf("Merge into the default kubeconfig ($KUBECONFIG or %s)", clientcmd.RecommendedHomeFile))
cmd.Flags().BoolVarP(&writeKubeConfigOptions.UpdateExisting, "update", "u", true, "Update conflicting fields in existing kubeconfig")
cmd.Flags().BoolVarP(&writeKubeConfigOptions.UpdateCurrentContext, "switch-context", "s", true, "Switch to new context")
cmd.Flags().BoolVar(&writeKubeConfigOptions.OverwriteExisting, "overwrite", false, "[Careful!] Overwrite existing file, ignoring its contents")
cmd.Flags().BoolVarP(&getKubeconfigFlags.all, "all", "a", false, "Get kubeconfigs from all existing clusters")

@ -7,6 +7,6 @@
- API-Ports
- by default, we don't expose any API-Port (no host port mapping)
- kubeconfig
- if `--default` is set, we use the default loading rules to get the default kubeconfig:
- if `--[update|merge]-default-kubeconfig` is set, we use the default loading rules to get the default kubeconfig:
- First: kubeconfig specified via the KUBECONFIG environment variable (error out if multiple are specified)
- Second: default kubeconfig in home directory (e.g. `$HOME/.kube/config`)

@ -17,7 +17,7 @@ k3d
--token # specify a cluster token (default: auto-generated)
--timeout # specify a timeout, after which the cluster creation will be interrupted and changes rolled back
--update-default-kubeconfig # enable the automated update of the default kubeconfig with the details of the newly created cluster (also sets '--wait=true')
--switch # (implies --update-default-kubeconfig) automatically sets the current-context of your default kubeconfig to the new cluster's context
--switch-context # (implies --update-default-kubeconfig) automatically sets the current-context of your default kubeconfig to the new cluster's context
-v, --volume # specify additional bind-mounts
--wait # enable waiting for all master nodes to be ready before returning
-w, --workers # specify how many worker nodes you want to create
@ -53,9 +53,9 @@ k3d
-a, --all # get kubeconfigs from all clusters
--output # specify the output file where the kubeconfig should be written to
--overwrite # [Careful!] forcefully overwrite the output file, ignoring existing contents
-s, --switch # switch current-context in kubeconfig to the new context
-s, --switch-context # switch current-context in kubeconfig to the new context
-u, --update # update conflicting fields in existing kubeconfig (default: true)
-d, --default # update the default kubeconfig (usually $KUBECONFIG or $HOME/.kube/config)
-d, --merge-default-kubeconfig # update the default kubeconfig (usually $KUBECONFIG or $HOME/.kube/config)
load
image [IMAGE | ARCHIVE [IMAGE | ARCHIVE ...]] # Load one or more images from the local runtime environment or tar-archives into k3d clusters
-c, --cluster # clusters to load the image into

@ -14,13 +14,13 @@ To get a kubeconfig set up for you to connect to a k3d cluster, you can go diffe
1. Create a new kubeconfig file **after** cluster creation
- `#!bash k3d get kubeconfig mycluster`
- *Note:* this will create (or update) the file `$HOME/.k3d/kubeconfig-mycluster.yaml`
- *Tip:* pipe this: `export KUBECONFIG?$(k3d get kubeconfig mycluster)`
- *Tip:* Use it: `#!bash export KUBECONFIG=$(k3d get kubeconfig mycluster)`
2. Update your default kubeconfig **upon** cluster creation
- `#!bash k3d create cluster mycluster --update-kubeconfig`
- *Note:* this won't switch the current-context (append `--switch` to do so)
- *Note:* this won't switch the current-context (append `--switch-context` to do so)
3. Update your default kubeconfig **after** cluster creation
- `#!bash k3d get kubeconfig mycluster --default`
- *Note:* this won't switch the current-context (append `--switch` to do so)
- `#!bash k3d get kubeconfig mycluster --merge-default-kubeconfig`
- *Note:* this won't switch the current-context (append `--switch-context` to do so)
4. Update a different kubeconfig **after** cluster creation
- `#!bash k3d get kubeconfig mycluster --output some/other/file.yaml`
- *Note:* this won't switch the current-context
@ -29,7 +29,7 @@ To get a kubeconfig set up for you to connect to a k3d cluster, you can go diffe
!!! info "Switching the current context"
None of the above options switch the current-context by default.
This is intended to be least intrusive, since the current-context has a global effect.
You can switch the current-context directly with the `get kubeconfig` command by adding the `--switch` flag.
You can switch the current-context directly with the `get kubeconfig` command by adding the `--switch-context` flag.
## Removing cluster details from the kubeconfig
@ -39,6 +39,6 @@ It will also delete the respective kubeconfig file in `$HOME/.k3d/` if it exists
## Handling multiple clusters
`k3d get kubeconfig` let's you specify one or more clusters via arguments _or_ all via `--all`.
All kubeconfigs will then be merged into a single file if `--default` or `--output` is specified.
All kubeconfigs will then be merged into a single file if `--merge-default-kubeconfig` or `--output` is specified.
If none of those two flags was specified, a new file will be created per cluster and the merged path (e.g. `$HOME/.k3d/kubeconfig-cluster1.yaml:$HOME/.k3d/cluster2.yaml`) will be returned.
Note, that with multiple cluster specified, the `--switch` flag will change the current context to the cluster which was last in the list.
Note, that with multiple cluster specified, the `--switch-context` flag will change the current context to the cluster which was last in the list.

Loading…
Cancel
Save