阿里云k8s如何创建可用的api token

阿里云的 Kubernetes 配置文件(如您所提供的 YAML 格式文件)通常不会直接包含用于连接 Kubernetes 集群的令牌。而是包含了客户端证书和私钥数据,这些是用于通过证书验证而不是令牌验证的方式来与 Kubernetes API 服务器进行安全交互的。

1.创建一个 ServiceAccount:

kubectl create serviceaccount [service-account-name]

2.通过 YAML 文件创建 ClusterRoleBinding

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: example-clusterrolebinding
subjects:
- kind: ServiceAccount
  name: example-serviceaccount
  namespace: example-namespace
roleRef:
  kind: ClusterRole
  name: example-clusterrole
  apiGroup: rbac.authorization.k8s.io

3.手动创建服务账号令牌

apiVersion: v1
kind: Secret
metadata:
  name: [secret-name]
  namespace: [your-namespace]
  annotations:
    kubernetes.io/service-account.name: [service-account-name]
type: kubernetes.io/service-account-token

4.定义pod-exec-role

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: your-namespace
  name: pod-exec-role
rules:
- apiGroups: [""]
  resources: ["pods/exec", "pods/log"]
  verbs: ["create", "get", "list"]

5.创建ClusterRoleBinding

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: pod-exec-binding
  namespace: your-namespace
subjects:
- kind: User
  name: "your-username"
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-exec-role
  apiGroup: rbac.authorization.k8s.io

6.创建view的roleBinding

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cao-crb
subjects:
- kind: User
  name: "your-username"  # 替换为实际的用户名
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: view  # 确保这是正确的 ClusterRole 名称
  apiGroup: rbac.authorization.k8s.io
相关推荐
Marcel1116 小时前
WSL2使用Kind创建K8S集群时出现IPV6网络创建失败
云原生·kubernetes·kind
悟空码字8 小时前
阿里云上线 DeepSeek,AI 领域再掀波澜
阿里云·deepseek
柳鲲鹏8 小时前
docker push镜像到阿里云
阿里云·docker·容器
G皮T9 小时前
【弹性计算】IaaS 和 PaaS 类计算产品
阿里云·云计算·paas·iaas·云服务器·弹性服务器·弹性计算
alden_ygq11 小时前
在阿里云Linux主机上运行大模型deepseek r1
linux·阿里云·云计算
格桑阿sir13 小时前
Kubernetes控制平面组件:etcd(二)
kubernetes·etcd·raft·mvcc·boltdb·watch机制·treeindex
喝醉酒的小白14 小时前
K8s:kubernetes.io~csi 目录介绍
kubernetes
a_j5815 小时前
Kubernetes知识点总结(十)
云原生·容器·kubernetes
零炻大礼包16 小时前
【DeepSeek-R1】 API申请(腾讯云)
云计算·腾讯云·deepseek-r1
因_果_律17 小时前
如何最优雅地部署 AWS Lambda?Lambda Version 与 Alias 的最佳实践
serverless·云计算·aws