Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Latest commit

 

History

History
145 lines (119 loc) · 6.55 KB

cattle_demo.md

File metadata and controls

145 lines (119 loc) · 6.55 KB

A Simple Group Demo with Terraform

This demo combines the Terraform instance plugin and a simple vanilla plugin to provision instances in AWS. The Terraform configurations are found in the directory aws-two-tier.

1. The group config

the file [example/instance/terraform/aws-two-tier/group.json)(./example/instance/terraform/aws-two-tier/group.json) shows a simple group of cattle nodes provisioned using Terraform:

{
    "ID": "terraform_demo",
    "Properties": {
        "Instance": {
            "Plugin": "instance-terraform",
            "Properties": {
                "type": "aws_instance",
                "value": {
                    "ami": "${lookup(var.aws_amis, var.aws_region)}",
                    "instance_type": "t2.micro",
                    "key_name": "chungers-ssh",
                    "vpc_security_group_ids": ["${aws_security_group.default.id}"],
                    "subnet_id": "${aws_subnet.default.id}",
                    "tags":  {
                        "Tier": "web",
                        "provisioner": "infrakit-terraform-demo"
                    },
                    "connection": {
                        "user": "ubuntu"
                    }
                }
            }
        },
        "Flavor": {
            "Plugin": "flavor-vanilla",
            "Properties": {
                "Size": 5,
                "Init": [
                    "sudo apt-get update -y",
                    "sudo apt-get install -y nginx",
                    "sudo service nginx start"
                ]
            }
        }
    }
}

2. Start the plugins

From the top level directory of the project:

# The instance plugin:
$ build/infrakit-instance-terraform --dir $(pwd)/example/instance/terraform/aws-two-tier/
# The group plugin
$ build/infrakit-group-default
# The vanilla flavor
$ build/infrakit-flavor-vanilla

3. List all the instances

$ build/infrakit instance --name=instance-terraform describe
ID                                                LOGICAL                               TAGS
# no instances

4. Commit the group

Using the JSON we showed above, commit the group:

$ build/infrakit group commit example/instance/terraform/aws-two-tier/group.json
Committed terraform_demo

The group plugin starts to create new instances to match the specification. In the AWS console using infrakit-terraform-demo as tag filter, we find these instances instances

5. List members

$ build/infrakit group describe terraform_demo
ID                              LOGICAL                         TAGS
instance-1475601644               -                             Name=instance-1475601644,Tier=web,infrakit.config.hash=BmjtnDnrqBvGHm05Nin3Vb66NaA=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475601645               -                             Name=instance-1475601645,Tier=web,infrakit.config.hash=BmjtnDnrqBvGHm05Nin3Vb66NaA=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475601634               -                             Name=instance-1475601634,Tier=web,infrakit.config.hash=BmjtnDnrqBvGHm05Nin3Vb66NaA=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475601635               -                             Name=instance-1475601635,Tier=web,infrakit.config.hash=BmjtnDnrqBvGHm05Nin3Vb66NaA=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475601636               -                             Name=instance-1475601636,Tier=web,infrakit.config.hash=BmjtnDnrqBvGHm05Nin3Vb66NaA=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo

6. Update the config

Let's change the size to 8 and the instance type to t2.nano.

Before committing, let's use the --pretend flag to double-check what will happen:

$ build/infrakit group commit example/instance/terraform/aws-two-tier/group.json --pretend
Committing terraform_demo will involve: Performing a rolling update on 5 instances, then adding 3 instances to increase the group size to 8

Looks good. Let's commit:

$ build/infrakit group commit example/instance/terraform/aws-two-tier/group.json
Committed terraform_demo

7. Check on the group:

The commit will proceed in the background, and after a short period the group will converge to the new configuration:

$ build/infrakit group describe terraform_demo
ID                              LOGICAL                         TAGS
instance-1475602365               -                             Name=instance-1475602365,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602374               -                             Name=instance-1475602374,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602314               -                             Name=instance-1475602314,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602324               -                             Name=instance-1475602324,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602334               -                             Name=instance-1475602334,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602344               -                             Name=instance-1475602344,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602354               -                             Name=instance-1475602354,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo
instance-1475602364               -                             Name=instance-1475602364,Tier=web,infrakit.config.hash=NP0kIk4bVoojdRZsRGC0XKTrrUs=,infrakit.group=terraform_demo,provisioner=infrakit-terraform-demo

Note the new SHA of the instances.

Also, in the console: instances2

You can also try to remove some instances and see that the group size will be restored shortly.

8. Tear everything down

We are done with the demo, remove the resources...

$ build/infrakit group destroy terraform_demo
destroy terraform_demo initiated