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

pull/322/head
iwilltry42 4 years ago
parent 960723fca4
commit 1422a87945
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 4
      cmd/cluster/clusterCreate.go
  2. 7
      cmd/kubeconfig/kubeconfigGet.go
  3. 4
      cmd/kubeconfig/kubeconfigMerge.go
  4. 4
      docs/usage/commands.md
  5. 2
      docs/usage/guides/exposing_services.md
  6. 5
      docs/usage/kubeconfig.md

@ -99,9 +99,9 @@ func NewCmdClusterCreate() *cobra.Command {
fmt.Printf("kubectl config use-context %s\n", fmt.Sprintf("%s-%s", k3d.DefaultObjectNamePrefix, cluster.Name))
} else if !updateCurrentContext {
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 {
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")

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

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

@ -51,9 +51,9 @@ k3d
list NODENAME
--no-headers # do not print headers
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
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
--output # specify the output file where the kubeconfig should be written to
--overwrite # [Careful!] forcefully overwrite the output file, ignoring existing contents

@ -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
`#!bash export KUBECONFIG="$(k3d kubeconfig get k3s-default)"`
`#!bash export KUBECONFIG="$(k3d kubeconfig write k3s-default)"`
3. Create a nginx deployment

@ -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
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`
- *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
- `#!bash k3d cluster create mycluster --update-kubeconfig`
- *Note:* this won't switch the current-context (append `--switch-context` to do so)

Loading…
Cancel
Save