Files
tldr/pages.zh/common/kubectl-config.md

30 lines
1.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# kubectl 配置
> 管理 Kubernetes 配置kubeconfig文件以通过 `kubectl` 或 Kubernetes API 访问集群。
> 默认情况下Kubernetes 将从 `${HOME}/.kube/config` 获取其配置。
> 另请参阅: `kubectx`, `kubens`。
> 更多信息: <https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#config>。
- 获取默认 kubeconfig 文件中的所有上下文:
`kubectl config get-contexts`
- 在自定义 kubeconfig 文件中获取所有集群/上下文/用户:
`kubectl config {{get-clusters|get-contexts|get-users}} --kubeconfig {{path/to/kubeconfig.yaml}}`
- 获取当前上下文:
`kubectl config current-context`
- 切换到另一个上下文:
`kubectl config {{use|use-context}} {{context_name}}`
- 删除集群/上下文/用户:
`kubectl config {{delete-cluster|delete-context|delete-user}} {{cluster|context|user}}`
- 永久添加自定义 kubeconfig 文件:
`export KUBECONFIG="{{$HOME.kube/config:path/to/custom/kubeconfig.yaml}}" kubectl config get-contexts`