本文档采用自动化机器翻译技术翻译。 尽管我们力求提供准确的译文,但不对翻译内容的完整性、准确性或可靠性作出任何保证。 若出现任何内容不一致情况,请以原始 英文 版本为准,且原始英文版本为权威文本。

安装和配置 kubectl

kubectl 是一个 CLI 工具,用于运行 Kubernetes 集群相关的命令。Rancher 2.x 中的许多维护和管理任务都需要它。

安装

请参阅 kubectl 安装将 kubectl 安装到你的操作系统上。

配置

When you create a Kubernetes cluster with RKE2/K3s, the Kubeconfig file is stored at /etc/rancher/rke2/rke2.yaml or /etc/rancher/k3s/k3s.yaml depending on your chosen distribution. These files are used to configure access to the Kubernetes cluster.

使用 kubectl 测试你的连接性,并查看你是否可以获取节点列表:

kubectl get nodes
 NAME                          STATUS    ROLES                      AGE       VERSION
165.227.114.63                Ready     controlplane,etcd,worker   11m       v1.10.1
165.227.116.167               Ready     controlplane,etcd,worker   11m       v1.10.1
165.227.127.226               Ready     controlplane,etcd,worker   11m       v1.10.1