-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from bailantaotao/support-aws-iam-authenticato…
…r-for-elastickube Support aws iam authenticator for elastickube
- Loading branch information
Showing
17 changed files
with
335 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module "ignition_aws_iam_authenticator" { | ||
source = "../../ignitions/aws-iam-authenticator" | ||
|
||
webhook_kubeconfig_ca = "${module.kubernetes.certificate_authority}" | ||
webhook_kubeconfig_path = "${var.auth_webhook_path}" | ||
} |
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,146 @@ | ||
locals { | ||
project = "elastikube" | ||
phase = "auth" | ||
cluster_name = "${local.phase}-${local.project}" | ||
|
||
kubernetes_version = "v1.10.5" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# SSH | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
provider "aws" { | ||
version = "1.23.0" | ||
region = "${var.aws_region}" | ||
} | ||
|
||
resource "aws_key_pair" "ssh_key" { | ||
public_key = "${file(pathexpand("~/.ssh/id_rsa.pub"))}" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Network | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "network" { | ||
source = "../../aws/network" | ||
aws_region = "${var.aws_region}" | ||
bastion_key_name = "${aws_key_pair.ssh_key.key_name}" | ||
project = "${local.project}" | ||
phase = "${local.phase}" | ||
extra_tags = "${var.extra_tags}" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# ElastiKube | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "kubernetes" { | ||
source = "../../aws/elastikube" | ||
|
||
name = "${local.cluster_name}" | ||
aws_region = "${var.aws_region}" | ||
version = "${local.kubernetes_version}" | ||
service_cidr = "${var.service_cidr}" | ||
cluster_cidr = "${var.cluster_cidr}" | ||
|
||
etcd_config = { | ||
instance_count = "3" | ||
ec2_type = "t2.medium" | ||
root_volume_iops = "0" | ||
root_volume_size = "256" | ||
root_volume_type = "gp2" | ||
} | ||
|
||
master_config = { | ||
instance_count = "2" | ||
ec2_type = "t2.medium" | ||
root_volume_iops = "0" | ||
root_volume_size = "256" | ||
root_volume_type = "gp2" | ||
} | ||
|
||
extra_ignition_file_ids = "${module.ignition_aws_iam_authenticator.files}" | ||
extra_ignition_systemd_unit_ids = "${module.ignition_aws_iam_authenticator.systemd_units}" | ||
|
||
hostzone = "${local.project}.cluster" | ||
subnet_ids = ["${module.network.private_subnet_ids}"] | ||
ssh_key = "${aws_key_pair.ssh_key.key_name}" | ||
reboot_strategy = "off" | ||
|
||
auth_webhook_path = "${var.auth_webhook_path}" | ||
|
||
extra_tags = "${merge(map( | ||
"Phase", "${local.phase}", | ||
"Project", "${local.project}", | ||
), var.extra_tags)}" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Worker Node (On Demand Instance) | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "worker_general" { | ||
source = "../../aws/kube-worker-general" | ||
|
||
name = "${local.cluster_name}" | ||
aws_region = "${var.aws_region}" | ||
version = "${local.kubernetes_version}" | ||
kube_service_cidr = "${var.service_cidr}" | ||
|
||
security_group_ids = ["${module.kubernetes.worker_sg_ids}"] | ||
subnet_ids = ["${module.network.private_subnet_ids}"] | ||
|
||
worker_config = { | ||
name = "general" | ||
instance_count = "2" | ||
ec2_type = "t2.medium" | ||
root_volume_iops = "0" | ||
root_volume_size = "64" | ||
root_volume_type = "gp2" | ||
} | ||
|
||
s3_bucket = "${module.kubernetes.s3_bucket}" | ||
ssh_key = "${aws_key_pair.ssh_key.key_name}" | ||
|
||
extra_tags = "${merge(map( | ||
"Phase", "${local.phase}", | ||
"Project", "${local.project}", | ||
), var.extra_tags)}" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# Worker Node (On Spot Instance) | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
module "worker_spot" { | ||
source = "../../aws/kube-worker-spot" | ||
|
||
name = "${local.cluster_name}" | ||
aws_region = "${var.aws_region}" | ||
version = "${local.kubernetes_version}" | ||
kube_service_cidr = "${var.service_cidr}" | ||
|
||
security_group_ids = ["${module.kubernetes.worker_sg_ids}"] | ||
subnet_ids = ["${module.network.private_subnet_ids}"] | ||
|
||
worker_config = { | ||
name = "spot" | ||
min_instance_count = "2" | ||
max_instance_count = "2" | ||
ec2_type = "m4.large" | ||
price = "0.04" | ||
root_volume_iops = "0" | ||
root_volume_size = "64" | ||
root_volume_type = "gp2" | ||
} | ||
|
||
s3_bucket = "${module.kubernetes.s3_bucket}" | ||
ssh_key = "${aws_key_pair.ssh_key.key_name}" | ||
|
||
extra_tags = "${merge(map( | ||
"Phase", "${local.phase}", | ||
"Project", "${local.project}", | ||
), var.extra_tags)}" | ||
} |
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,29 @@ | ||
variable "aws_region" { | ||
type = "string" | ||
default = "ap-southeast-1" | ||
description = "(Optional) The AWS region" | ||
} | ||
|
||
variable "service_cidr" { | ||
type = "string" | ||
default = "172.16.0.0/13" | ||
description = "(Optional) The Kubernetes service CIDR." | ||
} | ||
|
||
variable "cluster_cidr" { | ||
type = "string" | ||
default = "172.24.0.0/13" | ||
description = "(Optional) The Kubernetes cluster CIDR." | ||
} | ||
|
||
variable "extra_tags" { | ||
type = "map" | ||
default = {} | ||
description = "Extra AWS tags to be applied to created resources." | ||
} | ||
|
||
variable "auth_webhook_path" { | ||
type = "string" | ||
default = "/etc/kubernetes/aws-iam-authenticator" | ||
description = "(Optional) A path for using customize machine to authenticate to a Kubernetes cluster." | ||
} |
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 @@ | ||
locals { | ||
filesystem = "root" | ||
mode = 0644 | ||
} |
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 @@ | ||
output "systemd_units" { | ||
value = [ | ||
"${data.ignition_systemd_unit.provision.id}", | ||
] | ||
} | ||
|
||
output "files" { | ||
value = [ | ||
"${data.ignition_file.kubeconfig.id}", | ||
] | ||
} | ||
|
||
output "kubeconfig_path" { | ||
value = "${var.webhook_kubeconfig_path}" | ||
} |
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,23 @@ | ||
data "template_file" "provision" { | ||
template = "${file("${path.module}/resources/services/provision.service")}" | ||
|
||
vars { | ||
api_server_secret_path = "${local.api_server_secret_path}" | ||
api_server_secret_key_path = "${local.api_server_secret_path}/apiserver.key" | ||
api_server_secret_crt_path = "${local.api_server_secret_path}/apiserver.crt" | ||
|
||
state_path = "${var.state_path}" | ||
state_key_path = "${var.state_path}/key.pem" | ||
state_crt_path = "${var.state_path}/cert.pem" | ||
} | ||
} | ||
|
||
data "ignition_systemd_unit" "provision" { | ||
name = "vault-provision.service" | ||
enabled = true | ||
content = "${data.template_file.provision.rendered}" | ||
} | ||
|
||
locals { | ||
api_server_secret_path = "/etc/kubernetes/secrets" | ||
} |
17 changes: 17 additions & 0 deletions
17
ignitions/aws-iam-authenticator/resources/kubernetes/webhook/kubeconfig
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,17 @@ | ||
# clusters refers to the remote service. | ||
clusters: | ||
- name: aws-iam-authenticator | ||
cluster: | ||
certificate-authority-data: ${webhook_ca} | ||
server: https://127.0.0.1:${webhook_server_port}/authenticate | ||
# users refers to the API Server's webhook configuration | ||
# (we don't need to authenticate the API server). | ||
users: | ||
- name: apiserver | ||
# kubeconfig files require a context. Provide one for the API Server. | ||
current-context: webhook | ||
contexts: | ||
- name: webhook | ||
context: | ||
cluster: aws-iam-authenticator | ||
user: apiserver |
20 changes: 20 additions & 0 deletions
20
ignitions/aws-iam-authenticator/resources/services/provision.service
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,20 @@ | ||
[Unit] | ||
Description = Systemd unit for provision iam-aws-authentication | ||
Before = kubelet | ||
After = network.target | ||
|
||
[Service] | ||
Type = oneshot | ||
RemainAfterExit = true | ||
|
||
User = root | ||
Group = root | ||
|
||
ExecStartPre = /usr/bin/mkdir -p ${state_path} | ||
|
||
ExecStart = /usr/bin/cp ${api_server_secret_key_path} ${state_key_path} | ||
ExecStart = /usr/bin/cp ${api_server_secret_crt_path} ${state_crt_path} | ||
|
||
[Install] | ||
WantedBy = multi-user.target | ||
RequiredBy = kubelet |
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,22 @@ | ||
variable "state_path" { | ||
type = "string" | ||
default = "/var/aws-iam-authenticator" | ||
description = "Persisted TLS certificate and keys." | ||
} | ||
|
||
variable "server_port" { | ||
default = 21362 | ||
description = "Localhost port where the server will serve the /authenticate endpoint" | ||
} | ||
|
||
variable "webhook_kubeconfig_path" { | ||
type = "string" | ||
default = "/etc/kubernetes/aws-iam-authenticator" | ||
description = "A path for using iam aws authenticator to authenticate to a Kubernetes cluster." | ||
} | ||
|
||
variable "webhook_kubeconfig_ca" { | ||
type = "string" | ||
default = "" | ||
description = "A certificate for verifying the remote service." | ||
} |
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,19 @@ | ||
data "template_file" "kubeconfig" { | ||
template = "${file("${path.module}/resources/kubernetes/webhook/kubeconfig")}" | ||
|
||
vars { | ||
webhook_ca = "${var.webhook_kubeconfig_ca}" | ||
webhook_server_port = "${var.server_port}" | ||
} | ||
} | ||
|
||
data "ignition_file" "kubeconfig" { | ||
filesystem = "${local.filesystem}" | ||
mode = "${local.mode}" | ||
|
||
path = "${pathexpand(var.webhook_kubeconfig_path)}/kubeconfig" | ||
|
||
content { | ||
content = "${data.template_file.kubeconfig.rendered}" | ||
} | ||
} |
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
Oops, something went wrong.