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.  
  7. for ig in kops/$CLUSTER/instancegroup/*; do
  8. if ! kops get ig --name "$NAME" "$(basename "$ig")"; then
  9. kops create -f "$ig"
  10. else
  11. kops replace -f "$ig"
  12. fi
  13. done