k8s cluster deployed to AWS.

master
shnee 4 years ago
parent 15edee3b60
commit 4d39461101

3
.gitignore vendored

@ -44,6 +44,7 @@ terraform.rc
################################################################################
k8s-key*
STARTHERE
*admin-key*
TARTHERE
inventory

@ -22,6 +22,10 @@ VM_NAME_PREFIX="$(
tail -n 1 | \
sed 's/^.*=\s*"\(.*\)"/\1/g')"
PUBLIC_IP_OUTPUT="groups_hostnames_ips"
PRIVATE_IP_OUTPUT="groups_hostnames_private_ips"
IP_TYPE="$PRIVATE_IP_OUTPUT"
# This command stores the output data in the format below.
# [
# {
@ -48,7 +52,7 @@ VM_NAME_PREFIX="$(
# }
# ]
DATA="$(terraform show -json | \
jq '.values.outputs.groups_hostnames_ips.value | to_entries |
jq '.values.outputs.'"$IP_TYPE"'.value | to_entries |
map({group: .key, vms:.value | to_entries |
map({hostname:.key,ip:.value})})')"

@ -2,11 +2,11 @@
locals {
nodes-config = {
"master" = {
base-image = var.centos8-ami
base-image = var.ubuntu-ami
num = 1
},
"worker" = {
base-image = var.centos8-ami
base-image = var.ubuntu-ami
num = 2
}
}
@ -79,8 +79,8 @@ module "nodes" {
source = "./modules/aws-nodes"
ami = each.value.base-image
ec2-instance-type = var.aws-ec2-instance-type
subnet-id = module.aws-network.subnet.id
security-group-ids = [module.aws-network.default-security-group.id]
subnet-id = module.aws-network-existing.k8s-subnets[0]
security-group-ids = [data.aws_security_group.default.id]
user-datas = lookup(module.cloud-init-config, each.key, null).user-datas
num-nodes = each.value.num
name-prefix = "${var.vm-name-prefix}-${each.key}"
@ -132,3 +132,9 @@ module "nodes" {
output "groups_hostnames_ips" {
value = { for type, node in module.nodes : type => zipmap(node.names, node.ips) }
}
# This will outpus a map of group => [{hostname, private_ip}].
# TODO Figure out how what to do about private_ips for libvirt.
output "groups_hostnames_private_ips" {
value = { for type, node in module.nodes : type => zipmap(node.names, node.private_ips) }
}

@ -1,31 +1,52 @@
locals {
amis = {
amzn2 = {
owner-id = "137112412989"
# us-east-2
# owner-id = "137112412989"
# us-gov-west-1
owner-id = "045324592363"
name = "amzn2-ami-hvm-2*x86_64-gp2"
},
ubuntu = {
owner-id = "099720109477"
# us-east-2
# owner-id = "099720109477"
# us-gov-west-1
owner-id = "513442679011"
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
},
centos7 = {
owner-id = "125523088429"
name = "CentOS 7.*x86_64"
},
centos8 = {
owner-id = "125523088429"
name = "CentOS 8.*x86_64"
},
arch = {
owner-id = "093273469852"
name = "arch-linux-lts-hvm*x86_64-ebs"
},
# centos7 = {
# # us-east-2
# # owner-id = "125523088429"
# # us-gov-west-1
# # owner-id = THERE IS NO CENTOS7 IMAGE in us-gov-west-1!!
# name = "CentOS 7.*x86_64"
# },
# centos8 = {
# # us-east-2
# # owner-id = "125523088429"
# # us-gov-west-1
# # owner-id = THERE IS NO CENTOS8 IMAGE in us-gov-west-1!!
# name = "CentOS 8.*x86_64"
# },
# arch = {
# # us-east-2
# # owner-id = "093273469852"
# # us-gov-west-1
# # owner-id = THERE IS NO ARCH IMAGE in us-gov-west-1!!
# name = "arch-linux-lts-hvm*x86_64-ebs"
# },
rhel7 = {
owner-id = "309956199498"
# us-east-2
# owner-id = "309956199498"
# us-gov-west-1
owner-id = "219670896067"
name = "RHEL-7.*HVM*x86_64*GP2"
},
rhel8 = {
owner-id = "309956199498"
# us-east-2
# owner-id = "309956199498"
# us-gov-west-1
owner-id = "219670896067"
name = "RHEL-8.*HVM*x86_64*GP2"
}
}

@ -3,6 +3,7 @@ resource "aws_instance" "nodes" {
instance_type = var.ec2-instance-type
# TODO REM double check this key.
# key_name = aws_key_pair.debug1.key_name
# TODO Make this a variable.
associate_public_ip_address = true
subnet_id = var.subnet-id
vpc_security_group_ids = var.security-group-ids

@ -2,6 +2,10 @@ output "ips" {
value = aws_instance.nodes.*.public_ip
}
output "private_ips" {
value = aws_instance.nodes.*.private_ip
}
output "names" {
value = aws_instance.nodes.*.tags.Name
}

@ -1,4 +1,5 @@
variable "admin-ips" {
default = ["0.0.0.0/0"]
description = "A list of ips or cidr blocks that are allowed to connect to the nodes."
type = list(string)
}
@ -33,6 +34,7 @@ variable "disk-image-pool-name" {
}
variable "libvirt-connection-url" {
default = "nobody@localhost"
description = "The libvirt connection URI, ie. qemu+ssh://<user>@<host>/system"
}
@ -95,31 +97,46 @@ variable "vm-name-prefix" {
################################################################################
variable "amzn2-ami" {
default = "ami-0dd0ccab7e2801812"
# us-east-2
# default = "ami-0dd0ccab7e2801812"
# us-gov-west-1
default = "ami-098bf51d9a35299f0"
description = "The AMI to use for Amazon Linux 2."
}
variable "ubuntu-ami" {
default = "ami-06c7d6c0987eaa46c"
# us-east-2
# default = "ami-06c7d6c0987eaa46c"
# us-gov-west-1
default = "ami-087ee83c8de303181"
description = "The AMI to use for Ubuntu."
}
variable "centos7-ami" {
# us-east-2
default = "ami-00f8e2c955f7ffa9b"
description = "The AMI to use for CentOS 7."
}
variable "centos8-ami" {
# us-east-2
default = "ami-057cacbfbbb471bb3"
description = "The AMI to use for CentOS 8."
}
variable "arch-ami" {
# us-east-2
default = "ami-02653f06de985e3ba"
description = "The AMI to use for Arch Linux."
}
variable "rhel7-ami" {
default = "ami-0a509b3c2a4d05b3f"
# us-east-2
# default = "ami-0a509b3c2a4d05b3f"
# us-gov-west-1
default = "ami-04ccdf5793086ea95"
description = "The AMI to use for RHEL 7."
}
variable "rhel8-ami" {
default = "ami-0d871ca8a77af2948"
# us-east-2
# default = "ami-0d871ca8a77af2948"
# us-gov-west-1
default = "ami-0b1f10cd1cd107dd2"
description = "The AMI to use for RHEL 8."
}

Loading…
Cancel
Save