Create ServiceAccounts for access to the Kubernetes Deployments

9/3/2018

I want to access to the kubernetes deployment objects via api server .

I have a service account file shown as below .

apiVersion: v1
kind: ServiceAccount
metadata:
  name: name
  namespace: namespace

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: name
  namespace: namespace
rules:
- apiGroups: [""]
  resources: ["deployment"]
  verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
  resources: ["deployment/exec"]
  verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
  resources: ["deployment/log"]
  verbs: ["get","list","watch"]
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get"]

---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: name
  namespace: namespace
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: name
subjects:
- kind: ServiceAccount
  name: name

I'm getting 403 Forbidden error the token with owner of this service-accounts while access the endpoint

/apis/apps/v1beta1/namespaces/namespace/deployments
-- ColossusMark1
kubernetes
rbac

1 Answer

9/3/2018

All of your role's rules are for the core (empty) API group. However, the URL you're trying to access, /apis/apps/v1beta1, is in the "apps" API group (the part of the path after /apis). So to access that particular API path, you need to change the role definition to

rules:
- apiGroups: ["apps"]
  resources: ["deployment"]
  verbs: ["create","delete","get","list","patch","update","watch"]
# and also the other deployment subpaths
-- David Maze
Source: StackOverflow