> For the complete documentation index, see [llms.txt](https://bohans.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bohans.gitbook.io/devops/kubernetes/ji-chu-zhi-shi/an-zhuang/ji-qun/cong-kong-zhi-ping-mian-jie-dian-yi-wai-de-ji-suan-ji-kong-zhi-ji-qun.md).

# 从控制平面节点以外的计算机控制集群

### 从控制平面节点以外的计算机控制集群[ ](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#optional-controlling-your-cluster-from-machines-other-than-the-control-plane-node) <a href="#optional-controlling-your-cluster-from-machines-other-than-the-control-plane-node" id="optional-controlling-your-cluster-from-machines-other-than-the-control-plane-node"></a>

为了使 kubectl 在其他计算机（例如笔记本电脑）上与你的集群通信， 你需要将管理员 kubeconfig 文件 **/etc/kubernetes/admin.conf** 从控制平面节点复制到工作站，如下所示：

```bash
scp root@<control-plane-host>:/etc/kubernetes/admin.conf .
kubectl --kubeconfig ./admin.conf get nodes
```

### 将 API 服务器代理到本地主机[ ](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#optional-proxying-api-server-to-localhost) <a href="#optional-proxying-api-server-to-localhost" id="optional-proxying-api-server-to-localhost"></a>

如果要从集群外部连接到 API 服务器，则可以使用 kubectl proxy：

```bash
scp root@<control-plane-host>:/etc/kubernetes/admin.conf .
kubectl --kubeconfig ./admin.conf proxy
```

你现在可以在本地访问 API 服务器 <http://localhost:8001/api/v1>

### ~~生成凭据~~

{% hint style="info" %} <mark style="color:orange;">**admin.conf 文件为用户提供了对集群的超级用户特权， 该文件应谨慎使用。**</mark>

<mark style="color:orange;">**对于普通用户，建议生成一个你为其授予特权的唯一证书。**</mark>
{% endhint %}

生成配置文件：

```bash
kubeadm kubeconfig user --client-name node_admin > /root/node_admin.conf
```

授权：

{% code overflow="wrap" %}

```bash
kubectl create rolebinding admin --clusterrole=admin --user=node_admin 
```

{% endcode %}

你可以使用 `kubeadm kubeconfig user --client-name <CN>` 命令执行此操作。 该命令会将 KubeConfig 文件打印到 STDOUT，你应该将其保存到文件并分发给用户。 之后，使用 `kubectl create (cluster)rolebinding` 授予特权。
