@@ -84,15 +84,20 @@ If the contents of the kubernetes_auth file conflict with entries in .kubeconfig
## Loading and merging rules
The rules for loading and merging the .kubeconfig files are straightforward, but there are a lot of them. The final config is built in this order:
1. Merge together the kubeconfig itself. This is done with the following hierarchy and merge rules:
1. Get the kubeconfig from disk. This is done with the following hierarchy and merge rules:
If the CommandLineLocation (the value of the `kubeconfig` command line option) is set, use this file only. No merging. Only one instance of this flag is allowed.
Else, if EnvVarLocation (the value of $KUBECONFIG) is available, use it as a list of files that should be merged.
Merge files together based on the following rules.
Empty filenames are ignored. Files with non-deserializable content produced errors.
The first file to set a particular value or map key wins and the value or map key is never changed.
This means that the first file to set CurrentContext will have its context preserved. It also means that if two files specify a "red-user", only values from the first file's red-user are used. Even non-conflicting entries from the second file's "red-user" are discarded.
1. CommandLineLocation - the value of the `kubeconfig` command line option
1. EnvVarLocation - the value of $KUBECONFIG
1. CurrentDirectoryLocation - ``pwd``/.kubeconfig
1. HomeDirectoryLocation = ~/.kube/.kubeconfig
Otherwise, use HomeDirectoryLocation (~/.kube/config) with no merging.
1. Determine the context to use based on the first hit in this chain
1. command line argument - the value of the `context` command line option
1. current-context from the merged kubeconfig file
config modifies kubeconfig files using subcommands like "kubectl config set current-context my-context"
The loading order follows these rules:
1. If the --kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place.
2. If $KUBECONFIG environment variable is set, then it is used a list of paths (normal path delimitting rules for your system). These paths are merged together. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list.
3. Otherwise, ${HOME}/.kube/config is used and no merging takes place.
```
kubectl config SUBCOMMAND
```
...
...
@@ -14,11 +20,8 @@ kubectl config SUBCOMMAND
### Options
```
--envvar=false: use the kubeconfig from $KUBECONFIG
--global=false: use the kubeconfig from /home/username/.kube/.kubeconfig
-h, --help=false: help for config
--kubeconfig="": use a particular kubeconfig file
--local=false: use the kubeconfig in the current directory
```
### Options inherrited from parent commands
...
...
@@ -60,4 +63,4 @@ kubectl config SUBCOMMAND
*[kubectl config use-context](kubectl_config_use-context.md) - Sets the current-context in a kubeconfig file
*[kubectl config view](kubectl_config_view.md) - displays Merged kubeconfig settings or a specified kubeconfig file.
###### Auto generated by spf13/cobra at 2015-04-14 19:53:16.640323684 +0000 UTC
###### Auto generated by spf13/cobra at 2015-04-16 17:04:37.392043616 +0000 UTC
config modifies kubeconfig files using subcommands like "kubectl config set current\-context my\-context"
.SH OPTIONS
.PP
\fB\-\-envvar\fP=false
use the kubeconfig from $KUBECONFIG
The loading order follows these rules:
1. If the \-\-kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place.
2. If $KUBECONFIG environment variable is set, then it is used a list of paths (normal path delimitting rules for your system). These paths are merged together. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list.
3. Otherwise, $\{HOME\}/.kube/config is used and no merging takes place.
.PP
\fB\-\-global\fP=false
use the kubeconfig from /home/username/.kube/.kubeconfig
.SH OPTIONS
.PP
\fB\-h\fP, \fB\-\-help\fP=false
help for config
...
...
@@ -33,10 +31,6 @@ config modifies kubeconfig files using subcommands like "kubectl config set curr
Use:fmt.Sprintf("set-context NAME [--%v=cluster_nickname] [--%v=user_nickname] [--%v=namespace]",clientcmd.FlagClusterName,clientcmd.FlagAuthInfoName,clientcmd.FlagNamespace),
...
...
@@ -76,7 +76,7 @@ func (o createContextOptions) run() error {
returnerr
}
config,err:=o.pathOptions.getStartingConfig()
config,err:=o.configAccess.GetStartingConfig()
iferr!=nil{
returnerr
}
...
...
@@ -84,7 +84,7 @@ func (o createContextOptions) run() error {
returnerrors.New("if merge==false a precise file must to specified")
}
returnnil
}
// getStartingConfig returns the Config object built from the sources specified by the options, the filename read (only if it was a single file), and an error if something goes wrong