大网数据广告活动
服务器运维问答

Create Rancher API Key with kubectl

· 52CE 我爱测

Given access to the kubernetes cluster, but no API key, how can I programatically create a API key for rancher server? The method described in documentation here requires a password login an a web browser. I would like to get the…

问题原文

原帖链接 · d_inevitable · CC BY-SA 4.0

Given access to the kubernetes cluster, but no API key, how can I programatically create a API key for rancher server?

The method described in documentation here requires a password login an a web browser. I would like to get the same outcome programatically. Given that all the state should be on etcd, it should, in theory, be possible through kubectl.

已采纳解答

原帖链接 · d_inevitable · CC BY-SA 4.0

I found a way to make this work:

Create a JSON file to define the token (i.e token.json):

{
  "apiVersion": "management.cattle.io/v3",
  "authProvider": "local",
  "current": false,
  "description": <enter description>,
  "expired": false,
  "expiresAt": "",
  "isDerived": true,
  "kind": "Token",
  "metadata": {
    "labels": {
      "authn.management.cattle.io/token-userId": <enter user id>,
      "cattle.io/creator": "kubectl"
    },
    "name": <enter a token id>,
  },
  "token": <enter token>,
  "ttl": 0,
  "userId": <enter user id>,
}

The token ID can be any unique string to give a name of the token. For the user-id, choose a user to which this token should be long to. (see user list with kubectl get users -n cattle-system).

kubectl apply -f token.json

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-07-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。