1
  • I want scale up my statefulset and want to initiate this scale up from inside the pod(container) using the Kubernetes API(http request) to the kubernetes rest server.
  • 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 :

Can somebody help me with this?

himanshu
  • 175
  • 3
  • 12
  • error mesaage state that service account do not have permission to view the statefulsets. ask your kubernetes administrator to assign permission to this service account – Dashrath Mundkar Aug 21 '20 at 08:49
  • @DashrathMundkar yes there was some permission issue regarding the service account. Thanks for the help. – himanshu Aug 22 '20 at 10:57

1 Answers1

8

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.

Mike Bryant
  • 1,072
  • 9
  • 11
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107