fbpx

Working with InstanceGroups

The kops InstanceGroup is a declarative model of a group of nodes. each InstanceGroup is managed by an Elastigroup. By modifying the object, you can change the number of nodes, the OS image you’re running – essentially all the per-node configuration is in the InstanceGroup including custom labels.  CPU / GPU

We’ll assume you have a working cluster – if not, you probably want to read how to get started.

 

Edit InstanceGroup

./05-edit-ig.sh

OR

. 00-env.sh && kops edit ig nodes \
    --name $KOPS_CLUSTER_NAME \
    --state $KOPS_STATE_STORE \
    --logtostderr --v 2

This command will essentially download the cluster state from your s3 state bucket, and open a vim terminal to make the changes.

The default instance-group called nodes

Example of an InstanceGroup

apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
  creationTimestamp: 2017-12-27T23:21:17.000Z
  labels:
    kops.k8s.io/cluster: stav.ek8s.com
  name: nodes
spec:
  image: kope.io/k8s-1.7-debian-jessie-amd64-hvm-ebs-2017-12-02
  machineType: 'm4.large,m3.large,c4.large,c3.large'
  maxSize: 2
  minSize: 2
  role: Node
  subnets:
    - us-east-1a
    - us-east-1b

 

Add A Custom Label

metadata:
  creationTimestamp: 2017-12-27T23:21:17.000Z
  labels:
    kops.k8s.io/cluster: stav.ek8s.com
    tasks: cpu
  name: nodes

Under metadata -> labels add tasks: cpu

 

:wq!

On saving you’ll note that nothing happens. Although you’ve changed the model, you need to tell kops to apply your changes to the cloud.

 

We use the same kops update cluster command that we used when initially creating the cluster;

00-env.sh && kops update cluster \
    --name $KOPS_CLUSTER_NAME \
    --state $KOPS_STATE_STORE \
    --logtostderr --v 2 \
    --yes
When running without --yes it should show you a preview of the changes 

 

Rolling Updates

There are some changes that might require a rolling-update command meaning = to force your instances to restart. So in order to complete that update, we will have to roll the configuration to the nodes, using the following command:

. 00-env.sh && kops rolling-update cluster \
    --name $KOPS_CLUSTER_NAME \
    --state $KOPS_STATE_STORE \
    --node-interval 30s \
    --instance-group $KOPS_IG_NAME \
    --logtostderr --v 2 \
    --yes

The cluster will now roll that new configuration on the nodes in the cluster using a graceful draining timeout one by one and will wait for 1m30s for pods to stabilize after draining.

 

Create A New Instance Group

If we want to create an additional instance-group for different labeling purposes, or just to distinguish between different environments, we will use the following sequence.

. 00-env.sh && kops create ig nodesmore \
    --name $KOPS_CLUSTER_NAME \
    --state $KOPS_STATE_STORE \
    --role node \
    --subnet us-east-1a \
    --logtostderr --v 2

That command will open a vim terminal to verify the InstanceGroup configuration before creating the instance group

apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
  creationTimestamp: null
  name: nodesmore
spec:
  image: kope.io/k8s-1.7-debian-jessie-amd64-hvm-ebs-2017-12-02
  machineType: m3.medium
  maxSize: 2
  minSize: 2
  role: Node
  subnets:
  - us-east-1a

Save and exit the terminal will trigger the new InstanceGroup creation

:wq!

 

Please note, again, that it did not actually create the InstanceGroup, it just updates the kops-state bucket with that new config. In order to trigger the instance-group creation, we should run kops update cluster command.

. 00-env.sh && kops update cluster \
    --name $KOPS_CLUSTER_NAME \
    --state $KOPS_STATE_STORE \
    --logtostderr --v 2 \
    --yes

Now, the instance-group nodesmore is created