Skip to content

Commit

Permalink
Merge pull request #42 from SmartColumbusOS/smrt-216
Browse files Browse the repository at this point in the history
SMRT-216 Setup ELB and DNS for JupyterHub and rename variables
  • Loading branch information
JarredOlson authored Jul 11, 2018
2 parents 6b4d6f8 + e3e3916 commit 7e1340c
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ node('master') {

withCredentials([sshUserPrivateKey(credentialsId: "k8s-no-pass", keyFileVariable: 'keyfile')]) {
sh("mkdir -p ~/.kube/")
sh("mkdir -p /var/jenkins_home/.kube")
sh("echo '====> WAITING FOR KUBERNETES TO START... <===='")
retry(24) {
sleep(10)
Expand All @@ -51,9 +52,17 @@ node('master') {
sh("kubectl get nodes")
}
}

stage('Deploy Tiller') {
dir('env') {
sh("kubectl --namespace kube-system create serviceaccount tiller")
sh("kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller")
}
}
}
}

def copyKubeConfig(kubernetes_master_ip) {
sh("""scp -o ConnectTimeout=30 -o StrictHostKeyChecking=no -i $keyfile centos@${kubernetes_master_ip}:~/kubeconfig ~/.kube/config""")
}
sh("""scp -o ConnectTimeout=30 -o StrictHostKeyChecking=no -i $keyfile centos@${kubernetes_master_ip}:~/kubeconfig /var/jenkins_home/.kube/config""")
}
2 changes: 1 addition & 1 deletion alm/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "aws" {
region = "${var.region}"
region = "${var.region}"
profile = "${var.credentials_profile}"
}

Expand Down
44 changes: 43 additions & 1 deletion env/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module "vpc" {
}

resource "aws_route53_zone" "private" {
name = "${var.private_dns_zone_name}"
name = "${var.dns_zone_name}"
vpc_id = "${module.vpc.vpc_id}"
force_destroy = true

Expand Down Expand Up @@ -92,3 +92,45 @@ module "kubernetes" {
},
]
}

resource "aws_elb" "jupyter_elb" {
name = "jupyter-elb"

internal = true
subnets = ["${module.vpc.private_subnets}"]
security_groups = ["${module.kubernetes.kubeconfig_security_group}"]

listener {
instance_port = 30001
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}

health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "TCP:30001"
interval = 30
}
}

resource "aws_autoscaling_attachment" "jupyter_k8s_attachment" {
autoscaling_group_name = "${module.kubernetes.autoscaling_group_name}"
elb = "${aws_elb.jupyter_elb.id}"
}

resource "aws_route53_record" "jupyterhub_dns" {
zone_id = "${var.public_dns_zone_id}"
name = "jupyter.${var.dns_zone_name}"
type = "A"

count = 1

alias {
name = "${aws_elb.jupyter_elb.dns_name}"
zone_id = "${aws_elb.jupyter_elb.zone_id}"
evaluate_target_health = false
}
}
8 changes: 6 additions & 2 deletions env/main_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ variable "vpc_enable_dns_hostnames" {
default = true
}

variable "private_dns_zone_name" {
description = "Name of private DNS Route53 zone"
variable "dns_zone_name" {
description = "Name of public and private DNS Route53 zone"
}

variable "kubernetes_cluster_name" {
Expand All @@ -93,3 +93,7 @@ variable "kube_key" {
description = "The SSH key to use for kubernetes hosts"
default = "./k8_rsa.pub"
}

variable "public_dns_zone_id" {
description = "Public DNS Zone Id. This goes away after the public zone is terraformed."
}
4 changes: 3 additions & 1 deletion env/variables/dev.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environment = "dev"

vpc_name = "dev"

private_dns_zone_name = "dev.smartcolumbusos.com"
dns_zone_name = "dev.smartcolumbusos.com"

role_arn = "arn:aws:iam::073132350570:role/jenkins_role"

Expand All @@ -27,3 +27,5 @@ vpc_azs= ["us-east-2a","us-east-2b","us-east-2c"]
vpc_private_subnets = ["10.100.0.0/19", "10.100.64.0/19", "10.100.128.0/19"]

vpc_public_subnets = ["10.100.32.0/20", "10.100.96.0/20", "10.100.160.0/20"]

public_dns_zone_id = "Z25PZI6XYQF2OB"
4 changes: 3 additions & 1 deletion env/variables/prod.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environment = "prod"

vpc_name = "prod"

private_dns_zone_name = "smartcolumbus.com"
dns_zone_name = "smartcolumbus.com"

role_arn = "arn:aws:iam::374013108165:role/jenkins_role"

Expand All @@ -27,3 +27,5 @@ vpc_azs= ["us-east-2a","us-east-2b","us-east-2c"]
vpc_private_subnets = ["10.100.0.0/19", "10.100.64.0/19", "10.100.128.0/19"]

vpc_public_subnets = ["10.100.32.0/20", "10.100.96.0/20", "10.100.160.0/20"]

public_dns_zone_id = ""
4 changes: 3 additions & 1 deletion env/variables/sandbox.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vpc_single_nat_gateway = true

environment = "sandbox"

private_dns_zone_name = "sandbox.smartcolumbus.com"
dns_zone_name = "sandbox.smartcolumbus.com"

alm_account_id = "068920858268"

Expand All @@ -29,3 +29,5 @@ role_arn = "arn:aws:iam::068920858268:role/admin_role"
alm_role_arn = "arn:aws:iam::068920858268:role/admin_role"

kube_key = "~/.ssh/id_rsa.pub"

public_dns_zone_id = "Z8ERD8071HP70"
4 changes: 3 additions & 1 deletion env/variables/test.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environment = "test"

vpc_name = "test"

private_dns_zone_name = "test.smartcolumbus.com"
dns_zone_name = "test.smartcolumbus.com"

role_arn = "arn:aws:iam::647770347641:role/jenkins_role"

Expand All @@ -27,3 +27,5 @@ vpc_azs= ["us-east-2a","us-east-2b","us-east-2c"]
vpc_private_subnets = ["10.100.0.0/19", "10.100.64.0/19", "10.100.128.0/19"]

vpc_public_subnets = ["10.100.32.0/20", "10.100.96.0/20", "10.100.160.0/20"]

public_dns_zone_id = ""

0 comments on commit 7e1340c

Please sign in to comment.