Skip to content

Commit 10c7d2d

Browse files
author
Shubhra Kar
authored
Merge pull request #29 from fayazg/gcm-cns
lb on cluster managers and affinity config
2 parents 9f29eb8 + 17c42d0 commit 10c7d2d

File tree

7 files changed

+97
-14
lines changed

7 files changed

+97
-14
lines changed

template_clustermanager.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ name=global-cluster
1010
## Should the cluster manager run in HA mode
1111
## Running in HA mode will start two node cluster manager with a database node
1212
ha=true
13+
## How many cluster manager nodes should this GCM set up (HA)
14+
gcm_node_count=2
15+
1316
## Comma separated names of triton networks to use
1417
## Cluster managers will have to be reachable by environment nodes
1518
networks=Joyent-SDC-Public,Joyent-SDC-Private

terraform/create-rancher-env.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ module "gcp_example" {
137137
k8s_plane_isolation = "required"
138138

139139
gcp_path_to_credentials = "/path/to/creds.json"
140-
gcp_project_id = "k8s-test-187102"
140+
gcp_project_id = "k8s-test-187102"
141141

142142
gcp_compute_region = "us-west1"
143-
gcp_instance_zone = "us-west1-a"
143+
gcp_instance_zone = "us-west1-a"
144144

145-
etcd_gcp_instance_type = "n1-standard-1"
145+
etcd_gcp_instance_type = "n1-standard-1"
146146
orchestration_gcp_instance_type = "n1-standard-1"
147-
compute_gcp_instance_type = "n1-standard-1"
147+
compute_gcp_instance_type = "n1-standard-1"
148148

149149
# rancher_registry = "docker-registry.joyent.com:5000"
150150
# rancher_registry_username = "username"

terraform/create-rancher.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module "create_rancher-example" {
2121
master_triton_machine_package = "k4-highcpu-kvm-1.75G"
2222
mysqldb_triton_machine_package = "k4-highcpu-kvm-1.75G"
2323
ha = true
24+
gcm_node_count = "2"
2425

2526
# rancher_server_image = "docker-registry.joyent.com:5000/rancher/server:v1.6.10"
2627
# rancher_agent_image = "docker-registry.joyent.com:5000/rancher/agent:v1.2.6"

terraform/modules/triton-rancher-k8s/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ resource "triton_machine" "etcd_host" {
109109
user_script = "${element(data.template_file.install_rancher_agent_etcd.*.rendered, count.index)}"
110110

111111
networks = ["${data.triton_network.networks.*.id}"]
112+
113+
cns = {
114+
services = ["etcd.${var.name}"]
115+
}
116+
117+
affinity = ["role!=~etcd"]
118+
119+
tags = {
120+
role = "etcd"
121+
}
112122
}
113123

114124
resource "rancher_registration_token" "orchestration" {
@@ -147,6 +157,16 @@ resource "triton_machine" "orchestration_host" {
147157
user_script = "${element(data.template_file.install_rancher_agent_orchestration.*.rendered, count.index)}"
148158

149159
networks = ["${data.triton_network.networks.*.id}"]
160+
161+
cns = {
162+
services = ["orchestration.${var.name}"]
163+
}
164+
165+
affinity = ["role!=~orchestration"]
166+
167+
tags = {
168+
role = "orchestration"
169+
}
150170
}
151171

152172
resource "rancher_registration_token" "compute" {

terraform/modules/triton-rancher/main.tf

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "triton_machine" "rancher_mysqldb" {
4848
}
4949

5050
provisioner "remote-exec" {
51-
inline = <<EOF
51+
inline = <<-EOF
5252
${data.template_file.install_rancher_mysqldb.rendered}
5353
EOF
5454
}
@@ -79,7 +79,7 @@ data "template_file" "install_rancher_master" {
7979
}
8080

8181
resource "triton_machine" "rancher_master" {
82-
count = "${1 + var.ha}"
82+
count = "${var.gcm_node_count}"
8383

8484
package = "${var.master_triton_machine_package}"
8585
image = "${data.triton_image.image.id}"
@@ -88,6 +88,16 @@ resource "triton_machine" "rancher_master" {
8888
user_script = "${data.template_file.install_rancher_master.rendered}"
8989

9090
networks = ["${data.triton_network.networks.*.id}"]
91+
92+
cns = {
93+
services = ["${var.name}"]
94+
}
95+
96+
affinity = ["role!=~gcm"]
97+
98+
tags = {
99+
role = "gcm"
100+
}
91101
}
92102

93103
data "template_file" "setup_rancher_k8s" {

terraform/modules/triton-rancher/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ variable "ha" {
7575
description = "Should Rancher be deployed in HA, if true a mysqldb node and 2 Rancher master nodes will be created."
7676
}
7777

78+
variable "gcm_node_count" {
79+
default = "1"
80+
description = "Number of Global Cluster Managers to cluster."
81+
}
82+
7883
variable "mysqldb_triton_machine_package" {
7984
default = ""
8085
description = "The Triton machine package to use for the Rancher mysqldb node. Defaults to master_triton_machine_package."

triton-kubernetes.sh

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,13 @@ getClusterManagerConfig() {
284284
# _mysqldb_triton_machine_package
285285
# _name
286286
# _ha
287+
# _gcm_node_count
287288
_name="$(getArgument "Name your Global Cluster Manager" "global-cluster")"
288289
_ha="$(getVerification "Do you want to set up the Global Cluster Manager in HA mode")"
290+
if [ "$_ha" == "true" ]
291+
then
292+
_gcm_node_count="$(getArgument "Number of cluster manager nodes for $_name Global Cluster Manager" "2")"
293+
fi
289294
echo "From below options:"
290295
echo "Joyent-SDC-Public"
291296
echo "Joyent-SDC-Private"
@@ -625,7 +630,12 @@ readConfig() {
625630
then
626631
docker_engine_install_url=${line//docker_engine_install_url=/}
627632
echo "docker-engine Install Script: $docker_engine_install_url"
633+
elif echo "$line" | grep -q ^gcm_node_count=
634+
then
635+
_gcm_node_count=${line//gcm_node_count=/}
636+
echo "Number of cluster manager Nodes: $_gcm_node_count"
628637
fi
638+
629639
if [ "$_ha" == "true" ]
630640
then
631641
_etcd_node_count=3
@@ -653,7 +663,12 @@ setModuleClusterManager() {
653663
rancher_registry_username_line="rancher_registry_username = \"${rancher_registry_username}\""
654664
rancher_registry_password_line="rancher_registry_password = \"${rancher_registry_password}\""
655665
fi
656-
666+
667+
if [ "$_ha" == "false" ]
668+
then
669+
_gcm_node_count="1"
670+
fi
671+
657672
cd terraform
658673
cat >>create-rancher.tf <<-EOF
659674
@@ -674,6 +689,7 @@ setModuleClusterManager() {
674689
master_triton_machine_package = "${_master_triton_machine_package}"
675690
mysqldb_triton_machine_package = "${_mysqldb_triton_machine_package}"
676691
ha = ${_ha}
692+
gcm_node_count = ${_gcm_node_count}
677693
678694
${rancher_server_image_line}
679695
${rancher_agent_image_line}
@@ -1027,8 +1043,17 @@ showClusterDetails() {
10271043
else
10281044
echo "This is a non-HA setup so there is only one cluster manager node."
10291045
fi
1046+
1047+
local __MasterCNS __name
1048+
__name=$_name
1049+
__MasterCNS=$(triton instance get "${__name}-master-1" 2>&1 | jq '.dns_names' 2>&1 | grep "${__name}.svc.*.triton.zone" | tr -d '"' | tr -d ' ' | tr -d ',' || true)
1050+
if [ "$__MasterCNS" ]
1051+
then
1052+
echo " http://${__MasterCNS}:8080/"
1053+
else
1054+
echo " http://${__MasterIP}:8080/"
1055+
fi
10301056
cat <<-EOM
1031-
http://${__MasterIP}:8080/settings/env
10321057
10331058
Next step is adding Kubernetes environments to be managed here.
10341059
To start your first environment, run:
@@ -1047,13 +1072,32 @@ showEnvironmentDetails() {
10471072
else
10481073
echo "This is a non-HA setup so Kubernetes services could run on any of the compute nodes."
10491074
fi
1075+
1076+
local __MasterCNS __name
1077+
__name=$(triton ls -l 2>&1 | grep "$__MasterIP" | awk '{print $2}' 2>&1 | sed 's/-master-1//g' || true)
1078+
__MasterCNS=$(triton instance get "${__name}-master-1" 2>&1 | jq '.dns_names' 2>&1 | grep "${__name}.svc.*.triton.zone" | tr -d '"' | tr -d ' ' | tr -d ',' || true)
1079+
if [ "$__MasterCNS" ]
1080+
then
1081+
cat <<-EOM
1082+
Cluster Manager URL:
1083+
http://${__MasterCNS}:8080/settings/env
1084+
Kubernetes Hosts URL:
1085+
http://${__MasterCNS}:8080/env/$($TERRAFORM output -state=terraform/terraform.tfstate -module="${_name}" -json | jq '.environment_id.value' | tr -d '"')/infra/hosts?mode=dot
1086+
Kubernetes Health:
1087+
http://${__MasterCNS}:8080/env/$($TERRAFORM output -state=terraform/terraform.tfstate -module="${_name}" -json | jq '.environment_id.value' | tr -d '"')/apps/stacks?which=cattle
1088+
EOM
1089+
else
1090+
cat <<-EOM
1091+
Cluster Manager URL:
1092+
http://${__MasterIP}:8080/settings/env
1093+
Kubernetes Hosts URL:
1094+
http://${__MasterIP}:8080/env/$($TERRAFORM output -state=terraform/terraform.tfstate -module="${_name}" -json | jq '.environment_id.value' | tr -d '"')/infra/hosts?mode=dot
1095+
Kubernetes Health:
1096+
http://${__MasterIP}:8080/env/$($TERRAFORM output -state=terraform/terraform.tfstate -module="${_name}" -json | jq '.environment_id.value' | tr -d '"')/apps/stacks?which=cattle
1097+
EOM
1098+
fi
1099+
10501100
cat <<-EOM
1051-
Cluster Manager URL:
1052-
http://${__MasterIP}:8080/settings/env
1053-
Kubernetes Hosts URL:
1054-
http://${__MasterIP}:8080/env/$($TERRAFORM output -state=terraform/terraform.tfstate -module="${_name}" -json | jq '.environment_id.value' | tr -d '"')/infra/hosts?mode=dot
1055-
Kubernetes Health:
1056-
http://${__MasterIP}:8080/env/$($TERRAFORM output -state=terraform/terraform.tfstate -module="${_name}" -json | jq '.environment_id.value' | tr -d '"')/apps/stacks?which=cattle
10571101
10581102
NOTE: Nodes might take a few minutes to connect and come up.
10591103

0 commit comments

Comments
 (0)