kubectl create token

概要

请求一个 ServiceAccount 令牌。

kubectl create token SERVICE_ACCOUNT_NAME

示例

  # Request a token to authenticate to the kube-apiserver as the service account "myapp" in the current namespace
  kubectl create token myapp
  
  # Request a token for a service account in a custom namespace
  kubectl create token myapp --namespace myns
  
  # Request a token with a custom expiration
  kubectl create token myapp --duration 10m
  
  # Request a token with a custom audience
  kubectl create token myapp --audience https://example.com
  
  # Request a token bound to an instance of a Secret object
  kubectl create token myapp --bound-object-kind Secret --bound-object-name mysecret
  
  # Request a token bound to an instance of a Secret object with a specific UID
  kubectl create token myapp --bound-object-kind Secret --bound-object-name mysecret --bound-object-uid 0d4691ed-659b-4935-a832-355f77ee47cc

选项

--allow-missing-template-keys     默认值: true

如果为 true,则当模板中缺少字段或 map 键时,忽略模板中的任何错误。仅适用于 golang 和 jsonpath 输出格式。

--audience strings (受众字符串)

所请求令牌的受众。如果未设置,默认为请求一个用于 Kubernetes API 服务器的令牌。可以重复设置以请求对多个受众有效的令牌。

--bound-object-kind string (绑定的对象类型字符串)

将令牌绑定到的对象的类型。支持的类型有 Node、Pod、Secret。如果设置,必须提供 --bound-object-name。

--bound-object-name string (绑定的对象名称字符串)

将令牌绑定到的对象的名称。当该对象被删除时,令牌将过期。需要 --bound-object-kind。

--bound-object-uid string (绑定的对象 UID 字符串)

将令牌绑定到的对象的 UID。需要 --bound-object-kind 和 --bound-object-name。如果未设置,则使用现有对象的 UID。

--duration duration (持续时间)

请求发放令牌的生命周期。如果未设置或设置为 0,生命周期将由服务器自动决定。服务器可能返回具有更长或更短生命周期的令牌。

-h, --help (帮助)

token 命令的帮助信息

-o, --output string (输出格式字符串)

输出格式。可选值包括:(json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file)。

--show-managed-fields (显示管理字段)

如果为 true,则在以 JSON 或 YAML 格式打印对象时保留 managedFields(管理字段)。

--template string (模板字符串)

当设置 -o=go-template 或 -o=go-template-file 时使用的模板字符串或模板文件路径。模板格式为 golang 模板 [https://golang.ac.cn/pkg/text/template/#pkg-overview]。

继承的父选项

--as string (伪装身份字符串)

用于伪装操作身份的用户名。用户可以是普通用户或命名空间中的 ServiceAccount。

--as-group strings (伪装身份组字符串列表)

用于伪装操作身份的组,可以重复此标志以指定多个组。

--as-uid string (伪装身份 UID 字符串)

用于伪装操作身份的 UID。

--cache-dir string     默认值: "$HOME/.kube/cache"

默认缓存目录

--certificate-authority string (证书颁发机构字符串)

证书颁发机构的证书文件路径

--client-certificate string (客户端证书字符串)

TLS 的客户端证书文件路径

--client-key string (客户端私钥字符串)

TLS 的客户端私钥文件路径

--cluster string (集群名称字符串)

要使用的 kubeconfig 集群名称

--context string (上下文名称字符串)

要使用的 kubeconfig 上下文名称

--default-not-ready-toleration-seconds int     默认值: 300

指示默认添加到每个尚未拥有此类容忍度的 Pod 的,针对 notReady:NoExecute 的容忍度的 tolerationSeconds。

--default-unreachable-toleration-seconds int     默认值: 300

指示默认添加到每个尚未拥有此类容忍度的 Pod 的,针对 unreachable:NoExecute 的容忍度的 tolerationSeconds。

--disable-compression (禁用压缩)

如果为 true,则对发送到服务器的所有请求禁用响应压缩。

--insecure-skip-tls-verify (不安全地跳过 TLS 验证)

如果为 true,则不检查服务器证书的有效性。这会使你的 HTTPS 连接不安全。

--kubeconfig string (kubeconfig 文件路径字符串)

用于 CLI 请求的 kubeconfig 文件路径。

--match-server-version (匹配服务器版本)

要求服务器版本与客户端版本匹配

-n, --namespace string (命名空间字符串)

如果存在,则为此次 CLI 请求使用的命名空间范围

--password string (密码字符串)

用于对 API 服务器进行基本认证的密码

--profile string     默认值: "none"

要捕获的 profile 名称。可选值包括 (none|cpu|heap|goroutine|threadcreate|block|mutex)。

--profile-output string     默认值: "profile.pprof"

写入 profile 的文件名

--request-timeout string     默认值: "0"

在放弃单个服务器请求之前等待的时间长度。非零值应包含相应的时间单位(例如 1s、2m、3h)。值为零表示请求永不超时。

-s, --server string (服务器地址字符串)

Kubernetes API 服务器的地址和端口

--storage-driver-buffer-duration duration     默认值: 1m0s

存储驱动程序中的写入将在此持续时间内缓冲,然后作为单个事务提交到非内存后端。

--storage-driver-db string     默认值: "cadvisor"

数据库名称

--storage-driver-host string     默认值: "localhost:8086"

数据库 host:port

--storage-driver-password string     默认值: "root"

数据库密码

--storage-driver-secure (存储驱动程序安全连接)

使用安全连接连接数据库

--storage-driver-table string     默认值: "stats"

表名称

--storage-driver-user string     默认值: "root"

数据库用户名

--tls-server-name string (TLS 服务器名称字符串)

用于服务器证书验证的服务器名称。如果未提供,则使用用于连接服务器的主机名。

--token string (令牌字符串)

用于对 API 服务器进行认证的 Bearer token

--user string (用户名称字符串)

要使用的 kubeconfig 用户名称

--username string (用户名字符串)

用于对 API 服务器进行基本认证的用户名

--version version[=true] (版本)

--version 或 --version=raw 打印版本信息并退出;--version=vX.Y.Z... 设置报告的版本。

--warnings-as-errors (将警告视为错误)

将从服务器收到的警告视为错误并以非零退出码退出。

参见

本页面是自动生成的。

如果你打算报告本页面的问题,请在问题描述中提及本页面是自动生成的。修复可能需要在 Kubernetes 项目中的其他地方进行。

最后修改于 2024 年 8 月 19 日下午 5:14 (太平洋标准时间):为 v1.31 更新 kubectl 参考 (59df28c340)