kubectl config set-credentials

概要

在 kubeconfig 中设置用户条目。

指定已有的名称将会在现有值的基础上合并新字段。

    Client-certificate flags:
    --client-certificate=certfile --client-key=keyfile
    
    Bearer token flags:
    --token=bearer_token
    
    Basic auth flags:
    --username=basic_user --password=basic_password

Bearer token 和 basic auth 是互斥的。

kubectl config set-credentials NAME [--client-certificate=path/to/certfile] [--client-key=path/to/keyfile] [--token=bearer_token] [--username=basic_user] [--password=basic_password] [--auth-provider=provider_name] [--auth-provider-arg=key=value] [--exec-command=exec_command] [--exec-api-version=exec_api_version] [--exec-arg=arg] [--exec-env=key=value]

示例

  # Set only the "client-key" field on the "cluster-admin"
  # entry, without touching other values
  kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key
  
  # Set basic auth for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
  
  # Embed client certificate data in the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
  
  # Enable the Google Compute Platform auth provider for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --auth-provider=gcp
  
  # Enable the OpenID Connect auth provider for the "cluster-admin" entry with additional arguments
  kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar
  
  # Remove the "client-secret" config value for the OpenID Connect auth provider for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-secret-
  
  # Enable new exec auth plugin for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1
  
  # Enable new exec auth plugin for the "cluster-admin" entry with interactive mode
  kubectl config set-credentials cluster-admin --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 --exec-interactive-mode=Never
  
  # Define new exec auth plugin arguments for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-arg=arg1 --exec-arg=arg2
  
  # Create or update exec auth plugin environment variables for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-env=key1=val1 --exec-env=key2=val2
  
  # Remove exec auth plugin environment variables for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-env=var-to-remove-

选项

--auth-provider string

kubeconfig 中用户条目的认证提供者

--auth-provider-arg strings

认证提供者的 'key=value' 参数

--client-certificate string

kubeconfig 中用户条目的客户端证书文件路径

--client-key string

kubeconfig 中用户条目的客户端密钥文件路径

--embed-certs tristate[=true]

在 kubeconfig 中嵌入用户条目的客户端证书/密钥

--exec-api-version string

kubeconfig 中用户条目的 exec 凭证插件的 API 版本

--exec-arg strings

kubeconfig 中用户条目的 exec 凭证插件命令的新参数

--exec-command string

kubeconfig 中用户条目的 exec 凭证插件的命令

--exec-env strings

exec 凭证插件的 'key=value' 环境变量

--exec-interactive-mode string

kubeconfig 中用户条目的 exec 凭证插件的 InteractiveMode

--exec-provide-cluster-info tristate[=true]

kubeconfig 中用户条目的 exec 凭证插件的 ProvideClusterInfo

-h, --help

set-credentials 的帮助信息

--password string

kubeconfig 中用户条目的密码

--token string

kubeconfig 中用户条目的 token

--username string

kubeconfig 中用户条目的用户名

继承自父命令的选项

--as string

操作时要模拟的用户名。用户可以是普通用户或命名空间中的 ServiceAccount。

--as-group strings

操作时要模拟的组,此标志可以重复以指定多个组。

--as-uid string

操作时要模拟的 UID。

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

默认缓存目录

--certificate-authority string

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

--cluster string

要使用的 kubeconfig 集群的名称

--context string

要使用的 kubeconfig 上下文的名称

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

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

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

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

--disable-compression

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

--insecure-skip-tls-verify

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

--kubeconfig string

使用特定的 kubeconfig 文件

--match-server-version

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

-n, --namespace string

如果存在,则为该 CLI 请求的命名空间范围

--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"

数据库主机:端口

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

数据库密码

--storage-driver-secure

使用安全连接到数据库

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

表名称

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

数据库用户名

--tls-server-name string

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

--user string

要使用的 kubeconfig 用户名

--version version[=true]

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

--warnings-as-errors

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

参阅

此页面是自动生成的。

如果您计划报告此页面存在问题,请在您的问题描述中提及该页面是自动生成的。修复可能需要在 Kubernetes 项目的其他地方进行。

最后修改于 2024 年 8 月 19 日下午 5:14 PST:更新 v1.31 的 kubectl 参考 (59df28c340)