unable to scale down Kubernetes cluster

7/2/2020

I have a Cassandra/Kubernetes cluster on GCP

manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get statefulsets --all-namespaces                                                                                                        
NAMESPACE       NAME                       READY   AGE
cass-operator   cluster1-dc1-default-sts   3/3     2d9h
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get all -n cass-operator                                                                                                                 
NAME                                 READY   STATUS    RESTARTS   AGE
pod/cass-operator-5f8cdf99fc-9c5g4   1/1     Running   0          2d9h
pod/cluster1-dc1-default-sts-0       2/2     Running   0          2d9h
pod/cluster1-dc1-default-sts-1       2/2     Running   0          2d9h
pod/cluster1-dc1-default-sts-2       2/2     Running   0          2d9h

NAME                                          TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)             AGE
service/cass-operator-metrics                 ClusterIP      10.51.243.147   <none>          8383/TCP,8686/TCP   2d9h
service/cassandra-loadbalancer                LoadBalancer   10.51.240.24    34.91.214.233   9042:30870/TCP      37h
service/cassandradatacenter-webhook-service   ClusterIP      10.51.243.86    <none>          443/TCP             2d9h
service/cluster1-dc1-all-pods-service         ClusterIP      None            <none>          <none>              2d9h
service/cluster1-dc1-service                  ClusterIP      None            <none>          9042/TCP,8080/TCP   2d9h
service/cluster1-seed-service                 ClusterIP      None            <none>          <none>              2d9h

NAME                            READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/cass-operator   1/1     1            1           2d9h

NAME                                       DESIRED   CURRENT   READY   AGE
replicaset.apps/cass-operator-5f8cdf99fc   1         1         1       2d9h

NAME                                        READY   AGE
statefulset.apps/cluster1-dc1-default-sts   3/3     2d9h
manuchadha25@cloudshell:~ (copper-frame-262317)$

I want to scale it down from 3 nodes to 2 nodes. I am tried running the following commands but both failed.

manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl scale statefulsets cluster1-dc1-default-sts --replicas=2
Error from server (NotFound): statefulsets.apps "cluster1-dc1-default-sts" not found

What is the right command to scale down cluster?

-- Manu Chadha
google-kubernetes-engine
kubernetes

2 Answers

7/2/2020

Use -n parameter to specify correct namespace where the statfulset is deployed. Without the namespace it's trying to delete from default namespace where the statfulset cluster1-dc1-default-sts does not exist.

kubectl scale statefulsets cluster1-dc1-default-sts --replicas=2 -n cass-operator
-- Arghya Sadhu
Source: StackOverflow

7/2/2020

Execute command in correct namespace using -n parameter (-n cass-operator in your case)

kubectl scale statefulsets cluster1-dc1-default-sts --replicas=2 -n cass-operator

You can also change namespace for all subsequent commands using

kubectl config set-context --current --namespace=cass-operator
-- Abdul Rauf
Source: StackOverflow