-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attach EBS volumes to etcd nodes for persistence #98
Open
adambom
wants to merge
5
commits into
kz8s:master
Choose a base branch
from
adambom:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
adaa14e
Attach EBS volumes to etcd nodes for persistence
adambom c217df1
Add snapshotting module
adambom 654a949
Remove unneeded vars
adambom 0653e76
Add info about ebs volumes to readme
adambom 8e73f42
Mount /dev/xvdf in cloud-config for etcd
adambom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
resource "aws_iam_role" "snapshot" { | ||
name = "snapshot" | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_role_policy" "snapshot" { | ||
name = "snapshot-k8s-${ var.name }" | ||
|
||
policy = <<EOS | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["logs:*"], | ||
"Resource": "arn:aws:logs:*:*:*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": "ec2:Describe*", | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:CreateNetworkInterface", | ||
"ec2:DescribeNetworkInterfaces", | ||
"ec2:DetachNetworkInterface", | ||
"ec2:DeleteNetworkInterface" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:CreateSnapshot", | ||
"ec2:CreateTags", | ||
"ec2:ModifySnapshotAttribute", | ||
"ec2:ResetSnapshotAttribute" | ||
], | ||
"Resource": ["*"] | ||
} | ||
] | ||
} | ||
EOS | ||
|
||
role = "${ aws_iam_role.snapshot.id }" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resource "aws_cloudwatch_event_rule" "snapshot" { | ||
name = "snapshot-${ var.name }" | ||
description = "Schedule snapshots of ebs volumes" | ||
|
||
schedule_expression = "rate(2 hours)" | ||
} | ||
|
||
resource "aws_cloudwatch_event_target" "snapshot" { | ||
rule = "${ aws_cloudwatch_event_rule.snapshot.name }" | ||
arn = "${ aws_lambda_function.snapshot.arn }" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
variable "iam-role-snapshot-arn" {} | ||
variable "name" {} | ||
variable "security-groups" {} | ||
variable "subnet-ids" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
resource "aws_lambda_permission" "snapshot" { | ||
statement_id = "AllowExecutionFromCloudWatchForSnapshots" | ||
action = "lambda:InvokeFunction" | ||
function_name = "${ aws_lambda_function.snapshot.arn }" | ||
principal = "events.amazonaws.com" | ||
source_arn = "${ aws_cloudwatch_event_rule.snapshot.arn }" | ||
} | ||
|
||
resource "aws_lambda_function" "snapshot" { | ||
filename = "${ path.module }/../../tmp/snapshot.zip" | ||
function_name = "snapshot-${ var.name }" | ||
handler = "snapshot.snapshot" | ||
runtime = "python2.7" | ||
source_code_hash = "${ base64sha256(data.template_file.init.rendered) }" | ||
|
||
role = "${ var.iam-role-snapshot-arn }" | ||
|
||
vpc_config { | ||
subnet_ids = ["${ split(",", var.subnet-ids) }"] | ||
security_group_ids = ["${ split(",", var.security-groups) }"] | ||
} | ||
} | ||
|
||
data "template_file" "init" { | ||
template = "${ file("${ path.module }/snapshot.py.tpl") }" | ||
|
||
vars { | ||
name = "${ var.name }" | ||
} | ||
} | ||
|
||
resource "archive_file" "init" { | ||
type = "zip" | ||
source_content_filename = "snapshot.py" | ||
source_content = "${ data.template_file.init.rendered }" | ||
output_path = "${ path.module }/../../tmp/snapshot.zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import boto3 | ||
|
||
|
||
ec = boto3.client('ec2') | ||
|
||
def snapshot(event, context): | ||
volumes = ec.describe_volumes(Filters=[{ | ||
'Name': 'tag:KubernetesCluster', | ||
'Values': ['${ name }'], }]) | ||
|
||
for vol in volumes.get('Volumes', []): | ||
snap = ec.create_snapshot(VolumeId=vol.get('VolumeId')) | ||
ec.create_tags( | ||
Resources=[snap.get('SnapshotId')], | ||
Tags=vol.get('Tags')) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adambom - Where are you mounting xvdf ? Or am I missing something ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to include some changes to cloud-config.tf. On startup we format /dev/xvdf and mount it to /media/etcd2 and instruct etcd to use that location to persist state. I chose xvdf because that's the device we're using on worker nodes for ephemeral storage. See 8e73f42.