I tried scaling up statefulset pods using
PUT /apis/apps/v1/namespaces/{namespace}/statefulsets/{name}/scale
but it didn't work for me.
Even tried fetching the scale data of specified statefulset using
"GET /apis/apps/v1/namespaces/{namespace}/statefulsets/{name}/scale"
REQUEST : curl -s -k -H "Authorization: Bearer $TOKEN" -X GET https://kubernetes.default.svc:443/apis/apps/v1/namespaces/$Namespace/$Kind/$PodNamePrefix/scale
Gives an error :
"message": "statefulsets.apps \"app-4x\" is forbidden: User \"system:serviceaccount:<namespace>:default\" cannot get resource \"statefulsets/scale\" in API group \"apps\" in the namespace \"<namespace>\"","reason": "Forbidden",
Reference : https://v1-14.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/
Can somebody help me with this?
You need to define RBAC using Role
and RoleBinding
to authorize the service account to perform the required operations
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: ss-role
rules:
- apiGroups: ["apps"]
resources: ["statefulsets/scale" ]
verbs: ["get", "list", "create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
namespace: default
name: ss-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ss-role
subjects:
- kind: ServiceAccount
name: default
namespace: default
Above Role
and RoleBinding
is based on the assumption that you are using default
service account of default
namespace to scale statefulsets
in default
namespace.