Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KUBECONFIG management migration for kind v0.6.0+ #1060

Closed
BenTheElder opened this issue Nov 6, 2019 · 2 comments
Closed

KUBECONFIG management migration for kind v0.6.0+ #1060

BenTheElder opened this issue Nov 6, 2019 · 2 comments
Assignees
Labels
kind/documentation Categorizes issue or PR as related to documentation.
Milestone

Comments

@BenTheElder
Copy link
Member

KUBECONFIG management for kind v0.6.0+ versus previous releases:

If you just want to use kind for local development, you can skip the export KUBECONFIG="$(kind get kubeconfig-path --name=kind)" step.

KIND now exports / merges kubeconfigs in the same way that kops, minikube, and other tools do. This means that when switching terminals kind will "just work" without remembering to export the KUBECONFIG environment variable in each terminal.

The file selection logic follows kubectl and client-go, which is roughly:

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 as a list of paths (normal path delimiting rules for your system). These paths are merged. 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.

source: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#config

The Kubernetes client credentials will be written by kind create cluster to the path determined by these rules, with a context name like kind-foo where foo is the --name of the cluster.

Like other tools, when exporting the credentials kind will set the current context to the new cluster. If you switch the current context again you can specifically reference the kind cluster by using kubectl with --context=kind-foo.

The instructions output by kind create cluster have been updated to reflect this.

Emulating The Old Behavior

You can emulate the previous behavior by switching from:

kind create cluster --name=foo
export KUBECONFIG="$(kind get kubeconfig-path --name=foo)"

to:

export KUBECONFIG="${HOME}/.kube/kind-config-foo"
kind create cluster --name=foo

This may be useful for some test scripts.

Additional Notes

  • Going forward kind clusters will be identified in kubeconfigs by the kind- prefix on entries
  • Note that your current context will be set when creating a cluster. If you wish to keep kind seperate from your other clusters, please specify --kubeconfig or KUBECONFIG to point to another file when calling kind create cluster
  • kind delete cluster will inspect either --kubeconfig if set or the files in KUBECONFIG and ${HOME}/.kube/config (the kubectl default) to find and remove the matching cluster by KIND --name in each file.
@BenTheElder BenTheElder added the kind/documentation Categorizes issue or PR as related to documentation. label Nov 6, 2019
@BenTheElder BenTheElder added this to the v0.6.0 milestone Nov 6, 2019
@BenTheElder BenTheElder self-assigned this Nov 6, 2019
@BenTheElder
Copy link
Member Author

see: #850 for background.

@BenTheElder
Copy link
Member Author

If you need help with this, please use: https://github.com/kubernetes-sigs/kind/issues/new?labels=triage%2Fsupport&template=question.md to file a new support issue, or reach out in #kind in the Kubernetes slack instance, thanks!

@kubernetes-sigs kubernetes-sigs locked as resolved and limited conversation to collaborators Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/documentation Categorizes issue or PR as related to documentation.
Projects
None yet
Development

No branches or pull requests

1 participant