Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce3a5b39f5 | ||
|
|
ad0212a29d | ||
|
|
1787590da2 | ||
|
|
17c60e41bb | ||
|
|
ec6bb824d0 | ||
|
|
091b459046 | ||
|
|
b4ac04fbd8 | ||
|
|
31a70766ec | ||
|
|
25794c641a | ||
|
|
b0b959f28b |
@@ -1,3 +1,15 @@
|
|||||||
|
A Terraform script to create k8s nodes. This script has modules for creating the
|
||||||
|
nodes on a KVM/QEMU (libvirt) hypervisor or creating the nodes via AWS.
|
||||||
|
|
||||||
|
The modules allow you create N VMs of a specific type. So you could create 1
|
||||||
|
master node and 3 worker nodes or you could create 3 Ubuntu VMs and 5 CentOS
|
||||||
|
VMs, or whatever fits your needs.
|
||||||
|
|
||||||
|
Cloud-Init
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
Both the libvirt and aws modules use cloud-init for initial configuration of the
|
||||||
|
VMs.
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|||||||
+1
-14
@@ -1,4 +1,4 @@
|
|||||||
vm-name-prefix = "k8s-tf"
|
vm-name-prefix = "ansible-test"
|
||||||
|
|
||||||
# A CIDR block ending in '/32' equates to a single IP address, '0.0.0.0/0'
|
# A CIDR block ending in '/32' equates to a single IP address, '0.0.0.0/0'
|
||||||
# equates to any ip address.
|
# equates to any ip address.
|
||||||
@@ -21,19 +21,6 @@ aws-ec2-instance-type = "t2.micro"
|
|||||||
# 4 GiB, 2 vcpus
|
# 4 GiB, 2 vcpus
|
||||||
# aws-ec2-instnce-type = "t2.medium"
|
# aws-ec2-instnce-type = "t2.medium"
|
||||||
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
nodes-config = {
|
|
||||||
"master" = {
|
|
||||||
base-image = "ami-0dd0ccab7e2801812"
|
|
||||||
num = 1
|
|
||||||
},
|
|
||||||
"worker" = {
|
|
||||||
base-image = "ami-0dd0ccab7e2801812"
|
|
||||||
num = 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# AWS images (AMIs)
|
# AWS images (AMIs)
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
aws ec2 describe-instance-status | \
|
||||||
|
jq '.InstanceStatuses[] | {id: .InstanceId, instance_status: .InstanceStatus.Status, system_status: .SystemStatus.Status}'
|
||||||
@@ -8,12 +8,25 @@ terraform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
nodes-config = {
|
||||||
|
"master" = {
|
||||||
|
base-image = var.amzn2-ami
|
||||||
|
num = 1
|
||||||
|
},
|
||||||
|
"worker" = {
|
||||||
|
base-image = var.amzn2-ami
|
||||||
|
num = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# cloud-init
|
# cloud-init
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
module "cloud-init-config" {
|
module "cloud-init-config" {
|
||||||
for_each = var.nodes-config
|
for_each = local.nodes-config
|
||||||
source = "./modules/cloud-init-config"
|
source = "./modules/cloud-init-config"
|
||||||
cloud-init-template = "${path.module}/cloud_init.cfg"
|
cloud-init-template = "${path.module}/cloud_init.cfg"
|
||||||
hostname-prefix = "${var.vm-name-prefix}-${each.key}"
|
hostname-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||||
@@ -32,7 +45,8 @@ provider "aws" {
|
|||||||
region = "us-east-2"
|
region = "us-east-2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# This module will grab the latest ami for a variety of distros.
|
# This module will grab the latest ami for a variety of distros. Uncomment to
|
||||||
|
# get a list of the latest AMIs for our supported distros.
|
||||||
# module "aws-amis" {
|
# module "aws-amis" {
|
||||||
# source = "./modules/aws-amis"
|
# source = "./modules/aws-amis"
|
||||||
# }
|
# }
|
||||||
@@ -59,7 +73,7 @@ resource "aws_key_pair" "key" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module "nodes" {
|
module "nodes" {
|
||||||
for_each = var.nodes-config
|
for_each = local.nodes-config
|
||||||
source = "./modules/aws-nodes"
|
source = "./modules/aws-nodes"
|
||||||
ami = each.value.base-image
|
ami = each.value.base-image
|
||||||
ec2-instance-type = var.aws-ec2-instance-type
|
ec2-instance-type = var.aws-ec2-instance-type
|
||||||
@@ -85,7 +99,7 @@ module "nodes" {
|
|||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# module "nodes" {
|
# module "nodes" {
|
||||||
# for_each = var.nodes-config
|
# for_each = local.nodes-config
|
||||||
# source = "./modules/libvirt-nodes"
|
# source = "./modules/libvirt-nodes"
|
||||||
# pool-name = libvirt_pool.images.name
|
# pool-name = libvirt_pool.images.name
|
||||||
# name-prefix = "${var.vm-name-prefix}-${each.key}"
|
# name-prefix = "${var.vm-name-prefix}-${each.key}"
|
||||||
|
|||||||
+36
-5
@@ -43,11 +43,6 @@ variable "node-vcpus" {
|
|||||||
type = number
|
type = number
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "nodes-config" {
|
|
||||||
description = "A config that declares how many nodes of each type you want created."
|
|
||||||
type = map(object({base-image=string,num=number}))
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "root-admin-passwd" {
|
variable "root-admin-passwd" {
|
||||||
description = "This will be the password for the root and admin user. The format of this can by any format accepted by cloud-init's chpasswd module."
|
description = "This will be the password for the root and admin user. The format of this can by any format accepted by cloud-init's chpasswd module."
|
||||||
}
|
}
|
||||||
@@ -76,3 +71,39 @@ variable "vm-name-prefix" {
|
|||||||
default = "k8s-tf"
|
default = "k8s-tf"
|
||||||
description = "This prefix will appear before all VM names and hostnames, ie. k8s-tf-master-0."
|
description = "This prefix will appear before all VM names and hostnames, ie. k8s-tf-master-0."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# AWS AMI vars
|
||||||
|
# These variables are really mor like constants. Using variables improves
|
||||||
|
# readability. The defaults are manually updated. Use the aws-amis module to get
|
||||||
|
# the latest for each distro.
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
variable "amzn2-ami" {
|
||||||
|
default = "ami-0dd0ccab7e2801812"
|
||||||
|
description = "The AMI to use for Amazon Linux 2."
|
||||||
|
}
|
||||||
|
variable "ubuntu-ami" {
|
||||||
|
default = "ami-06c7d6c0987eaa46c"
|
||||||
|
description = "The AMI to use for Ubuntu."
|
||||||
|
}
|
||||||
|
variable "centos7-ami" {
|
||||||
|
default = "ami-00f8e2c955f7ffa9b"
|
||||||
|
description = "The AMI to use for CentOS 7."
|
||||||
|
}
|
||||||
|
variable "centos8-ami" {
|
||||||
|
default = "ami-057cacbfbbb471bb3"
|
||||||
|
description = "The AMI to use for CentOS 8."
|
||||||
|
}
|
||||||
|
variable "arch-ami" {
|
||||||
|
default = "ami-02653f06de985e3ba"
|
||||||
|
description = "The AMI to use for Arch Linux."
|
||||||
|
}
|
||||||
|
variable "rhel7-ami" {
|
||||||
|
default = "ami-0a509b3c2a4d05b3f"
|
||||||
|
description = "The AMI to use for RHEL 7."
|
||||||
|
}
|
||||||
|
variable "rhel8-ami" {
|
||||||
|
default = "ami-0d871ca8a77af2948"
|
||||||
|
description = "The AMI to use for RHEL 8."
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user