Download kOps config spec file

kOps operates off of a config spec file that is generated during the create phase. It is uploaded to the amazon s3 bucket that is passed in during create.

If you download the config spec file on a running cluster that is configured the way you like it, you can just pass that config spec file in to the create command and have kOps create the cluster for you, kops create -f spec_file in a completely unattended manner.

Let us say you create your cluster with the following configuration options:

  1. export KOPS_STATE_STORE=s3://k8s-us-west
  2. export CLOUD=aws
  3. export ZONE="us-west-1a"
  4. export MASTER_ZONES="us-west-1a"
  5. export NAME=k8s.example.com
  6. export K8S_VERSION=1.6.4
  7. export NETWORKCIDR="10.240.0.0/16"
  8. export MASTER_SIZE="m3.large"
  9. export WORKER_SIZE="m4.large"

Next you call the kOps command to create the cluster in your terminal:

  1. kops create cluster $NAME \
  2. --cloud=$CLOUD \
  3. --zones="$ZONE" \
  4. --kubernetes-version=$K8S_VERSION \
  5. --master-zones="$MASTER_ZONES" \
  6. --node-count=3 \
  7. --node-size="$WORKER_SIZE" \
  8. --master-size="$MASTER_SIZE" \
  9. --network-cidr=${NETWORKCIDR} \
  10. --dns-zone=ZVO7KL181S5AP \
  11. --ssh-public-key=$HOME/.ssh/lab_no_password.pub

kOps command

You can simply use the kOps command kops get --name $NAME -o yaml > a_fun_name_you_will_remember.yml

Note: for the above command to work the cluster NAME and the KOPS_STATE_STORE will have to be exported in your environment.

For more information on how to use and modify the configurations see here.

Managing instance groups

You can also manage instance groups in separate YAML files as well. The command kops get --name $NAME -o yaml > $NAME.yml exports the entire cluster. An option is to have a YAML file for the cluster, and individual YAML files for the instance groups. This allows you to do stuff like:

  1. if ! kops get cluster --name "$NAME"; then
  2. kops create -f "kops/$CLUSTER/$REGION.yaml"
  3. else
  4. kops replace -f "kops/$CLUSTER/$REGION.yaml"
  5. fi
  6. for ig in kops/$CLUSTER/instancegroup/*; do
  7. if ! kops get ig --name "$NAME" "$(basename "$ig")"; then
  8. kops create -f "$ig"
  9. else
  10. kops replace -f "$ig"
  11. fi
  12. done