阿里云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
相关推荐
@hdd5 小时前
工作节点组件详解:kubelet、kube-proxy 与容器运行时
容器·kubernetes
@hdd5 小时前
Kubernetes 网络模型:Pod 通信、Service 网络与 CNI
网络·云原生·容器·kubernetes
lingling1989r7 小时前
千万别错过!这3个播客内容技巧让你播放量翻倍
阿里云
only_Klein10 小时前
kubernetes-ReplicaSet控制器
容器·kubernetes
only_Klein12 小时前
Kubernetes-DaemonSet控制器
容器·kubernetes
lingling1989r14 小时前
做播客没做起来,3个让你失眠的真相!
阿里云
hhzz17 小时前
基于对象存储OSS实现企业门户网站托管
阿里云·对象存储·oss·企业网站托管
sun032217 小时前
【AWS】【ECS】部署流程
云计算·aws
阿寻寻18 小时前
【云原生技术】探针**就是:Kubelet(K8s 节点上的组件)会**进入容器里执行一条命令**,根据命令的退出码判断健康
云原生·kubernetes·kubelet
迎仔18 小时前
11-裸金属算力中心:K8s的实际价值与“管一切“的体现
云原生·容器·kubernetes