Skip to content

Instantly share code, notes, and snippets.

resource "aws_vpc" "kubernetes" {
cidr_block = "10.43.0.0/16"
enable_dns_hostnames = true
}
resource "aws_subnet" "kubernetes" {
vpc_id = "${aws_vpc.kubernetes.id}"
cidr_block = "10.43.0.0/16"
availability_zone = "eu-west-1a"
}
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.kubernetes.id}"
}
resource "aws_route_table" "kubernetes" {
vpc_id = "${aws_vpc.kubernetes.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
resource "aws_instance" "etcd" {
count = 3
ami = "ami-1967056a" // Unbuntu 16.04 LTS HVM, EBS-SSD
instance_type = "t2.micro"
subnet_id = "${aws_subnet.kubernetes.id}"
private_ip = "${cidrhost("10.43.0.0/16", 10 + count.index)}"
associate_public_ip_address = true
availability_zone = "eu-west-1a"
resource "aws_elb" "kubernetes_api" {
name = "kube-api"
instances = ["${aws_instance.controller.*.id}"]
subnets = ["${aws_subnet.kubernetes.id}"]
cross_zone_load_balancing = false
security_groups = ["${aws_security_group.kubernetes_api.id}"]
listener {
lb_port = 6443
resource "aws_instance" "worker" {
count = 3
...
tags {
Owner = "Lorenzo"
Name = "worker-${count.index}"
ansibleFilter = "Kubernetes01"
ansibleNodeType = "worker"
ansibleNodeName = "worker${count.index}"
}
resource "aws_security_group" "kubernetes" {
vpc_id = "${aws_vpc.kubernetes.id}"
name = "kubernetes"
# Allow all outbound
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
# Generate Certificates
data "template_file" "certificates" {
template = "${file("${path.module}/template/kubernetes-csr.json")}"
depends_on = ["aws_elb.kubernetes_api","aws_instance.etcd","aws_instance.controller","aws_instance.worker"]
vars {
kubernetes_api_elb_dns_name = "${aws_elb.kubernetes_api.dns_name}"
kubernetes_cluster_dns = "${var.kubernetes_cluster_dns}"
etcd0_ip = "${aws_instance.etcd.0.private_ip}"
...
controller0_ip = "${aws_instance.controller.0.private_ip}"
- hosts: etcd
roles:
- common
- etcd
- hosts: controller
roles:
- common
- controller
[ec2]
instance_filters = tag:ansibleFilter=Kubernetes01
regions = eu-west-1
destination_variable = ip_address
vpc_destination_variable = ip_address
hostname_variable = tag_ansibleNodeName
@nicusX
nicusX / k8snthw-groups
Last active August 11, 2016 10:34
Ansible groups
[tag_ansibleNodeType_etcd]
[tag_ansibleNodeType_worker]
[tag_ansibleNodeType_controller]
[etcd:children]
tag_ansibleNodeType_etcd
[worker:children]
tag_ansibleNodeType_worker