Skip to content

Instantly share code, notes, and snippets.

@vishnuhd
Last active September 3, 2019 13:03
Show Gist options
  • Save vishnuhd/d8cad4cb73fd7c481b09698ac741859c to your computer and use it in GitHub Desktop.
Save vishnuhd/d8cad4cb73fd7c481b09698ac741859c to your computer and use it in GitHub Desktop.
Managing kubernetes cluster with KOPS

Managing kubernetes cluster with KOPS

Prerequisite

  • kops
  • kubectl
  • awscli configured

Create the kops cluster

  • For cluster creating we need to add more env variables. NAME will be the name of the cluster, since we wont do DNS settings we will use gossip based DNS and for that cluster name needs to end with .k8s.local and before that you can put almost anything.
export NAME=vhd-demo.k8s.local
  • Create a bucket for kops to use a backend.
aws s3api create-bucket --bucket ${NAME}-state --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1
  • Add env var for bucket state store.
export KOPS_STATE_STORE=s3://${NAME}-state
  • Create the kops cluster.
kops create cluster \
 --name=${NAME} \
 --zones=ap-south-1a \
 --master-size="t3.medium" \
 --node-size="t3.medium" \
 --node-count="3" \
 --master-count="1" \
 --ssh-public-key="~/.ssh/id_rsa.pub"
  • Update the kops cluster to make actual changes in AWS.
kops update cluster --name ${NAME} --yes
  • Validate the created cluster, it might take a while to get it up and running.
kops validate cluster

Update/Stop the kops cluster

  • Get the instance group names.
kops get ig
  • Edit the instance group for the nodes and set maxSize and minSize to 0.
kops edit ig nodes
  • Edit the instance group for the master and set maxSize and minSize to 0.
kops edit ig master-ap-south-1a
  • Lastly, update the cluster to apply changes.
kops update cluster --yes
  • Changes may require instances to restart.
kops rolling-update cluster
  • If you want to turn your cluster back on, revert the settings, changing your master to at least 1, and your nodes to your liking, example 2. Then perform update cluster as earlier.

Delete the kops cluster

  • Delete the kops cluster.
kops delete cluster ${NAME} --yes
  • Delete the s3 bucket backend.
aws s3api delete-bucket --bucket ${NAME}-state --region ap-south-1

PS : This is not production ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment