Putting kubernetes cluster to "rest" with kops
A Question that came up today during our DevOps Bi Weekly meetup was:
“what is the easiest way to shutdown the kubernetes cluster we span up without loosing state / data ?”
So as promised this short how to cover that.
- A running kubernetes cluster installed via
As we saw today
kops has 2 main types we can tampre with:
- Cluster configuration - all the VPC specifications like subnets and route + kubelet configuration flages etc etc
- The instance grops which reperest the
nodesand in our experimental case the
to get the correct list of your isntancegroups (name may vary considering the availability zone you may run in e.g us-east-1 … ).
In our case:
kops get instancegroups NAME ROLE MACHINETYPE MIN MAX ZONES master-eu-west-1a Master m3.medium 1 1 eu-west-1a nodes Node t2.medium 2 2 eu-west-1a
kops sets master and nodes into Auto Scaling Groups we can set the min + max value to
0 and by that “put our cluster to rest” and once we increace the min/max count it will spin up with all the previous configurations and deployments etc stored in etcd.
Editing the instance groups:
kops edit ig nodes will yield the following (again details may vary):
apiVersion: kops/v1alpha2 kind: InstanceGroup metadata: creationTimestamp: 2018-04-25T13:48:02Z labels: kops.k8s.io/cluster: ac.hub.k8s.local name: nodes spec: image: ami-34237c4d machineType: t2.medium maxSize: 2 minSize: 2 nodeLabels: kops.k8s.io/instancegroup: nodes role: Node subnets: - eu-west-1a
0 will just tell the aws api to shutdown them instances until i’m ready to summen them again ;)
Please note: You will need to repeat this same process on your master nodes and once complete apply the changes to the cluster like so.
To complete the update and put the cluster to sleep run:
kops rolling-update cluster (without –yes in order to review our changes):
kops rolling-update cluster NAME STATUS NEEDUPDATE READY MIN MAX NODES master-eu-west-1a NeedsUpdate 1 0 1 1 1 nodes NeedsUpdate 2 0 2 2 2
As you can see above there are 3 instances which is in “Needs Update” state hence:
kops rolling-update cluster --yes will do that for you !
Once complete just to be sure run somthing like
aws ec2 describe instances --region <your region> and see you have no instances running in that vpc …
Hope this helps.
Share this article: