What are the options to scale up/scale down a kubernetes statefulset during runtime? What are the options to scale up/scale down a kubernetes statefulset during runtime? kubernetes kubernetes

What are the options to scale up/scale down a kubernetes statefulset during runtime?


You can setup a CronJob that will spawn a pod each (x minutes) and check, for example by using ConfigMap if it needs to scale up/down the StatefulSet.

This Job will use the REST API, with it you can use API reference docs to Replace or Patch your StatefulSet.

You can do that by:

Using kubectl proxy

$ kubectl proxy --port=8080 & See kubectl proxy for more details.

Then you can explore the API with curl, wget, or a browser, like so:

$ curl http://localhost:8080/api/ The output is similar to this:

{  "versions": [    "v1"  ],  "serverAddressByClientCIDRs": [    {      "clientCIDR": "0.0.0.0/0",      "serverAddress": "10.0.1.149:443"    }  ]}

Without kubectl proxy

It is possible to avoid using kubectl proxy by passing an authentication token directly to the API server, like this:

Using grep/cut approach:

# Check all possible clusters, as you .KUBECONFIG may have multiple contexts:kubectl config view -o jsonpath='{"Cluster name\tServer\n"}{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'# Select name of cluster you want to interact with from above output:export CLUSTER_NAME="some_server_name"# Point to the API server refering the cluster nameAPISERVER=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$CLUSTER_NAME\")].cluster.server}")# Gets the token valueTOKEN=$(kubectl get secrets -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='default')].data.token}"|base64 -d)# Explore the API with TOKENcurl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure

The output is similar to this:

{  "kind": "APIVersions",  "versions": [    "v1"  ],  "serverAddressByClientCIDRs": [    {      "clientCIDR": "0.0.0.0/0",      "serverAddress": "10.0.1.149:443"    }  ]}

Or with programmatic access to the API, Kubernetes officially supports Go and Python client libraries.

I hope this helps you a bit, if you have further questions please ask.