You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用单行kubectl命令创建带指定元数据的ServiceAccount

单行kubectl命令创建带元数据的ServiceAccount

要创建指定命名空间、包含注解的test-role ServiceAccount,可直接使用kubectl create serviceaccount命令,通过参数传入元数据,对应的单行命令如下:

kubectl create serviceaccount test-role -n utility --annotation eks.amazonaws.com/role-arn=arn:aws:iam::xxx:role/rolename

参数说明

  • -n utility:指定ServiceAccount所属的命名空间为utility
  • --annotation key=value:添加自定义注解,此处用于绑定EKS对应的IAM角色ARN

对应YAML配置示例

apiVersion: v1
kind: ServiceAccount
metadata:
  name: test-role
  namespace: utility
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::xxx:role/rolename

验证创建结果

执行以下命令查看创建后的ServiceAccount配置,确认元数据是否正确:

kubectl get serviceaccount test-role -n utility -o yaml

附kubectl版本信息

kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.5", GitCommit:"c285e781331a3785a7f436042c65c5641ce8a9e9", GitTreeState:"archive", BuildDate:"1980-01-01T00:00:00Z", GoVersion:"go1.17.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"23+", GitVersion:"v1.23.14-eks-ffeb93d", GitCommit:"96e7d52c98a32f2b296ca7f19dc9346cf79915ba", GitTreeState:"clean", BuildDate:"2022-11-29T18:43:31Z", GoVersion:"go1.17.13", Compiler:"gc", Platform:"linux/amd64"}

内容的提问来源于stack exchange,提问作者user6826691

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 19:45:43