我創建了一個系結到 clusterRole 的服務帳戶。
這是集群角色
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: devops-tools-role
namespace: devops-tools
rules:
- apiGroups:
- ""
- apps
- autoscaling
- batch
- extensions
- policy
- rbac.authorization.k8s.io
- networking.k8s.io
resources:
- pods
- componentstatuses
- configmaps
- daemonsets
- deployments
- events
- endpoints
- horizontalpodautoscalers
- ingress
- ingresses
- jobs
- limitranges
- namespaces
- nodes
- pods
- persistentvolumes
- persistentvolumeclaims
- resourcequotas
- replicasets
- replicationcontrollers
- serviceaccounts
- services
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
我嘗試從 pod 中讀取日志
kubectl -n dfg02 logs postgres-69c7bb5cf7-dstzt
,并得到:
Error from server (Forbidden): pods "postgres-69c7bb5cf7-dstzt" is forbidden: User "system:serviceaccount:devops-tools:bino" cannot get resource "pods/log" in API group "" in the namespace "dfg02"
所以我切換到“管理員”帳戶并嘗試查找要添加到集群角色的資源
? bino@corobalap ~/gitjece kubectl config use-context k0s-cluster
Switched to context "k0s-cluster".
bino@corobalap ~/gitjece kubectl api-resources |grep log
一無所獲。
我的問題是如何將“日志讀取權限”添加到 ClusterRole。
真誠
的-比諾-
uj5u.com熱心網友回復:
日志是 Pod 的子資源,僅在資源部分中指定 pod 是不夠的。
因此,只需將以下內容添加到您的 yaml 中,它就可以作業了。
resources:
- pods
- pods/log
PS:您pods在您的部分中指定了兩次resources,并不是說它做任何事情,只是想指出它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/518575.html
