├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── master.yaml.tpl ├── masters.tf ├── node.yaml.tpl ├── nodes.tf └── variables.tf /.gitignore: -------------------------------------------------------------------------------- 1 | terraform.tfstate 2 | terraform.tfstate.backup 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONEY: all 2 | 3 | all: 4 | true 5 | 6 | clean: 7 | rm -f variables.tf.json 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-aws-coreos-kubernetes-cluster 2 | 3 | Terraform module to help you rip off of the ideas found here: 4 | 5 | * https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/getting-started-guides/aws-coreos.md 6 | * http://awsadvent.tumblr.com/post/104260597799/aws-advent-2014-coreos-and-kubernetes-on-aws 7 | 8 | to build a simple kubernetes cluster on CoreOS, split across 2 AZs 9 | 10 | -------------------------------------------------------------------------------- /master.yaml.tpl: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | 3 | --- 4 | write-files: 5 | - path: /etc/conf.d/nfs 6 | permissions: '0644' 7 | content: | 8 | OPTS_RPC_MOUNTD="" 9 | - path: /opt/bin/wupiao 10 | permissions: '0755' 11 | content: | 12 | #!/bin/bash 13 | # [w]ait [u]ntil [p]ort [i]s [a]ctually [o]pen 14 | [ -n "$$1" ] && \ 15 | until curl -o /dev/null -sIf http://$${1}; do \ 16 | sleep 1 && echo .; 17 | done; 18 | exit $$? 19 | 20 | hostname: master 21 | coreos: 22 | etcd2: 23 | name: master 24 | listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001 25 | advertise-client-urls: http://$$private_ipv4:2379,http://$$private_ipv4:4001 26 | initial-cluster-token: k8s_etcd 27 | listen-peer-urls: http://$$private_ipv4:2380,http://$$private_ipv4:7001 28 | initial-advertise-peer-urls: http://$$private_ipv4:2380 29 | initial-cluster: master=http://$$private_ipv4:2380 30 | initial-cluster-state: new 31 | fleet: 32 | metadata: "role=master" 33 | units: 34 | - name: generate-serviceaccount-key.service 35 | command: start 36 | content: | 37 | [Unit] 38 | Description=Generate service-account key file 39 | 40 | [Service] 41 | ExecStartPre=-/usr/bin/mkdir -p /opt/bin 42 | ExecStart=/bin/openssl genrsa -out /opt/bin/kube-serviceaccount.key 2048 2>/dev/null 43 | RemainAfterExit=yes 44 | Type=oneshot 45 | - name: setup-network-environment.service 46 | command: start 47 | content: | 48 | [Unit] 49 | Description=Setup Network Environment 50 | Documentation=https://github.com/kelseyhightower/setup-network-environment 51 | Requires=network-online.target 52 | After=network-online.target 53 | 54 | [Service] 55 | ExecStartPre=-/usr/bin/mkdir -p /opt/bin 56 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/setup-network-environment -z /opt/bin/setup-network-environment https://github.com/kelseyhightower/setup-network-environment/releases/download/v1.0.0/setup-network-environment 57 | ExecStartPre=/usr/bin/chmod +x /opt/bin/setup-network-environment 58 | ExecStart=/opt/bin/setup-network-environment 59 | RemainAfterExit=yes 60 | Type=oneshot 61 | - name: fleet.service 62 | command: start 63 | - name: flanneld.service 64 | command: start 65 | drop-ins: 66 | - name: 50-network-config.conf 67 | content: | 68 | [Unit] 69 | Requires=etcd2.service 70 | [Service] 71 | ExecStartPre=/usr/bin/etcdctl set /coreos.com/network/config '{"Network": "${flanneld_cidr}", "Backend": {"Type": "vxlan"}}' 72 | - name: docker.service 73 | command: start 74 | drop-ins: 75 | - name: 60-wait-for-flannel-config.conf 76 | content: | 77 | [Unit] 78 | After=flanneld.service 79 | Requires=flanneld.service 80 | Restart=always 81 | Restart=on-failure 82 | - name: kube-apiserver.service 83 | command: start 84 | content: | 85 | [Unit] 86 | Description=Kubernetes API Server 87 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 88 | Requires=setup-network-environment.service etcd2.service generate-serviceaccount-key.service 89 | After=setup-network-environment.service etcd2.service generate-serviceaccount-key.service 90 | 91 | [Service] 92 | EnvironmentFile=/etc/network-environment 93 | ExecStartPre=-/usr/bin/mkdir -p /opt/bin 94 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/kube-apiserver -z /opt/bin/kube-apiserver https://storage.googleapis.com/kubernetes-release/release/${kubernetes_release}/bin/linux/amd64/kube-apiserver 95 | ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-apiserver 96 | ExecStartPre=/opt/bin/wupiao 127.0.0.1:2379/v2/machines 97 | ExecStart=/opt/bin/kube-apiserver \ 98 | --service_account_key_file=/opt/bin/kube-serviceaccount.key \ 99 | --service_account_lookup=false \ 100 | --admission_control=NamespaceLifecycle,NamespaceAutoProvision,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota \ 101 | --runtime_config=api/v1 \ 102 | --allow_privileged=true \ 103 | --insecure_bind_address=0.0.0.0 \ 104 | --insecure_port=8080 \ 105 | --kubelet_https=true \ 106 | --secure_port=6443 \ 107 | --service-cluster-ip-range=10.100.0.0/16 \ 108 | --etcd_servers=http://127.0.0.1:2379 \ 109 | --public_address_override=$${DEFAULT_IPV4} \ 110 | --logtostderr=true 111 | Restart=always 112 | RestartSec=10 113 | - name: kube-controller-manager.service 114 | command: start 115 | content: | 116 | [Unit] 117 | Description=Kubernetes Controller Manager 118 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 119 | Requires=kube-apiserver.service 120 | After=kube-apiserver.service 121 | 122 | [Service] 123 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/kube-controller-manager -z /opt/bin/kube-controller-manager https://storage.googleapis.com/kubernetes-release/release/${kubernetes_release}/bin/linux/amd64/kube-controller-manager 124 | ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-controller-manager 125 | ExecStart=/opt/bin/kube-controller-manager \ 126 | --service_account_private_key_file=/opt/bin/kube-serviceaccount.key \ 127 | --master=127.0.0.1:8080 \ 128 | --logtostderr=true 129 | Restart=always 130 | RestartSec=10 131 | - name: kube-scheduler.service 132 | command: start 133 | content: | 134 | [Unit] 135 | Description=Kubernetes Scheduler 136 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 137 | Requires=kube-apiserver.service 138 | After=kube-apiserver.service 139 | 140 | [Service] 141 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/kube-scheduler -z /opt/bin/kube-scheduler https://storage.googleapis.com/kubernetes-release/release/${kubernetes_release}/bin/linux/amd64/kube-scheduler 142 | ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-scheduler 143 | ExecStart=/opt/bin/kube-scheduler --master=127.0.0.1:8080 144 | Restart=always 145 | RestartSec=10 146 | update: 147 | group: alpha 148 | reboot-strategy: off 149 | -------------------------------------------------------------------------------- /masters.tf: -------------------------------------------------------------------------------- 1 | module "master_amitype" { 2 | source = "github.com/terraform-community-modules/tf_aws_virttype" 3 | instance_type = "${var.master-instance_type}" 4 | } 5 | 6 | module "master_ami" { 7 | source = "github.com/terraform-community-modules/tf_aws_coreos_ami" 8 | region = "${var.region}" 9 | channel = "${var.coreos-channel}" 10 | virttype = "${module.master_amitype.prefer_hvm}" 11 | } 12 | 13 | resource "template_file" "masters_cloud_init" { 14 | filename = "master.yaml.tpl" 15 | vars { 16 | kubernetes_release = "${var.kubernetes_release}" 17 | master_ip = "${aws_elb.kubernetes_master.dns_name}" 18 | flanneld_cidr = "${var.flanneld_cidr}" 19 | } 20 | } 21 | 22 | resource "aws_launch_configuration" "kubernetes-master" { 23 | image_id = "${module.master_ami.ami_id}" 24 | instance_type = "${var.master-instance_type}" 25 | security_groups = ["${var.sg}"] 26 | associate_public_ip_address = true 27 | user_data = "${template_file.masters_cloud_init.rendered}" 28 | key_name = "${var.admin_key_name}" 29 | lifecycle { 30 | create_before_destroy = true 31 | } 32 | } 33 | 34 | resource "aws_autoscaling_group" "kubernetes-master" { 35 | availability_zones = ["${var.primary-az}", "${var.secondary-az}"] 36 | name = "kubernetes-master" 37 | max_size = "${var.master-cluster-size}" 38 | min_size = "${var.master-cluster-size}" 39 | desired_capacity = "${var.master-cluster-size}" 40 | health_check_grace_period = 60 41 | health_check_type = "EC2" 42 | force_delete = true 43 | load_balancers = [ 44 | "${aws_elb.kubernetes_master.id}", 45 | "${aws_elb.kubernetes_master_public.id}" 46 | ] 47 | launch_configuration = "${aws_launch_configuration.kubernetes-master.name}" 48 | vpc_zone_identifier = [ "${var.primary-az-subnet}", "${var.secondary-az-subnet}" ] 49 | tag { 50 | key = "Name" 51 | value = "kubernetes-master" 52 | propagate_at_launch = true 53 | } 54 | } 55 | 56 | resource "aws_elb" "kubernetes_master" { 57 | name = "kubernetes-master" 58 | subnets = [ "${var.primary-az-subnet}", "${var.secondary-az-subnet}" ] 59 | cross_zone_load_balancing = true 60 | security_groups = ["${var.sg}"] 61 | internal = true 62 | 63 | health_check { 64 | healthy_threshold = 2 65 | unhealthy_threshold = 2 66 | timeout = 3 67 | target = "HTTP:8080/" 68 | interval = 30 69 | } 70 | 71 | listener { 72 | instance_port = 2379 73 | instance_protocol = "http" 74 | lb_port = 2379 75 | lb_protocol = "http" 76 | } 77 | 78 | listener { 79 | instance_port = 2380 80 | instance_protocol = "http" 81 | lb_port = 2380 82 | lb_protocol = "http" 83 | } 84 | 85 | listener { 86 | instance_port = 4001 87 | instance_protocol = "http" 88 | lb_port = 4001 89 | lb_protocol = "http" 90 | } 91 | 92 | listener { 93 | instance_port = 8080 94 | instance_protocol = "http" 95 | lb_port = 8080 96 | lb_protocol = "http" 97 | } 98 | } 99 | 100 | resource "aws_elb" "kubernetes_master_public" { 101 | name = "kubernetes-master-public" 102 | subnets = [ "${var.primary-az-subnet}", "${var.secondary-az-subnet}" ] 103 | cross_zone_load_balancing = true 104 | security_groups = ["${var.sg}"] 105 | 106 | health_check { 107 | healthy_threshold = 2 108 | unhealthy_threshold = 2 109 | timeout = 3 110 | target = "HTTP:8080/" 111 | interval = 30 112 | } 113 | 114 | listener { 115 | instance_port = 8080 116 | instance_protocol = "http" 117 | lb_port = 80 118 | lb_protocol = "http" 119 | } 120 | } 121 | 122 | output "public_url" { 123 | value = "http://${aws_elb.kubernetes_master_public.dns_name}" 124 | } 125 | -------------------------------------------------------------------------------- /node.yaml.tpl: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | write-files: 3 | - path: /opt/bin/wupiao 4 | permissions: '0755' 5 | content: | 6 | #!/bin/bash 7 | # [w]ait [u]ntil [p]ort [i]s [a]ctually [o]pen 8 | [ -n "$$1" ] && [ -n "$$2" ] && while ! curl --output /dev/null \ 9 | --silent --head --fail \ 10 | http://$${1}:$${2}; do sleep 1 && echo -n .; done; 11 | exit $$? 12 | coreos: 13 | etcd2: 14 | listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001 15 | advertise-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001 16 | initial-cluster: master=http://${master_ip}:2380 17 | proxy: on 18 | fleet: 19 | metadata: "role=node" 20 | units: 21 | - name: fleet.service 22 | command: start 23 | - name: flanneld.service 24 | command: start 25 | drop-ins: 26 | - name: 50-network-config.conf 27 | content: | 28 | [Unit] 29 | Requires=etcd2.service 30 | [Service] 31 | ExecStartPre=/usr/bin/etcdctl set /coreos.com/network/config '{"Network": "${flanneld_cidr}", "Backend": {"Type": "vxlan"}}' 32 | - name: docker.service 33 | command: start 34 | drop-ins: 35 | - name: 60-wait-for-flannel-config.conf 36 | content: | 37 | [Unit] 38 | After=flanneld.service 39 | Requires=flanneld.service 40 | Restart=always 41 | Restart=on-failure 42 | - name: setup-network-environment.service 43 | command: start 44 | content: | 45 | [Unit] 46 | Description=Setup Network Environment 47 | Documentation=https://github.com/kelseyhightower/setup-network-environment 48 | Requires=network-online.target 49 | After=network-online.target 50 | 51 | [Service] 52 | ExecStartPre=-/usr/bin/mkdir -p /opt/bin 53 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/setup-network-environment -z /opt/bin/setup-network-environment https://github.com/kelseyhightower/setup-network-environment/releases/download/v1.0.0/setup-network-environment 54 | ExecStartPre=/usr/bin/chmod +x /opt/bin/setup-network-environment 55 | ExecStart=/opt/bin/setup-network-environment 56 | RemainAfterExit=yes 57 | Type=oneshot 58 | - name: kube-proxy.service 59 | command: start 60 | content: | 61 | [Unit] 62 | Description=Kubernetes Proxy 63 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 64 | Requires=setup-network-environment.service 65 | After=setup-network-environment.service 66 | 67 | [Service] 68 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/kube-proxy -z /opt/bin/kube-proxy https://storage.googleapis.com/kubernetes-release/release/${kubernetes_release}/bin/linux/amd64/kube-proxy 69 | ExecStartPre=/usr/bin/chmod +x /opt/bin/kube-proxy 70 | # wait for kubernetes master to be up and ready 71 | ExecStartPre=/opt/bin/wupiao ${master_ip} 8080 72 | ExecStart=/opt/bin/kube-proxy \ 73 | --master=http://${master_ip}:8080 \ 74 | --logtostderr=true 75 | Restart=always 76 | RestartSec=10 77 | - name: kube-kubelet.service 78 | command: start 79 | content: | 80 | [Unit] 81 | Description=Kubernetes Kubelet 82 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 83 | Requires=setup-network-environment.service 84 | After=setup-network-environment.service 85 | 86 | [Service] 87 | EnvironmentFile=/etc/network-environment 88 | ExecStartPre=/usr/bin/curl -L -o /opt/bin/kubelet -z /opt/bin/kubelet https://storage.googleapis.com/kubernetes-release/release/${kubernetes_release}/bin/linux/amd64/kubelet 89 | ExecStartPre=/usr/bin/chmod +x /opt/bin/kubelet 90 | # wait for kubernetes master to be up and ready 91 | ExecStartPre=/opt/bin/wupiao ${master_ip} 8080 92 | ExecStart=/opt/bin/kubelet \ 93 | --address=0.0.0.0 \ 94 | --port=10250 \ 95 | --hostname_override=$${DEFAULT_IPV4} \ 96 | --api_servers=http://${master_ip}:8080 \ 97 | --allow_privileged=true \ 98 | --logtostderr=true \ 99 | --cadvisor_port=4194 \ 100 | --healthz_bind_address=0.0.0.0 \ 101 | --healthz_port=10248 102 | Restart=always 103 | RestartSec=10 104 | update: 105 | group: alpha 106 | reboot-strategy: off 107 | -------------------------------------------------------------------------------- /nodes.tf: -------------------------------------------------------------------------------- 1 | module "node_amitype" { 2 | source = "github.com/terraform-community-modules/tf_aws_virttype" 3 | instance_type = "${var.node-instance_type}" 4 | } 5 | 6 | module "node_ami" { 7 | source = "github.com/terraform-community-modules/tf_aws_coreos_ami" 8 | region = "${var.region}" 9 | channel = "${var.coreos-channel}" 10 | virttype = "${module.node_amitype.prefer_hvm}" 11 | } 12 | 13 | resource "template_file" "nodes_cloud_init" { 14 | filename = "node.yaml.tpl" 15 | vars { 16 | kubernetes_release = "${var.kubernetes_release}" 17 | master_ip = "${aws_elb.kubernetes_master.dns_name}" 18 | flanneld_cidr = "${var.flanneld_cidr}" 19 | } 20 | } 21 | 22 | resource "aws_launch_configuration" "kubernetes-node" { 23 | image_id = "${module.node_ami.ami_id}" 24 | instance_type = "${var.node-instance_type}" 25 | security_groups = ["${var.sg}"] 26 | associate_public_ip_address = true 27 | user_data = "${template_file.nodes_cloud_init.rendered}" 28 | key_name = "${var.admin_key_name}" 29 | lifecycle { 30 | create_before_destroy = true 31 | } 32 | } 33 | 34 | resource "aws_autoscaling_group" "kubernetes-node" { 35 | availability_zones = ["${var.primary-az}", "${var.secondary-az}"] 36 | name = "kubernetes-node" 37 | max_size = "${var.node-cluster-size}" 38 | min_size = "${var.node-cluster-size}" 39 | desired_capacity = "${var.node-cluster-size}" 40 | health_check_grace_period = 60 41 | health_check_type = "EC2" 42 | force_delete = true 43 | launch_configuration = "${aws_launch_configuration.kubernetes-node.name}" 44 | vpc_zone_identifier = [ "${var.primary-az-subnet}", "${var.secondary-az-subnet}" ] 45 | tag { 46 | key = "Name" 47 | value = "kubernetes-node" 48 | propagate_at_launch = true 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "etcd_discovery_uri" {} 2 | variable "admin_key_name" {} 3 | variable "sg" {} 4 | variable "region" {} 5 | variable "coreos-channel" { 6 | default = "stable" 7 | } 8 | variable "kubernetes_release" { 9 | default = "v1.0.6" 10 | } 11 | variable "primary-az" {} 12 | variable "secondary-az" {} 13 | variable "primary-az-subnet" {} 14 | variable "secondary-az-subnet" {} 15 | variable "master-cluster-size" { 16 | default = 1 17 | } 18 | variable "node-cluster-size" { 19 | default = 3 20 | } 21 | variable "master-instance_type" { 22 | default = "t2.small" 23 | } 24 | variable "node-instance_type" { 25 | default = "m3.large" 26 | } 27 | variable "flanneld_cidr" { 28 | default = "10.244.0.0/24" 29 | } 30 | --------------------------------------------------------------------------------