├── .gitattributes ├── .gitignore ├── .swp ├── LICENSE ├── README.md ├── Vagrantfile ├── artifacts ├── .gitkeep └── tls │ └── .gitkeep ├── manifests ├── master-apiserver-rbac.yaml ├── master-apiserver.yaml ├── master-controller-manager.yaml ├── master-proxy.yaml ├── master-scheduler.yaml └── node-proxy.yaml ├── master.yaml ├── node.yaml ├── plugins ├── calico │ ├── calico-rbac.yaml │ └── calico.yaml.tmpl ├── coredns │ ├── coredns.yaml.sed │ └── deploy.sh └── dashboard │ ├── dashboard-rbac.yaml │ └── dashboard.yaml ├── setup.tmpl ├── synced_folders.yaml ├── temp └── .gitkeep └── tls ├── make-certs-master-rbac.sh ├── make-certs-master.sh ├── make-certs-node.sh ├── master-kubeconfig.yaml ├── node-kubeconfig.yaml ├── openssl-master.cnf.tmpl └── openssl-node.cnf.tmpl /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | # Force LF line ending on these files 4 | * eol=lf 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | .dockercfg 3 | .editorconfig 4 | .ruby-gemset 5 | .ruby-version 6 | temp/* 7 | synced_folders.yaml 8 | artifacts/* 9 | -------------------------------------------------------------------------------- /.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pires/kubernetes-vagrant-coreos-cluster/56ebbaa2a972d5412c99324259a7208318d9d9df/.swp -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kubernetes-vagrant-coreos-cluster 2 | Turnkey **[Kubernetes](https://github.com/GoogleCloudPlatform/kubernetes)** 3 | cluster setup with **[Vagrant 2.1.1+](https://www.vagrantup.com)** and 4 | **[CoreOS](https://coreos.com)**. 5 | 6 | If you're lazy, or in a hurry, jump to the [TL;DR](#tldr) section. 7 | 8 | ## Pre-requisites 9 | 10 | * **[Vagrant 2.1.1+](https://www.vagrantup.com)** 11 | * a supported Vagrant hypervisor: 12 | * **[Virtualbox](https://www.virtualbox.org)** (the default) 13 | * **[Parallels Desktop](http://www.parallels.com/eu/products/desktop/)** 14 | * **[VMware Fusion](http://www.vmware.com/products/fusion)** or **[VMware Workstation](http://www.vmware.com/products/workstation)** 15 | 16 | ### MacOS X 17 | 18 | On **MacOS X** (and assuming you have [homebrew](http://brew.sh) already installed) run 19 | 20 | ``` 21 | brew install wget 22 | ``` 23 | 24 | ### Windows 25 | 26 | - The [vagrant-winnfsd plugin](https://github.com/GM-Alex/vagrant-winnfsd) will be installed in order to enable NFS shares. 27 | - The project will run some bash script under the VirtualMachines. These scripts line ending need to be in LF. Git for windows set `core.autocrlf true` by default at the installation time. When you clone this project repository, this parameter (set to true) ask git to change all line ending to CRLF. This behavior need to be changed before cloning the repository (or after for each files by hand). We recommand to turn this to off by running `git config --global core.autocrlf false` and `git config --global core.eol lf` before cloning. Then, after cloning, do not forget to turn the behavior back if you want to run other windows projects: `git config --global core.autocrlf true` and `git config --global core.eol crlf`. 28 | 29 | ## Deploy Kubernetes 30 | 31 | Current ```Vagrantfile``` will bootstrap one VM with everything needed to become a Kubernetes _master_ and, by default, a couple VMs with everything needed to become Kubernetes worker nodes. 32 | You can change the number of worker nodes and/or the Kubernetes version by setting environment variables **NODES** and **KUBERNETES_VERSION**, respectively. [You can find more details below](#customization). 33 | 34 | ``` 35 | vagrant up 36 | ``` 37 | 38 | ### Linux or MacOS host 39 | 40 | Kubernetes cluster is ready. Use `kubectl` to manage it. 41 | 42 | ### Windows host 43 | 44 | On Windows systems, `kubectl` is installed on the `master` node, in the ```/opt/bin``` directory. To manage your Kubernetes cluster, `ssh` into the `master` node and run `kubectl` from there. 45 | 46 | ``` 47 | vagrant ssh master 48 | kubectl cluster-info 49 | ``` 50 | 51 | ## Clean-up 52 | 53 | ``` 54 | vagrant destroy 55 | ``` 56 | 57 | If you've set `NODES` or any other variable when deploying, please make sure you set it in `vagrant destroy` call above, like: 58 | 59 | ``` 60 | NODES=3 vagrant destroy -f 61 | ``` 62 | 63 | ## Notes about hypervisors 64 | 65 | ### Virtualbox 66 | 67 | **VirtualBox** is the default hypervisor, and you'll probably need to disable its DHCP server 68 | ``` 69 | VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0 70 | ``` 71 | 72 | ### Parallels 73 | 74 | If you are using **Parallels Desktop**, you need to install **[vagrant-parallels](http://parallels.github.io/vagrant-parallels/docs/)** provider 75 | ``` 76 | vagrant plugin install vagrant-parallels 77 | ``` 78 | Then just add ```--provider parallels``` to the ```vagrant up``` invocations above. 79 | 80 | ### VMware 81 | If you are using one of the **VMware** hypervisors you must **[buy](http://www.vagrantup.com/vmware)** the matching provider and, depending on your case, just add either ```--provider vmware_fusion``` or ```--provider vmware_workstation``` to the ```vagrant up``` invocations above. 82 | 83 | ## Private Docker Repositories 84 | 85 | If you want to use Docker private repositories look for **DOCKERCFG** bellow. 86 | 87 | ## Customization 88 | ### Environment variables 89 | Most aspects of your cluster setup can be customized with environment variables. Right now the available ones are: 90 | - **HTTP_PROXY** sets http proxy address. 91 | 92 | Defaults to **$HTTP_PROXY of host machine if it exists**. 93 | 94 | You need customing this proxy setting on VMs when you have to face gfw with tools like shadowsocks, privoxy on host machine, because Vagrantfile uses proxy setting on host machine default,this setting might be not right to VMs, it would lead to internet disconnection of VMs. If you have the problem, you can refer to https://www.linuxbabe.com/virtualbox/how-to-access-host-services-from-a-virtualbox-guest-os for customing this setting. 95 | 96 | - **HTTPS_PROXY** 97 | 98 | like **HTTP_PROXY** 99 | 100 | - **NO_PROXY** 101 | 102 | like **HTTP_PROXY** 103 | - **NODES** sets the number of nodes (workers). 104 | 105 | Defaults to **2**. 106 | - **CHANNEL** sets the default CoreOS channel to be used in the VMs. 107 | 108 | Defaults to **alpha**. 109 | 110 | While by convenience, we allow an user to optionally consume CoreOS' *beta* or *stable* channels please do note that as both Kubernetes and CoreOS are quickly evolving platforms we only expect our setup to behave reliably on top of CoreOS' _alpha_ channel. 111 | So, **before submitting a bug**, either in [this](https://github.com/pires/kubernetes-vagrant-coreos-cluster/issues) project, or in ([Kubernetes](https://github.com/GoogleCloudPlatform/kubernetes/issues) or [CoreOS](https://github.com/coreos/bugs/issues)) **make sure it** (also) **happens in the** (default) **_alpha_ channel** :smile: 112 | - **COREOS_VERSION** will set the specific CoreOS release (from the given channel) to be used. 113 | 114 | Default is to use whatever is the **latest** one from the given channel. 115 | - **SERIAL_LOGGING** if set to *true* will allow logging from the VMs' serial console. 116 | 117 | Defaults to **false**. Only use this if you *really* know what you are doing. 118 | - **MASTER_MEM** sets the master node VM memory. 119 | 120 | Defaults to **1024** (in MB) 121 | - **MASTER_CPUS** sets the number of vCPUs to be used by the master VM. 122 | 123 | Defaults to **2**. 124 | - **NODE_MEM** sets the worker nodes VM memory. 125 | 126 | Defaults to **2048** (in MB) 127 | - **NODE_CPUS** sets the number of vCPUs to be used by node VMs. 128 | 129 | Defaults to **2**. 130 | - **DOCKERCFG** sets the location of your private docker repositories (and keys) configuration. However, this is only usable if you set **USE_DOCKERCFG=true**. 131 | 132 | Defaults to "**~/.dockercfg**". 133 | 134 | You can create/update a *~/.dockercfg* file at any time 135 | by running `docker login .`. All nodes will get it automatically, 136 | at 'vagrant up', given any modification or update to that file. 137 | 138 | - **DOCKER_OPTIONS** sets the additional `DOCKER_OPTS` for docker service on both master and the nodes. Useful for adding params such as `--insecure-registry`. 139 | 140 | - **KUBERNETES_VERSION** defines the specific kubernetes version being used. 141 | 142 | Defaults to `1.10.9`. 143 | Versions prior to `1.10.0` **may not work** with current cloud-configs and Kubernetes descriptors. 144 | 145 | - **USE_KUBE_UI** defines whether to deploy or not the Kubernetes UI 146 | 147 | Defaults to `false`. 148 | 149 | - **AUTHORIZATION_MODE** setting this to `RBAC` enables RBAC for the kubernetes cluster. 150 | 151 | Defaults to `AlwaysAllow`. 152 | 153 | - **CLUSTER_CIDR** defines the CIDR to be used for pod networking. This CIDR must not overlap with `10.100.0.0/16`. 154 | 155 | Defaults to `10.244.0.0/16`. 156 | 157 | So, in order to start, say, a Kubernetes cluster with 3 worker nodes, 4GB of RAM and 4 vCPUs per node one just would run: 158 | 159 | ``` 160 | NODE_MEM=4096 NODE_CPUS=4 NODES=3 vagrant up 161 | ``` 162 | 163 | or with Kubernetes UI: 164 | 165 | ``` 166 | NODE_MEM=4096 NODE_CPUS=4 NODES=3 USE_KUBE_UI=true vagrant up 167 | ``` 168 | 169 | **Please do note** that if you were using non default settings to startup your 170 | cluster you *must* also use those exact settings when invoking 171 | `vagrant {up,ssh,status,destroy}` to communicate with any of the nodes in the cluster as otherwise 172 | things may not behave as you'd expect. 173 | 174 | ### Synced Folders 175 | You can automatically mount in your *guest* VMs, at startup, an arbitrary 176 | number of local folders in your host machine by populating accordingly the 177 | `synced_folders.yaml` file in your `Vagrantfile` directory. For each folder 178 | you which to mount the allowed syntax is... 179 | 180 | ```yaml 181 | # the 'id' of this mount point. needs to be unique. 182 | - name: foobar 183 | # the host source directory to share with the guest(s). 184 | source: /foo 185 | # the path to mount ${source} above on guest(s) 186 | destination: /bar 187 | # the mount type. only NFS makes sense as, presently, we are not shipping 188 | # hypervisor specific guest tools. defaults to `true`. 189 | nfs: true 190 | # additional options to pass to the mount command on the guest(s) 191 | # if not set the Vagrant NFS defaults will be used. 192 | mount_options: 'nolock,vers=3,udp,noatime' 193 | # if the mount is enabled or disabled by default. default is `true`. 194 | disabled: false 195 | ``` 196 | 197 | **ATTENTION:** Don't remove `/vagrant` entry. 198 | 199 | ## TL;DR 200 | 201 | ``` 202 | vagrant up 203 | ``` 204 | 205 | This will start one `master` and two `worker` nodes, download Kubernetes binaries start all needed services. 206 | A Docker mirror cache will be provisioned in the `master`, to speed up container provisioning. This can take some time depending on your Internet connection speed. 207 | 208 | Please do note that, at any time, you can change the number of `worker` nodes by setting the `NODES` value in subsequent `vagrant up` invocations. 209 | 210 | ### Usage 211 | 212 | Congratulations! You're now ready to use your Kubernetes cluster. 213 | 214 | If you just want to test something simple, start with [Kubernetes examples] 215 | (https://github.com/GoogleCloudPlatform/kubernetes/blob/master/examples/). 216 | 217 | For a more elaborate scenario [here] 218 | (https://github.com/pires/kubernetes-elasticsearch-cluster) you'll find all 219 | you need to get a scalable Elasticsearch cluster on top of Kubernetes in no 220 | time. 221 | 222 | ## Troubleshooting 223 | 224 | #### Vagrant displays a warning message when running! 225 | 226 | Vagrant 2.1 integrated support for triggers as a core functionality. However, 227 | this change is not compatible with the 228 | [`vagrant-triggers`](https://github.com/emyl/vagrant-triggers) community plugin 229 | we were and still are using. Since we require this plugin, Vagrant will show the 230 | following warning: 231 | 232 | ``` 233 | WARNING: Vagrant has detected the `vagrant-triggers` plugin. This plugin conflicts 234 | with the internal triggers implementation. Please uninstall the `vagrant-triggers` 235 | plugin and run the command again if you wish to use the core trigger feature. To 236 | uninstall the plugin, run the command shown below: 237 | 238 | vagrant plugin uninstall vagrant-triggers 239 | 240 | Note that the community plugin `vagrant-triggers` and the core trigger feature 241 | in Vagrant do not have compatible syntax. 242 | 243 | To disable this warning, set the environment variable `VAGRANT_USE_VAGRANT_TRIGGERS`. 244 | ``` 245 | 246 | This warning is harmless and only means that we are using the community plugin 247 | instead of the core functionality. To disable it, set the 248 | `VAGRANT_USE_VAGRANT_TRIGGERS` environment variable to `false` before running 249 | `vagrant`: 250 | 251 | ``` 252 | $ VAGRANT_USE_VAGRANT_TRIGGERS=false NODES=2 vagrant up 253 | ``` 254 | 255 | #### I'm getting errors while waiting for Kubernetes master to become ready on a MacOS host! 256 | 257 | If you see something like this in the log: 258 | ``` 259 | ==> master: Waiting for Kubernetes master to become ready... 260 | error: unable to load file "temp/dns-controller.yaml": unable to connect to a server to handle "replicationcontrollers": couldn't read version from server: Get https://10.245.1.2/api: dial tcp 10.245.1.2:443: i/o timeout 261 | error: no objects passed to create 262 | ``` 263 | You probably have a pre-existing Kubernetes config file on your system at `~/.kube/config`. Delete or move that file and try again. 264 | 265 | #### I'm getting errors while waiting for mounting to /vagrant on a CentOS 7 host! 266 | 267 | If you see something like this in the log: 268 | ``` 269 | mount.nfs: Connection timed out. 270 | ``` 271 | It might be caused by firewall, you can check if firewall is active with 'systemctl status firewalld', if yes, you can use 'systemctl stop firewalld' simply. 272 | 273 | #### Kubernetes Dashboard asks for either a Kubeconfig or token! 274 | 275 | This behavior is expected in latest versions of the Kubernetes Dashboard, since 276 | different people may need to use the Kubernetes Dashboard with different 277 | permissions. Since we deploy a service account with 278 | [administrative privileges](https://github.com/kubernetes/dashboard/wiki/Access-control#admin-privileges) 279 | you should just click _Skip_. Everything will work as expected. 280 | 281 | ## Licensing 282 | 283 | This work is [open source](http://opensource.org/osd), and is licensed under the [Apache License, Version 2.0](http://opensource.org/licenses/Apache-2.0). 284 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | require "fileutils" 5 | require "net/http" 6 | require "open-uri" 7 | require "json" 8 | require "date" 9 | require "pathname" 10 | 11 | class Module 12 | def redefine_const(name, value) 13 | __send__(:remove_const, name) if const_defined?(name) 14 | const_set(name, value) 15 | end 16 | end 17 | 18 | module OS 19 | def OS.windows? 20 | (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil 21 | end 22 | 23 | def OS.mac? 24 | (/darwin/ =~ RUBY_PLATFORM) != nil 25 | end 26 | 27 | def OS.unix? 28 | !OS.windows? 29 | end 30 | 31 | def OS.linux? 32 | OS.unix? and not OS.mac? 33 | end 34 | end 35 | 36 | required_plugins = %w(vagrant-triggers) 37 | 38 | # check either 'http_proxy' or 'HTTP_PROXY' environment variable 39 | enable_proxy = !(ENV["HTTP_PROXY"] || ENV["http_proxy"] || "").empty? 40 | if enable_proxy 41 | required_plugins.push("vagrant-proxyconf") 42 | end 43 | 44 | if OS.windows? 45 | required_plugins.push("vagrant-winnfsd") 46 | end 47 | 48 | required_plugins.push("vagrant-timezone") 49 | 50 | required_plugins.each do |plugin| 51 | need_restart = false 52 | unless Vagrant.has_plugin? plugin 53 | system("vagrant plugin install #{plugin}", :chdir=>"/tmp") || exit! 54 | need_restart = true 55 | end 56 | exec "vagrant #{ARGV.join(" ")}" if need_restart 57 | end 58 | 59 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 60 | VAGRANTFILE_API_VERSION = "2" 61 | Vagrant.require_version ">= 2.1.1" 62 | 63 | MASTER_YAML = File.join(File.dirname(__FILE__), "master.yaml") 64 | NODE_YAML = File.join(File.dirname(__FILE__), "node.yaml") 65 | 66 | # AUTHORIZATION MODE is a setting for enabling or disabling RBAC for your Kubernetes Cluster 67 | # The default mode is ABAC. 68 | AUTHORIZATION_MODE = ENV["AUTHORIZATION_MODE"] || "AlwaysAllow" 69 | 70 | if AUTHORIZATION_MODE == "RBAC" 71 | CERTS_MASTER_SCRIPT = File.join(File.dirname(__FILE__), "tls/make-certs-master-rbac.sh") 72 | else 73 | CERTS_MASTER_SCRIPT = File.join(File.dirname(__FILE__), "tls/make-certs-master.sh") 74 | end 75 | 76 | CERTS_MASTER_CONF = File.join(File.dirname(__FILE__), "tls/openssl-master.cnf.tmpl") 77 | CERTS_NODE_SCRIPT = File.join(File.dirname(__FILE__), "tls/make-certs-node.sh") 78 | CERTS_NODE_CONF = File.join(File.dirname(__FILE__), "tls/openssl-node.cnf.tmpl") 79 | 80 | MANIFESTS_DIR = Pathname.getwd().join("manifests") 81 | 82 | USE_DOCKERCFG = ENV["USE_DOCKERCFG"] || false 83 | DOCKERCFG = File.expand_path(ENV["DOCKERCFG"] || "~/.dockercfg") 84 | 85 | DOCKER_OPTIONS = ENV["DOCKER_OPTIONS"] || "" 86 | 87 | KUBERNETES_VERSION = ENV["KUBERNETES_VERSION"] || "1.10.9" 88 | 89 | CHANNEL = ENV["CHANNEL"] || "alpha" 90 | 91 | #if CHANNEL != 'alpha' 92 | # puts "=============================================================================" 93 | # puts "As this is a fastly evolving technology CoreOS' alpha channel is the only one" 94 | # puts "expected to behave reliably. While one can invoke the beta or stable channels" 95 | # puts "please be aware that your mileage may vary a whole lot." 96 | # puts "So, before submitting a bug, in this project, or upstreams (either kubernetes" 97 | # puts "or CoreOS) please make sure it (also) happens in the (default) alpha channel." 98 | # puts "=============================================================================" 99 | #end 100 | 101 | COREOS_VERSION = ENV["COREOS_VERSION"] || "latest" 102 | upstream = "http://#{CHANNEL}.release.core-os.net/amd64-usr/#{COREOS_VERSION}" 103 | if COREOS_VERSION == "latest" 104 | upstream = "http://#{CHANNEL}.release.core-os.net/amd64-usr/current" 105 | url = "#{upstream}/version.txt" 106 | Object.redefine_const(:COREOS_VERSION, 107 | open(url).read().scan(/COREOS_VERSION=.*/)[0].gsub("COREOS_VERSION=", "")) 108 | end 109 | 110 | NODES = ENV["NODES"] || 2 111 | 112 | MASTER_MEM = ENV["MASTER_MEM"] || 1024 113 | MASTER_CPUS = ENV["MASTER_CPUS"] || 2 114 | 115 | NODE_MEM = ENV["NODE_MEM"] || 2048 116 | NODE_CPUS = ENV["NODE_CPUS"] || 2 117 | 118 | BASE_IP_ADDR = ENV["BASE_IP_ADDR"] || "172.17.8" 119 | 120 | DNS_DOMAIN = ENV["DNS_DOMAIN"] || "cluster.local" 121 | 122 | SERIAL_LOGGING = (ENV["SERIAL_LOGGING"].to_s.downcase == "true") 123 | GUI = (ENV["GUI"].to_s.downcase == "true") 124 | USE_KUBE_UI = (ENV["USE_KUBE_UI"].to_s.downcase == "true") || false 125 | 126 | BOX_TIMEOUT_COUNT = (ENV["BOX_TIMEOUT_COUNT"] || 50).to_i 127 | 128 | if enable_proxy 129 | HTTP_PROXY = ENV["HTTP_PROXY"] || ENV["http_proxy"] 130 | HTTPS_PROXY = ENV["HTTPS_PROXY"] || ENV["https_proxy"] 131 | NO_PROXY = ENV["NO_PROXY"] || ENV["no_proxy"] || "localhost" 132 | end 133 | 134 | REMOVE_VAGRANTFILE_USER_DATA_BEFORE_HALT = (ENV["REMOVE_VAGRANTFILE_USER_DATA_BEFORE_HALT"].to_s.downcase == "true") 135 | # if this is set true, remember to use --provision when executing vagrant up / reload 136 | 137 | # Read YAML file with mountpoint details 138 | MOUNT_POINTS = YAML::load_file(File.join(File.dirname(__FILE__), "synced_folders.yaml")) 139 | 140 | # CLUSTER_CIDR is the CIDR used for pod networking 141 | CLUSTER_CIDR = ENV["CLUSTER_CIDR"] || "10.244.0.0/16" 142 | 143 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 144 | # always use host timezone in VMs 145 | config.timezone.value = :host 146 | 147 | # always use Vagrants' insecure key 148 | config.ssh.insert_key = false 149 | config.ssh.forward_agent = true 150 | 151 | config.vm.box = "coreos-#{CHANNEL}" 152 | config.vm.box_version = "= #{COREOS_VERSION}" 153 | config.vm.box_url = "#{upstream}/coreos_production_vagrant.json" 154 | 155 | ["vmware_fusion", "vmware_workstation"].each do |vmware| 156 | config.vm.provider vmware do |v, override| 157 | override.vm.box_url = "#{upstream}/coreos_production_vagrant_vmware_fusion.json" 158 | end 159 | end 160 | 161 | config.vm.provider :parallels do |vb, override| 162 | override.vm.box = "AntonioMeireles/coreos-#{CHANNEL}" 163 | override.vm.box_url = "https://vagrantcloud.com/AntonioMeireles/coreos-#{CHANNEL}" 164 | end 165 | 166 | config.vm.provider :virtualbox do |v| 167 | # On VirtualBox, we don't have guest additions or a functional vboxsf 168 | # in CoreOS, so tell Vagrant that so it can be smarter. 169 | v.check_guest_additions = false 170 | v.functional_vboxsf = false 171 | v.customize ["modifyvm", :id, "--paravirtprovider", "kvm"] 172 | end 173 | config.vm.provider :parallels do |p| 174 | p.update_guest_tools = false 175 | p.check_guest_tools = false 176 | end 177 | 178 | # plugin conflict 179 | if Vagrant.has_plugin?("vagrant-vbguest") 180 | config.vbguest.auto_update = false 181 | end 182 | 183 | # setup VM proxy to system proxy environment 184 | if Vagrant.has_plugin?("vagrant-proxyconf") && enable_proxy 185 | config.proxy.http = HTTP_PROXY 186 | config.proxy.https = HTTPS_PROXY 187 | # most http tools, like wget and curl do not undestand IP range 188 | # thus adding each node one by one to no_proxy 189 | no_proxies = NO_PROXY.split(",") 190 | (1..(NODES.to_i + 1)).each do |i| 191 | vm_ip_addr = "#{BASE_IP_ADDR}.#{i + 100}" 192 | Object.redefine_const(:NO_PROXY, 193 | "#{NO_PROXY},#{vm_ip_addr}") unless no_proxies.include?(vm_ip_addr) 194 | end 195 | config.proxy.no_proxy = NO_PROXY 196 | # proxyconf plugin use wrong approach to set Docker proxy for CoreOS 197 | # force proxyconf to skip Docker proxy setup 198 | config.proxy.enabled = {docker: false} 199 | end 200 | 201 | (1..(NODES.to_i + 1)).each do |i| 202 | if i == 1 203 | hostname = "master" 204 | ETCD_SEED_CLUSTER = "#{hostname}=http://#{BASE_IP_ADDR}.#{i + 100}:2380" 205 | cfg = MASTER_YAML 206 | memory = MASTER_MEM 207 | cpus = MASTER_CPUS 208 | MASTER_IP = "#{BASE_IP_ADDR}.#{i + 100}" 209 | else 210 | hostname = "node-%02d" % (i - 1) 211 | cfg = NODE_YAML 212 | memory = NODE_MEM 213 | cpus = NODE_CPUS 214 | end 215 | 216 | config.vm.define vmName = hostname do |kHost| 217 | kHost.vm.hostname = vmName 218 | 219 | # suspend / resume is hard to be properly supported because we have no way 220 | # to assure the fully deterministic behavior of whatever is inside the VMs 221 | # when faced with XXL clock gaps... so we just disable this functionality. 222 | kHost.trigger.reject [:suspend, :resume] do 223 | info "'vagrant suspend' and 'vagrant resume' are disabled." 224 | info "- please do use 'vagrant halt' and 'vagrant up' instead." 225 | end 226 | 227 | config.trigger.instead_of :reload do 228 | exec "vagrant halt && vagrant up" 229 | exit 230 | end 231 | 232 | # vagrant-triggers has no concept of global triggers so to avoid having 233 | # then to run as many times as the total number of VMs we only call them 234 | # in the master (re: emyl/vagrant-triggers#13)... 235 | if vmName == "master" 236 | kHost.trigger.before [:up, :provision] do 237 | info "#{Time.now}: setting up Kubernetes master..." 238 | info "Setting Kubernetes version #{KUBERNETES_VERSION}" 239 | 240 | # create setup file 241 | setupFile = "#{__dir__}/temp/setup" 242 | # find and replace kubernetes version and master IP in setup file 243 | setupData = File.read("setup.tmpl") 244 | setupData = setupData.gsub("__KUBERNETES_VERSION__", KUBERNETES_VERSION) 245 | setupData = setupData.gsub("__MASTER_IP__", MASTER_IP) 246 | if enable_proxy 247 | # remove __PROXY_LINE__ flag and set __NO_PROXY__ 248 | setupData = setupData.gsub("__PROXY_LINE__", "") 249 | setupData = setupData.gsub("__NO_PROXY__", NO_PROXY) 250 | else 251 | # remove lines that start with __PROXY_LINE__ 252 | setupData = setupData.gsub(/^\s*__PROXY_LINE__.*$\n/, "") 253 | end 254 | # write new setup data to setup file 255 | File.open(setupFile, "wb") do |f| 256 | f.write(setupData) 257 | end 258 | 259 | # give setup file executable permissions 260 | system "chmod +x temp/setup" 261 | 262 | system "#{__dir__}/plugins/coredns/deploy.sh 10.100.0.10/24 #{DNS_DOMAIN} #{__dir__}/plugins/coredns/coredns.yaml.sed > #{__dir__}/temp/coredns-deployment.yaml" 263 | 264 | # Replace __CLUSTER_CIDR__ in calico.yaml.tmpl with the value of CLUSTER_CIDR 265 | calicoTmpl = File.read("#{__dir__}/plugins/calico/calico.yaml.tmpl") 266 | calicoTmpl = calicoTmpl.gsub("__CLUSTER_CIDR__", CLUSTER_CIDR) 267 | File.open("#{__dir__}/temp/calico.yaml", "wb") do |f| 268 | f.write(calicoTmpl) 269 | end 270 | end 271 | 272 | kHost.trigger.after [:up, :resume] do 273 | unless OS.windows? 274 | info "Sanitizing stuff..." 275 | system "ssh-add ~/.vagrant.d/insecure_private_key" 276 | system "rm -rf ~/.fleetctl/known_hosts" 277 | end 278 | end 279 | 280 | kHost.trigger.after [:up] do 281 | info "Waiting for Kubernetes master to become ready..." 282 | j, uri, res = 0, URI("http://#{MASTER_IP}:8080"), nil 283 | loop do 284 | j += 1 285 | begin 286 | res = Net::HTTP.get_response(uri) 287 | rescue 288 | sleep 10 289 | end 290 | break if res.is_a? Net::HTTPSuccess or j >= BOX_TIMEOUT_COUNT 291 | end 292 | if res.is_a? Net::HTTPSuccess 293 | info "#{Time.now}: successfully deployed #{vmName}" 294 | else 295 | info "#{Time.now}: failed to deploy #{vmName} within timeout count of #{BOX_TIMEOUT_COUNT}" 296 | end 297 | 298 | info "Installing kubectl for the Kubernetes version we just bootstrapped..." 299 | if OS.windows? 300 | run_remote "sudo -u core /bin/sh /home/core/kubectlsetup install" 301 | else 302 | system "./temp/setup install" 303 | end 304 | 305 | # set cluster 306 | if OS.windows? 307 | run_remote "/opt/bin/kubectl config set-cluster default-cluster --server=https://#{MASTER_IP} --certificate-authority=/vagrant/artifacts/tls/ca.pem" 308 | run_remote "/opt/bin/kubectl config set-credentials default-admin --certificate-authority=/vagrant/artifacts/tls/ca.pem --client-key=/vagrant/artifacts/tls/admin-key.pem --client-certificate=/vagrant/artifacts/tls/admin.pem" 309 | run_remote "/opt/bin/kubectl config set-context local --cluster=default-cluster --user=default-admin" 310 | run_remote "/opt/bin/kubectl config use-context local" 311 | else 312 | system "kubectl config set-cluster default-cluster --server=https://#{MASTER_IP} --certificate-authority=artifacts/tls/ca.pem" 313 | system "kubectl config set-credentials default-admin --certificate-authority=artifacts/tls/ca.pem --client-key=artifacts/tls/admin-key.pem --client-certificate=artifacts/tls/admin.pem" 314 | system "kubectl config set-context local --cluster=default-cluster --user=default-admin" 315 | system "kubectl config use-context local" 316 | end 317 | 318 | info "Configuring Calico..." 319 | 320 | # Install Calico 321 | if OS.windows? 322 | if AUTHORIZATION_MODE == "RBAC" 323 | run_remote "/opt/bin/kubectl apply -f /home/core/calico-rbac.yaml" 324 | end 325 | run_remote "/opt/bin/kubectl apply -f /home/core/calico.yaml" 326 | else 327 | if AUTHORIZATION_MODE == "RBAC" 328 | system "kubectl apply -f plugins/calico/calico-rbac.yaml" 329 | end 330 | system "kubectl apply -f temp/calico.yaml" 331 | end 332 | 333 | info "Configuring Kubernetes DNS..." 334 | 335 | res, uri.path = nil, "/api/v1/namespaces/kube-system/deployment/coredns" 336 | begin 337 | res = Net::HTTP.get_response(uri) 338 | rescue 339 | end 340 | if not res.is_a? Net::HTTPSuccess 341 | if OS.windows? 342 | run_remote "/opt/bin/kubectl create -f /home/core/coredns-deployment.yaml" 343 | else 344 | system "kubectl create -f temp/coredns-deployment.yaml" 345 | end 346 | end 347 | 348 | if USE_KUBE_UI 349 | info "Configuring Kubernetes Dashboard..." 350 | 351 | if OS.windows? 352 | run_remote "/opt/bin/kubectl apply -f /home/core/dashboard.yaml" 353 | if AUTHORIZATION_MODE == "RBAC" 354 | run_remote "/opt/bin/kubectl apply -f /home/core/dashboard-rbac.yaml" 355 | end 356 | else 357 | system "kubectl apply -f plugins/dashboard/dashboard.yaml" 358 | if AUTHORIZATION_MODE == "RBAC" 359 | system "kubectl apply -f plugins/dashboard/dashboard-rbac.yaml" 360 | end 361 | end 362 | 363 | info "Kubernetes Dashboard will be available at http://#{MASTER_IP}:8080/ui/" 364 | end 365 | end 366 | 367 | # copy setup files to master vm if host is windows 368 | if OS.windows? 369 | kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "temp/setup"), :destination => "/home/core/kubectlsetup" 370 | 371 | kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "plugins/calico/calico-rbac.yaml"), :destination => "/home/core/calico-rbac.yaml" 372 | kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "temp/calico.yaml"), :destination => "/home/core/calico.yaml" 373 | 374 | kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "temp/coredns-deployment.yaml"), :destination => "/home/core/coredns-deployment.yaml" 375 | 376 | if USE_KUBE_UI 377 | kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "plugins/dashboard/dashboard-rbac.yaml"), :destination => "/home/core/dashboard-rbac.yaml" 378 | kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "plugins/dashboard/dashboard.yaml"), :destination => "/home/core/dashboard.yaml" 379 | end 380 | end 381 | 382 | # clean temp directory after master is destroyed 383 | kHost.trigger.after [:destroy] do 384 | FileUtils.rm_rf(Dir.glob("#{__dir__}/temp/*")) 385 | FileUtils.rm_rf(Dir.glob("#{__dir__}/artifacts/tls/*")) 386 | end 387 | end 388 | 389 | if vmName == "node-%02d" % (i - 1) 390 | kHost.trigger.before [:up, :provision] do 391 | info "#{Time.now}: setting up node..." 392 | end 393 | 394 | kHost.trigger.after [:up] do 395 | info "Waiting for Kubernetes worker [node-%02d" % (i - 1) + "] to become ready..." 396 | j, uri, hasResponse = 0, URI("http://#{BASE_IP_ADDR}.#{i + 100}:10250"), false 397 | loop do 398 | j += 1 399 | begin 400 | res = Net::HTTP.get_response(uri) 401 | hasResponse = true 402 | rescue Net::HTTPBadResponse 403 | hasResponse = true 404 | rescue 405 | sleep 10 406 | end 407 | break if hasResponse or j >= BOX_TIMEOUT_COUNT 408 | end 409 | if hasResponse 410 | info "#{Time.now}: successfully deployed #{vmName}" 411 | else 412 | info "#{Time.now}: failed to deploy #{vmName} within timeout count of #{BOX_TIMEOUT_COUNT}" 413 | end 414 | end 415 | end 416 | 417 | kHost.trigger.before [:halt, :reload] do 418 | if REMOVE_VAGRANTFILE_USER_DATA_BEFORE_HALT 419 | run_remote "sudo rm -f /var/lib/coreos-vagrant/vagrantfile-user-data" 420 | end 421 | end 422 | 423 | if SERIAL_LOGGING 424 | logdir = File.join(File.dirname(__FILE__), "log") 425 | FileUtils.mkdir_p(logdir) 426 | 427 | serialFile = File.join(logdir, "#{vmName}-serial.txt") 428 | FileUtils.touch(serialFile) 429 | 430 | ["vmware_fusion", "vmware_workstation"].each do |vmware| 431 | kHost.vm.provider vmware do |v, override| 432 | v.vmx["serial0.present"] = "TRUE" 433 | v.vmx["serial0.fileType"] = "file" 434 | v.vmx["serial0.fileName"] = serialFile 435 | v.vmx["serial0.tryNoRxLoss"] = "FALSE" 436 | end 437 | end 438 | kHost.vm.provider :virtualbox do |vb, override| 439 | vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"] 440 | vb.customize ["modifyvm", :id, "--uartmode1", serialFile] 441 | end 442 | # supported since vagrant-parallels 1.3.7 443 | # https://github.com/Parallels/vagrant-parallels/issues/164 444 | kHost.vm.provider :parallels do |v| 445 | v.customize("post-import", 446 | ["set", :id, "--device-add", "serial", "--output", serialFile]) 447 | v.customize("pre-boot", 448 | ["set", :id, "--device-set", "serial0", "--output", serialFile]) 449 | end 450 | end 451 | 452 | ["vmware_fusion", "vmware_workstation", "virtualbox"].each do |h| 453 | kHost.vm.provider h do |vb| 454 | vb.gui = GUI 455 | end 456 | end 457 | ["vmware_fusion", "vmware_workstation"].each do |h| 458 | kHost.vm.provider h do |v| 459 | v.vmx["memsize"] = memory 460 | v.vmx["numvcpus"] = cpus 461 | v.vmx["virtualHW.version"] = 10 462 | end 463 | end 464 | ["parallels", "virtualbox"].each do |h| 465 | kHost.vm.provider h do |n| 466 | n.memory = memory 467 | n.cpus = cpus 468 | end 469 | end 470 | 471 | kHost.vm.network :private_network, ip: "#{BASE_IP_ADDR}.#{i + 100}" 472 | 473 | # you can override this in synced_folders.yaml 474 | kHost.vm.synced_folder ".", "/vagrant", disabled: true 475 | 476 | begin 477 | MOUNT_POINTS.each do |mount| 478 | mount_options = "" 479 | disabled = false 480 | nfs = true 481 | if mount["mount_options"] 482 | mount_options = mount["mount_options"] 483 | end 484 | if mount["disabled"] 485 | disabled = mount["disabled"] 486 | end 487 | if mount["nfs"] 488 | nfs = mount["nfs"] 489 | end 490 | if File.exist?(File.expand_path("#{mount["source"]}")) 491 | if mount["destination"] 492 | kHost.vm.synced_folder "#{mount["source"]}", "#{mount["destination"]}", 493 | id: "#{mount["name"]}", 494 | disabled: disabled, 495 | mount_options: ["#{mount_options}"], 496 | nfs: nfs 497 | end 498 | end 499 | end 500 | rescue 501 | end 502 | 503 | if USE_DOCKERCFG && File.exist?(DOCKERCFG) 504 | kHost.vm.provision :file, run: "always", 505 | :source => "#{DOCKERCFG}", :destination => "/home/core/.dockercfg" 506 | 507 | kHost.vm.provision :shell, run: "always" do |s| 508 | s.inline = "cp /home/core/.dockercfg /root/.dockercfg" 509 | s.privileged = true 510 | end 511 | end 512 | 513 | # Copy TLS stuff 514 | if vmName == "master" 515 | kHost.vm.provision :file, :source => "#{CERTS_MASTER_SCRIPT}", :destination => "/tmp/make-certs.sh" 516 | kHost.vm.provision :file, :source => "#{CERTS_MASTER_CONF}", :destination => "/tmp/openssl.cnf" 517 | kHost.vm.provision :shell, :privileged => true, 518 | inline: <<-EOF 519 | sed -i"*" "s|__MASTER_IP__|#{MASTER_IP}|g" /tmp/openssl.cnf 520 | sed -i"*" "s|__DNS_DOMAIN__|#{DNS_DOMAIN}|g" /tmp/openssl.cnf 521 | EOF 522 | kHost.vm.provision :shell, run: "always" do |s| 523 | s.inline = "mkdir -p /etc/kubernetes && cp -R /vagrant/tls/master-kubeconfig.yaml /etc/kubernetes/master-kubeconfig.yaml" 524 | s.privileged = true 525 | end 526 | else 527 | kHost.vm.provision :file, :source => "#{CERTS_NODE_SCRIPT}", :destination => "/tmp/make-certs.sh" 528 | kHost.vm.provision :file, :source => "#{CERTS_NODE_CONF}", :destination => "/tmp/openssl.cnf" 529 | kHost.vm.provision :file, :source => "#{CERTS_NODE_CONF}", :destination => "/tmp/openssl.cnf" 530 | kHost.vm.provision :shell, run: "always" do |s| 531 | s.inline = "mkdir -p /etc/kubernetes && cp -R /vagrant/tls/node-kubeconfig.yaml /etc/kubernetes/node-kubeconfig.yaml" 532 | s.privileged = true 533 | end 534 | kHost.vm.provision :shell, :privileged => true, 535 | inline: <<-EOF 536 | sed -i"*" "s|__NODE_IP__|#{BASE_IP_ADDR}.#{i + 100}|g" /tmp/openssl.cnf 537 | sed -i"*" "s|__MASTER_IP__|#{MASTER_IP}|g" /etc/kubernetes/node-kubeconfig.yaml 538 | EOF 539 | end 540 | 541 | # Process Kubernetes manifests, depending on node type 542 | begin 543 | if vmName == "master" 544 | if AUTHORIZATION_MODE == "RBAC" 545 | kHost.vm.provision :shell, run: "always" do |s| 546 | s.inline = "mkdir -p /etc/kubernetes/manifests && find /vagrant/manifests/master* ! -name master-apiserver.yaml -exec cp -t /etc/kubernetes/manifests {} +" 547 | s.privileged = true 548 | end 549 | else 550 | kHost.vm.provision :shell, run: "always" do |s| 551 | s.inline = "mkdir -p /etc/kubernetes/manifests && cp -R /vagrant/manifests/master* /etc/kubernetes/manifests" 552 | s.privileged = true 553 | end 554 | end 555 | else 556 | kHost.vm.provision :shell, run: "always" do |s| 557 | s.inline = "mkdir -p /etc/kubernetes/manifests && cp -R /vagrant/manifests/node* /etc/kubernetes/manifests/" 558 | s.privileged = true 559 | end 560 | end 561 | kHost.vm.provision :shell, run: "always", :privileged => true, 562 | inline: <<-EOF 563 | sed -i"*" "s,__RELEASE__,v#{KUBERNETES_VERSION},g" /etc/kubernetes/manifests/*.yaml 564 | sed -i"*" "s|__MASTER_IP__|#{MASTER_IP}|g" /etc/kubernetes/manifests/*.yaml 565 | sed -i"*" "s|__DNS_DOMAIN__|#{DNS_DOMAIN}|g" /etc/kubernetes/manifests/*.yaml 566 | sed -i"*" "s|__CLUSTER_CIDR__|#{CLUSTER_CIDR}|g" /etc/kubernetes/manifests/*.yaml 567 | EOF 568 | end 569 | 570 | # Process vagrantfile 571 | if File.exist?(cfg) 572 | kHost.vm.provision :file, :source => "#{cfg}", :destination => "/tmp/vagrantfile-user-data" 573 | if enable_proxy 574 | kHost.vm.provision :shell, :privileged => true, 575 | inline: <<-EOF 576 | sed -i"*" "s|__PROXY_LINE__||g" /tmp/vagrantfile-user-data 577 | sed -i"*" "s|__HTTP_PROXY__|#{HTTP_PROXY}|g" /tmp/vagrantfile-user-data 578 | sed -i"*" "s|__HTTPS_PROXY__|#{HTTPS_PROXY}|g" /tmp/vagrantfile-user-data 579 | sed -i"*" "s|__NO_PROXY__|#{NO_PROXY}|g" /tmp/vagrantfile-user-data 580 | EOF 581 | end 582 | kHost.vm.provision :shell, :privileged => true, 583 | inline: <<-EOF 584 | sed -i"*" "/__PROXY_LINE__/d" /tmp/vagrantfile-user-data 585 | sed -i"*" "s,__DOCKER_OPTIONS__,#{DOCKER_OPTIONS},g" /tmp/vagrantfile-user-data 586 | sed -i"*" "s,__RELEASE__,v#{KUBERNETES_VERSION},g" /tmp/vagrantfile-user-data 587 | sed -i"*" "s,__CHANNEL__,#{CHANNEL},g" /tmp/vagrantfile-user-data 588 | sed -i"*" "s,__NAME__,#{hostname},g" /tmp/vagrantfile-user-data 589 | sed -i"*" "s|__MASTER_IP__|#{MASTER_IP}|g" /tmp/vagrantfile-user-data 590 | sed -i"*" "s|__DNS_DOMAIN__|#{DNS_DOMAIN}|g" /tmp/vagrantfile-user-data 591 | sed -i"*" "s|__ETCD_SEED_CLUSTER__|#{ETCD_SEED_CLUSTER}|g" /tmp/vagrantfile-user-data 592 | sed -i"*" "s|__CLUSTER_CIDR__|#{CLUSTER_CIDR}|g" /tmp/vagrantfile-user-data 593 | mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/ 594 | EOF 595 | end 596 | end 597 | end 598 | end 599 | -------------------------------------------------------------------------------- /artifacts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pires/kubernetes-vagrant-coreos-cluster/56ebbaa2a972d5412c99324259a7208318d9d9df/artifacts/.gitkeep -------------------------------------------------------------------------------- /artifacts/tls/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pires/kubernetes-vagrant-coreos-cluster/56ebbaa2a972d5412c99324259a7208318d9d9df/artifacts/tls/.gitkeep -------------------------------------------------------------------------------- /manifests/master-apiserver-rbac.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: kube-apiserver 5 | namespace: kube-system 6 | spec: 7 | hostNetwork: true 8 | containers: 9 | - name: kube-apiserver 10 | image: gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 11 | command: 12 | - /hyperkube 13 | - apiserver 14 | - --bind-address=0.0.0.0 15 | - --insecure-bind-address=0.0.0.0 16 | - --etcd-servers=http://127.0.0.1:2379 17 | - --allow-privileged=true 18 | - --anonymous-auth=false 19 | - --service-cluster-ip-range=10.100.0.0/16 20 | - --secure-port=443 21 | - --advertise-address=__MASTER_IP__ 22 | - --enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota 23 | - --tls-cert-file=/etc/kubernetes/ssl/apiserver.pem 24 | - --tls-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem 25 | - --client-ca-file=/etc/kubernetes/ssl/ca.pem 26 | - --service-account-key-file=/etc/kubernetes/ssl/apiserver-key.pem 27 | - --runtime-config=extensions/v1beta1=true,networking.k8s.io/v1,batch/v2alpha1=true,admissionregistration.k8s.io/v1alpha1=true 28 | - --authorization-mode=RBAC 29 | ports: 30 | - containerPort: 443 31 | hostPort: 443 32 | name: https 33 | - containerPort: 8080 34 | hostPort: 8080 35 | name: local 36 | volumeMounts: 37 | - mountPath: /etc/kubernetes/ssl 38 | name: ssl-certs-kubernetes 39 | readOnly: true 40 | - mountPath: /etc/ssl/certs 41 | name: ssl-certs-host 42 | readOnly: true 43 | volumes: 44 | - hostPath: 45 | path: /etc/kubernetes/ssl 46 | name: ssl-certs-kubernetes 47 | - hostPath: 48 | path: /usr/share/ca-certificates 49 | name: ssl-certs-host 50 | -------------------------------------------------------------------------------- /manifests/master-apiserver.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: kube-apiserver 5 | namespace: kube-system 6 | spec: 7 | hostNetwork: true 8 | containers: 9 | - name: kube-apiserver 10 | image: gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 11 | command: 12 | - /hyperkube 13 | - apiserver 14 | - --bind-address=0.0.0.0 15 | - --insecure-bind-address=0.0.0.0 16 | - --etcd-servers=http://127.0.0.1:2379 17 | - --allow-privileged=true 18 | - --anonymous-auth=false 19 | - --service-cluster-ip-range=10.100.0.0/16 20 | - --secure-port=443 21 | - --advertise-address=__MASTER_IP__ 22 | - --enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota 23 | - --tls-cert-file=/etc/kubernetes/ssl/apiserver.pem 24 | - --tls-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem 25 | - --client-ca-file=/etc/kubernetes/ssl/ca.pem 26 | - --service-account-key-file=/etc/kubernetes/ssl/apiserver-key.pem 27 | ports: 28 | - containerPort: 443 29 | hostPort: 443 30 | name: https 31 | - containerPort: 8080 32 | hostPort: 8080 33 | name: local 34 | volumeMounts: 35 | - mountPath: /etc/kubernetes/ssl 36 | name: ssl-certs-kubernetes 37 | readOnly: true 38 | - mountPath: /etc/ssl/certs 39 | name: ssl-certs-host 40 | readOnly: true 41 | volumes: 42 | - hostPath: 43 | path: /etc/kubernetes/ssl 44 | name: ssl-certs-kubernetes 45 | - hostPath: 46 | path: /usr/share/ca-certificates 47 | name: ssl-certs-host 48 | -------------------------------------------------------------------------------- /manifests/master-controller-manager.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: kube-controller-manager 5 | namespace: kube-system 6 | spec: 7 | hostNetwork: true 8 | containers: 9 | - name: kube-controller-manager 10 | image: gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 11 | command: 12 | - /hyperkube 13 | - controller-manager 14 | - --master=http://__MASTER_IP__:8080 15 | - --service-account-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem 16 | - --root-ca-file=/etc/kubernetes/ssl/ca.pem 17 | - --cluster-signing-cert-file=/etc/kubernetes/ssl/ca.pem 18 | - --cluster-signing-key-file=/etc/kubernetes/ssl/ca-key.pem 19 | - --cluster-cidr=__CLUSTER_CIDR__ 20 | - --allocate-node-cidrs=true 21 | livenessProbe: 22 | httpGet: 23 | host: 127.0.0.1 24 | path: /healthz 25 | port: 10252 26 | initialDelaySeconds: 15 27 | timeoutSeconds: 1 28 | volumeMounts: 29 | - mountPath: /etc/kubernetes/ssl 30 | name: ssl-certs-kubernetes 31 | readOnly: true 32 | - mountPath: /etc/ssl/certs 33 | name: ssl-certs-host 34 | readOnly: true 35 | volumes: 36 | - name: ssl-certs-kubernetes 37 | hostPath: 38 | path: /etc/kubernetes/ssl 39 | - name: ssl-certs-host 40 | hostPath: 41 | path: /usr/share/ca-certificates 42 | -------------------------------------------------------------------------------- /manifests/master-proxy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: kube-proxy 5 | namespace: kube-system 6 | spec: 7 | hostNetwork: true 8 | containers: 9 | - name: kube-proxy 10 | image: gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 11 | command: 12 | - /hyperkube 13 | - proxy 14 | - --master=http://__MASTER_IP__:8080 15 | - --proxy-mode=iptables 16 | - --cluster-cidr=__CLUSTER_CIDR__ 17 | securityContext: 18 | privileged: true 19 | volumeMounts: 20 | - mountPath: /etc/ssl/certs 21 | name: ssl-certs-host 22 | readOnly: true 23 | volumes: 24 | - name: ssl-certs-host 25 | hostPath: 26 | path: /usr/share/ca-certificates 27 | -------------------------------------------------------------------------------- /manifests/master-scheduler.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: kube-scheduler 5 | namespace: kube-system 6 | spec: 7 | hostNetwork: true 8 | containers: 9 | - name: kube-scheduler 10 | image: gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 11 | command: 12 | - /hyperkube 13 | - scheduler 14 | - --master=http://__MASTER_IP__:8080 15 | livenessProbe: 16 | httpGet: 17 | host: 127.0.0.1 18 | path: /healthz 19 | port: 10251 20 | initialDelaySeconds: 15 21 | timeoutSeconds: 1 -------------------------------------------------------------------------------- /manifests/node-proxy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: kube-proxy 5 | namespace: kube-system 6 | spec: 7 | hostNetwork: true 8 | containers: 9 | - name: kube-proxy 10 | image: gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 11 | command: 12 | - /hyperkube 13 | - proxy 14 | - --master=https://__MASTER_IP__:443 15 | - --kubeconfig=/etc/kubernetes/node-kubeconfig.yaml 16 | - --proxy-mode=iptables 17 | - --cluster-cidr=__CLUSTER_CIDR__ 18 | securityContext: 19 | privileged: true 20 | volumeMounts: 21 | - mountPath: /etc/ssl/certs 22 | name: "ssl-certs" 23 | - mountPath: /etc/kubernetes/node-kubeconfig.yaml 24 | name: "kubeconfig" 25 | readOnly: true 26 | - mountPath: /etc/kubernetes/ssl 27 | name: "etc-kube-ssl" 28 | readOnly: true 29 | volumes: 30 | - name: "ssl-certs" 31 | hostPath: 32 | path: "/usr/share/ca-certificates" 33 | - name: "kubeconfig" 34 | hostPath: 35 | path: "/etc/kubernetes/node-kubeconfig.yaml" 36 | - name: "etc-kube-ssl" 37 | hostPath: 38 | path: "/etc/kubernetes/ssl" 39 | -------------------------------------------------------------------------------- /master.yaml: -------------------------------------------------------------------------------- 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 | coreos: 21 | units: 22 | - name: rpcbind.service 23 | enable: true 24 | command: start 25 | - name: rpc-statd.service 26 | enable: true 27 | command: start 28 | - name: etcd-member.service 29 | command: start 30 | content: | 31 | [Unit] 32 | Description=etcd 33 | Documentation=https://github.com/coreos/etcd 34 | [Service] 35 | Environment='ETCD_IMAGE_TAG=v3.3.4' 36 | Environment='ETCD_DATA_DIR=/var/lib/etcd' 37 | Environment='ETCD_USER=etcd' 38 | Type=notify 39 | Restart=always 40 | RestartSec=5s 41 | LimitNOFILE=40000 42 | TimeoutStartSec=0 43 | ExecStart=/usr/lib/coreos/etcd-wrapper --name __NAME__ \ 44 | --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \ 45 | --advertise-client-urls http://$public_ipv4:2379,http://$public_ipv4:4001 \ 46 | --listen-peer-urls http://$private_ipv4:2380,http://$private_ipv4:7001 \ 47 | --initial-advertise-peer-urls http://$private_ipv4:2380 \ 48 | --initial-cluster __ETCD_SEED_CLUSTER__ 49 | [Install] 50 | WantedBy=multi-user.target 51 | - name: docker.service 52 | command: start 53 | drop-ins: 54 | - name: 51-docker-mirror.conf 55 | - __PROXY_LINE__name: http-proxy.conf 56 | __PROXY_LINE__content: | 57 | __PROXY_LINE__[Service] 58 | __PROXY_LINE__EnvironmentFile=/etc/environment 59 | - name: 50-docker-options.conf 60 | content: | 61 | [Service] 62 | Environment='DOCKER_OPTS=--storage-driver=overlay2 __DOCKER_OPTIONS__' 63 | - name: early-docker.service 64 | drop-ins: 65 | - __PROXY_LINE__name: http-proxy.conf 66 | __PROXY_LINE__content: | 67 | __PROXY_LINE__[Service] 68 | __PROXY_LINE__EnvironmentFile=/etc/environment 69 | - name: kube-certs.service 70 | command: start 71 | content: | 72 | [Unit] 73 | Description=Generate Kubernetes API Server certificates 74 | ConditionPathExists=/tmp/make-certs.sh 75 | Requires=network-online.target 76 | After=network-online.target 77 | [Service] 78 | ExecStartPre=-/usr/sbin/groupadd -r kube-cert 79 | ExecStartPre=/usr/bin/chmod 755 /tmp/make-certs.sh 80 | ExecStart=/tmp/make-certs.sh 81 | Type=oneshot 82 | RemainAfterExit=true 83 | - name: hyperkube-download.service 84 | command: start 85 | content: | 86 | [Unit] 87 | Description=Download Hyperkube Docker image 88 | Requires=docker.service 89 | After=docker.service 90 | ConditionPathExists=!/vagrant/artifacts/hyperkube___RELEASE__.tar 91 | [Service] 92 | ExecStart=/usr/bin/docker pull gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 93 | ExecStart=/usr/bin/docker save --output /vagrant/artifacts/hyperkube___RELEASE__.tar gcr.io/google_containers/hyperkube-amd64:__RELEASE__ 94 | Type=oneshot 95 | RemainAfterExit=true 96 | - name: hyperkube-import.service 97 | command: start 98 | content: | 99 | [Unit] 100 | Description=Import Hyperkube Docker image 101 | Requires=docker.service 102 | After=docker.service 103 | ConditionPathExists=/vagrant/artifacts/hyperkube___RELEASE__.tar 104 | [Service] 105 | ExecStart=/usr/bin/docker load --input /vagrant/artifacts/hyperkube___RELEASE__.tar 106 | Type=oneshot 107 | RemainAfterExit=true 108 | - name: kube-kubelet.service 109 | command: start 110 | content: | 111 | [Unit] 112 | Description=Kubernetes Kubelet 113 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 114 | Requires=kube-certs.service 115 | Wants=hyperkube-download.service hyperkube-import.service 116 | After=kube-certs.service hyperkube-download.service hyperkube-import.service 117 | [Service] 118 | ExecStartPre=/usr/bin/mkdir -p /etc/kubernetes/manifests 119 | ExecStartPre=-/usr/bin/docker rm -f kubelet 120 | ExecStart=/usr/bin/docker run \ 121 | --volume=/:/rootfs:ro \ 122 | --volume=/sys:/sys:ro \ 123 | --volume=/etc/cni/net.d:/etc/cni/net.d:rw \ 124 | --volume=/opt/cni/bin:/opt/cni/bin:rw \ 125 | --volume=/etc/kubernetes:/etc/kubernetes:ro \ 126 | --volume=/var/lib/calico/:/var/lib/calico:rw \ 127 | --volume=/var/lib/docker/:/var/lib/docker:rw \ 128 | --volume=/var/lib/kubelet/:/var/lib/kubelet:shared \ 129 | --volume=/var/run:/var/run:rw \ 130 | --net=host \ 131 | --pid=host \ 132 | --privileged=true \ 133 | --name=kubelet \ 134 | -d \ 135 | gcr.io/google_containers/hyperkube-amd64:__RELEASE__ \ 136 | /hyperkube kubelet \ 137 | --containerized \ 138 | --address=$private_ipv4 \ 139 | --register-schedulable=false \ 140 | --allow-privileged=true \ 141 | --pod-manifest-path=/etc/kubernetes/manifests \ 142 | --hostname-override=$public_ipv4 \ 143 | --cluster_dns=10.100.0.10 \ 144 | --cluster_domain=__DNS_DOMAIN__ \ 145 | --kubeconfig=/etc/kubernetes/master-kubeconfig.yaml \ 146 | --network-plugin=cni \ 147 | --pod-cidr=__CLUSTER_CIDR__ 148 | Restart=on-failure 149 | RestartSec=10 150 | WorkingDirectory=/root/ 151 | [Install] 152 | WantedBy=multi-user.target 153 | update: 154 | group: __CHANNEL__ 155 | reboot-strategy: off 156 | -------------------------------------------------------------------------------- /node.yaml: -------------------------------------------------------------------------------- 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 | coreos: 21 | units: 22 | - name: rpcbind.service 23 | enable: true 24 | command: start 25 | - name: rpc-statd.service 26 | enable: true 27 | command: start 28 | - name: etcd-member.service 29 | command: start 30 | content: | 31 | [Unit] 32 | Description=etcd 33 | Documentation=https://github.com/coreos/etcd 34 | [Service] 35 | Environment='ETCD_IMAGE_TAG=v3.1.8' 36 | Environment='ETCD_DATA_DIR=/var/lib/etcd' 37 | Environment='ETCD_USER=etcd' 38 | Type=notify 39 | Restart=always 40 | RestartSec=5s 41 | LimitNOFILE=40000 42 | TimeoutStartSec=0 43 | ExecStart=/usr/lib/coreos/etcd-wrapper --name __NAME__ \ 44 | --proxy on \ 45 | --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \ 46 | --advertise-client-urls http://$public_ipv4:2379,http://$public_ipv4:4001 \ 47 | --listen-peer-urls http://$private_ipv4:2380,http://$private_ipv4:7001 \ 48 | --initial-advertise-peer-urls http://$private_ipv4:2380 \ 49 | --initial-cluster __ETCD_SEED_CLUSTER__ 50 | [Install] 51 | WantedBy=multi-user.target 52 | - name: docker.service 53 | command: start 54 | drop-ins: 55 | - name: 51-docker-mirror.conf 56 | - __PROXY_LINE__name: http-proxy.conf 57 | __PROXY_LINE__content: | 58 | __PROXY_LINE__[Service] 59 | __PROXY_LINE__EnvironmentFile=/etc/environment 60 | - name: 50-docker-options.conf 61 | content: | 62 | [Service] 63 | Environment='DOCKER_OPTS=__DOCKER_OPTIONS__' 64 | - name: early-docker.service 65 | drop-ins: 66 | - __PROXY_LINE__name: http-proxy.conf 67 | __PROXY_LINE__content: | 68 | __PROXY_LINE__[Service] 69 | __PROXY_LINE__EnvironmentFile=/etc/environment 70 | - name: kube-certs.service 71 | command: start 72 | content: | 73 | [Unit] 74 | Description=Generate Kubernetes Node certificates 75 | ConditionPathExists=/tmp/make-certs.sh 76 | Requires=network-online.target 77 | After=network-online.target 78 | [Service] 79 | ExecStartPre=-/usr/sbin/groupadd -r kube-cert 80 | ExecStartPre=/usr/bin/chmod 755 /tmp/make-certs.sh 81 | ExecStart=/tmp/make-certs.sh 82 | Type=oneshot 83 | RemainAfterExit=true 84 | - name: hyperkube-import.service 85 | command: start 86 | content: | 87 | [Unit] 88 | Description=Import Hyperkube Docker image 89 | Requires=docker.service 90 | After=docker.service 91 | ConditionPathExists=/vagrant/artifacts/hyperkube___RELEASE__.tar 92 | [Service] 93 | ExecStart=/usr/bin/docker load --input /vagrant/artifacts/hyperkube___RELEASE__.tar 94 | Type=oneshot 95 | RemainAfterExit=true 96 | - name: kube-kubelet.service 97 | command: start 98 | content: | 99 | [Unit] 100 | Description=Kubernetes Kubelet 101 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 102 | Requires=hyperkube-import.service kube-certs.service 103 | After=hyperkube-import.service kube-certs.service 104 | [Service] 105 | ExecStartPre=/usr/bin/mkdir -p /etc/kubernetes/manifests 106 | ExecStartPre=-/usr/bin/docker rm -f kubelet 107 | ExecStart=/usr/bin/docker run \ 108 | --volume=/:/rootfs:ro \ 109 | --volume=/sys:/sys:ro \ 110 | --volume=/etc/cni/net.d:/etc/cni/net.d:rw \ 111 | --volume=/opt/cni/bin:/opt/cni/bin:rw \ 112 | --volume=/etc/kubernetes:/etc/kubernetes:ro \ 113 | --volume=/var/lib/calico/:/var/lib/calico:rw \ 114 | --volume=/var/lib/docker/:/var/lib/docker:rw \ 115 | --volume=/var/lib/kubelet/:/var/lib/kubelet:shared \ 116 | --volume=/var/run:/var/run:rw \ 117 | --net=host \ 118 | --pid=host \ 119 | --privileged=true \ 120 | --name=kubelet \ 121 | -d \ 122 | gcr.io/google_containers/hyperkube-amd64:__RELEASE__ \ 123 | /hyperkube kubelet \ 124 | --containerized \ 125 | --address=$private_ipv4 \ 126 | --allow-privileged=true \ 127 | --pod-manifest-path=/etc/kubernetes/manifests \ 128 | --hostname-override=$public_ipv4 \ 129 | --cluster_dns=10.100.0.10 \ 130 | --cluster_domain=__DNS_DOMAIN__ \ 131 | --kubeconfig=/etc/kubernetes/node-kubeconfig.yaml \ 132 | --tls-cert-file=/etc/kubernetes/ssl/node.pem \ 133 | --tls-private-key-file=/etc/kubernetes/ssl/node-key.pem \ 134 | --network-plugin=cni \ 135 | --pod-cidr=__CLUSTER_CIDR__ 136 | Restart=on-failure 137 | RestartSec=10 138 | WorkingDirectory=/root/ 139 | [Install] 140 | WantedBy=multi-user.target 141 | update: 142 | group: __CHANNEL__ 143 | reboot-strategy: off 144 | -------------------------------------------------------------------------------- /plugins/calico/calico-rbac.yaml: -------------------------------------------------------------------------------- 1 | # Calico Version v3.3.0 2 | # https://docs.projectcalico.org/v3.3/releases#v3.3.0 3 | kind: ClusterRole 4 | apiVersion: rbac.authorization.k8s.io/v1beta1 5 | metadata: 6 | name: calico-node 7 | rules: 8 | - apiGroups: [""] 9 | resources: 10 | - namespaces 11 | - serviceaccounts 12 | verbs: 13 | - get 14 | - list 15 | - watch 16 | - apiGroups: [""] 17 | resources: 18 | - pods/status 19 | verbs: 20 | - patch 21 | - apiGroups: [""] 22 | resources: 23 | - pods 24 | verbs: 25 | - get 26 | - list 27 | - watch 28 | - apiGroups: [""] 29 | resources: 30 | - services 31 | verbs: 32 | - get 33 | - apiGroups: [""] 34 | resources: 35 | - endpoints 36 | verbs: 37 | - get 38 | - apiGroups: [""] 39 | resources: 40 | - nodes 41 | verbs: 42 | - get 43 | - list 44 | - update 45 | - watch 46 | - apiGroups: ["extensions"] 47 | resources: 48 | - networkpolicies 49 | verbs: 50 | - get 51 | - list 52 | - watch 53 | - apiGroups: ["networking.k8s.io"] 54 | resources: 55 | - networkpolicies 56 | verbs: 57 | - watch 58 | - list 59 | - apiGroups: ["crd.projectcalico.org"] 60 | resources: 61 | - globalfelixconfigs 62 | - felixconfigurations 63 | - bgppeers 64 | - globalbgpconfigs 65 | - bgpconfigurations 66 | - ippools 67 | - globalnetworkpolicies 68 | - globalnetworksets 69 | - networkpolicies 70 | - clusterinformations 71 | - hostendpoints 72 | verbs: 73 | - create 74 | - get 75 | - list 76 | - update 77 | - watch 78 | 79 | --- 80 | 81 | apiVersion: rbac.authorization.k8s.io/v1beta1 82 | kind: ClusterRoleBinding 83 | metadata: 84 | name: calico-node 85 | roleRef: 86 | apiGroup: rbac.authorization.k8s.io 87 | kind: ClusterRole 88 | name: calico-node 89 | subjects: 90 | - kind: ServiceAccount 91 | name: calico-node 92 | namespace: kube-system 93 | -------------------------------------------------------------------------------- /plugins/calico/calico.yaml.tmpl: -------------------------------------------------------------------------------- 1 | # Calico Version v3.3.0 2 | # https://docs.projectcalico.org/v3.3/releases#v3.3.0 3 | # This manifest includes the following component versions: 4 | # calico/node:v3.3.0 5 | # calico/cni:v3.3.0 6 | 7 | # This ConfigMap is used to configure a self-hosted Calico installation. 8 | kind: ConfigMap 9 | apiVersion: v1 10 | metadata: 11 | name: calico-config 12 | namespace: kube-system 13 | data: 14 | # To enable Typha, set this to "calico-typha" *and* set a non-zero value for Typha replicas 15 | # below. We recommend using Typha if you have more than 50 nodes. Above 100 nodes it is 16 | # essential. 17 | typha_service_name: "none" 18 | # Configure the Calico backend to use. 19 | calico_backend: "bird" 20 | 21 | # Configure the MTU to use 22 | veth_mtu: "1440" 23 | 24 | # The CNI network configuration to install on each node. The special 25 | # values in this config will be automatically populated. 26 | cni_network_config: |- 27 | { 28 | "name": "k8s-pod-network", 29 | "cniVersion": "0.3.0", 30 | "plugins": [ 31 | { 32 | "type": "calico", 33 | "log_level": "info", 34 | "datastore_type": "kubernetes", 35 | "nodename": "__KUBERNETES_NODE_NAME__", 36 | "mtu": __CNI_MTU__, 37 | "ipam": { 38 | "type": "host-local", 39 | "subnet": "usePodCidr" 40 | }, 41 | "policy": { 42 | "type": "k8s" 43 | }, 44 | "kubernetes": { 45 | "kubeconfig": "__KUBECONFIG_FILEPATH__" 46 | } 47 | }, 48 | { 49 | "type": "portmap", 50 | "snat": true, 51 | "capabilities": {"portMappings": true} 52 | } 53 | ] 54 | } 55 | 56 | --- 57 | 58 | 59 | # This manifest creates a Service, which will be backed by Calico's Typha daemon. 60 | # Typha sits in between Felix and the API server, reducing Calico's load on the API server. 61 | 62 | apiVersion: v1 63 | kind: Service 64 | metadata: 65 | name: calico-typha 66 | namespace: kube-system 67 | labels: 68 | k8s-app: calico-typha 69 | spec: 70 | ports: 71 | - port: 5473 72 | protocol: TCP 73 | targetPort: calico-typha 74 | name: calico-typha 75 | selector: 76 | k8s-app: calico-typha 77 | 78 | --- 79 | 80 | # This manifest creates a Deployment of Typha to back the above service. 81 | 82 | apiVersion: apps/v1beta1 83 | kind: Deployment 84 | metadata: 85 | name: calico-typha 86 | namespace: kube-system 87 | labels: 88 | k8s-app: calico-typha 89 | spec: 90 | # Number of Typha replicas. To enable Typha, set this to a non-zero value *and* set the 91 | # typha_service_name variable in the calico-config ConfigMap above. 92 | # 93 | # We recommend using Typha if you have more than 50 nodes. Above 100 nodes it is essential 94 | # (when using the Kubernetes datastore). Use one replica for every 100-200 nodes. In 95 | # production, we recommend running at least 3 replicas to reduce the impact of rolling upgrade. 96 | replicas: 0 97 | revisionHistoryLimit: 2 98 | template: 99 | metadata: 100 | labels: 101 | k8s-app: calico-typha 102 | annotations: 103 | # This, along with the CriticalAddonsOnly toleration below, marks the pod as a critical 104 | # add-on, ensuring it gets priority scheduling and that its resources are reserved 105 | # if it ever gets evicted. 106 | scheduler.alpha.kubernetes.io/critical-pod: '' 107 | cluster-autoscaler.kubernetes.io/safe-to-evict: 'true' 108 | spec: 109 | nodeSelector: 110 | beta.kubernetes.io/os: linux 111 | hostNetwork: true 112 | tolerations: 113 | # Mark the pod as a critical add-on for rescheduling. 114 | - key: CriticalAddonsOnly 115 | operator: Exists 116 | # Since Calico can't network a pod until Typha is up, we need to run Typha itself 117 | # as a host-networked pod. 118 | serviceAccountName: calico-node 119 | containers: 120 | - image: quay.io/calico/typha:v3.3.0 121 | name: calico-typha 122 | ports: 123 | - containerPort: 5473 124 | name: calico-typha 125 | protocol: TCP 126 | env: 127 | # Enable "info" logging by default. Can be set to "debug" to increase verbosity. 128 | - name: TYPHA_LOGSEVERITYSCREEN 129 | value: "info" 130 | # Disable logging to file and syslog since those don't make sense in Kubernetes. 131 | - name: TYPHA_LOGFILEPATH 132 | value: "none" 133 | - name: TYPHA_LOGSEVERITYSYS 134 | value: "none" 135 | # Monitor the Kubernetes API to find the number of running instances and rebalance 136 | # connections. 137 | - name: TYPHA_CONNECTIONREBALANCINGMODE 138 | value: "kubernetes" 139 | - name: TYPHA_DATASTORETYPE 140 | value: "kubernetes" 141 | - name: TYPHA_HEALTHENABLED 142 | value: "true" 143 | # Uncomment these lines to enable prometheus metrics. Since Typha is host-networked, 144 | # this opens a port on the host, which may need to be secured. 145 | #- name: TYPHA_PROMETHEUSMETRICSENABLED 146 | # value: "true" 147 | #- name: TYPHA_PROMETHEUSMETRICSPORT 148 | # value: "9093" 149 | livenessProbe: 150 | exec: 151 | command: 152 | - calico-typha 153 | - check 154 | - liveness 155 | periodSeconds: 30 156 | initialDelaySeconds: 30 157 | readinessProbe: 158 | exec: 159 | command: 160 | - calico-typha 161 | - check 162 | - readiness 163 | periodSeconds: 10 164 | 165 | --- 166 | 167 | # This manifest creates a Pod Disruption Budget for Typha to allow K8s Cluster Autoscaler to evict 168 | 169 | apiVersion: policy/v1beta1 170 | kind: PodDisruptionBudget 171 | metadata: 172 | name: calico-typha 173 | namespace: kube-system 174 | labels: 175 | k8s-app: calico-typha 176 | spec: 177 | maxUnavailable: 1 178 | selector: 179 | matchLabels: 180 | k8s-app: calico-typha 181 | 182 | --- 183 | 184 | # This manifest installs the calico/node container, as well 185 | # as the Calico CNI plugins and network config on 186 | # each master and worker node in a Kubernetes cluster. 187 | kind: DaemonSet 188 | apiVersion: extensions/v1beta1 189 | metadata: 190 | name: calico-node 191 | namespace: kube-system 192 | labels: 193 | k8s-app: calico-node 194 | spec: 195 | selector: 196 | matchLabels: 197 | k8s-app: calico-node 198 | updateStrategy: 199 | type: RollingUpdate 200 | rollingUpdate: 201 | maxUnavailable: 1 202 | template: 203 | metadata: 204 | labels: 205 | k8s-app: calico-node 206 | annotations: 207 | # This, along with the CriticalAddonsOnly toleration below, 208 | # marks the pod as a critical add-on, ensuring it gets 209 | # priority scheduling and that its resources are reserved 210 | # if it ever gets evicted. 211 | scheduler.alpha.kubernetes.io/critical-pod: '' 212 | spec: 213 | nodeSelector: 214 | beta.kubernetes.io/os: linux 215 | hostNetwork: true 216 | tolerations: 217 | # Make sure calico-node gets scheduled on all nodes. 218 | - effect: NoSchedule 219 | operator: Exists 220 | # Mark the pod as a critical add-on for rescheduling. 221 | - key: CriticalAddonsOnly 222 | operator: Exists 223 | - effect: NoExecute 224 | operator: Exists 225 | serviceAccountName: calico-node 226 | # Minimize downtime during a rolling upgrade or deletion; tell Kubernetes to do a "force 227 | # deletion": https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods. 228 | terminationGracePeriodSeconds: 0 229 | containers: 230 | # Runs calico/node container on each Kubernetes node. This 231 | # container programs network policy and routes on each 232 | # host. 233 | - name: calico-node 234 | image: quay.io/calico/node:v3.3.0 235 | env: 236 | # Use Kubernetes API as the backing datastore. 237 | - name: DATASTORE_TYPE 238 | value: "kubernetes" 239 | # Typha support: controlled by the ConfigMap. 240 | - name: FELIX_TYPHAK8SSERVICENAME 241 | valueFrom: 242 | configMapKeyRef: 243 | name: calico-config 244 | key: typha_service_name 245 | # Wait for the datastore. 246 | - name: WAIT_FOR_DATASTORE 247 | value: "true" 248 | # Set based on the k8s node name. 249 | - name: NODENAME 250 | valueFrom: 251 | fieldRef: 252 | fieldPath: spec.nodeName 253 | # Choose the backend to use. 254 | - name: CALICO_NETWORKING_BACKEND 255 | valueFrom: 256 | configMapKeyRef: 257 | name: calico-config 258 | key: calico_backend 259 | # Cluster type to identify the deployment type 260 | - name: CLUSTER_TYPE 261 | value: "k8s,bgp" 262 | # Auto-detect the BGP IP address. 263 | - name: IP 264 | value: "autodetect" 265 | # Enable IPIP 266 | - name: CALICO_IPV4POOL_IPIP 267 | value: "Always" 268 | # Set MTU for tunnel device used if ipip is enabled 269 | - name: FELIX_IPINIPMTU 270 | valueFrom: 271 | configMapKeyRef: 272 | name: calico-config 273 | key: veth_mtu 274 | # The default IPv4 pool to create on startup if none exists. Pod IPs will be 275 | # chosen from this range. Changing this value after installation will have 276 | # no effect. This should fall within `--cluster-cidr`. 277 | - name: CALICO_IPV4POOL_CIDR 278 | value: "__CLUSTER_CIDR__" 279 | # Disable file logging so `kubectl logs` works. 280 | - name: CALICO_DISABLE_FILE_LOGGING 281 | value: "true" 282 | # Set Felix endpoint to host default action to ACCEPT. 283 | - name: FELIX_DEFAULTENDPOINTTOHOSTACTION 284 | value: "ACCEPT" 285 | # Disable IPv6 on Kubernetes. 286 | - name: FELIX_IPV6SUPPORT 287 | value: "false" 288 | # Set Felix logging to "info" 289 | - name: FELIX_LOGSEVERITYSCREEN 290 | value: "info" 291 | - name: FELIX_HEALTHENABLED 292 | value: "true" 293 | securityContext: 294 | privileged: true 295 | resources: 296 | requests: 297 | cpu: 250m 298 | livenessProbe: 299 | httpGet: 300 | path: /liveness 301 | port: 9099 302 | host: localhost 303 | periodSeconds: 10 304 | initialDelaySeconds: 10 305 | failureThreshold: 6 306 | readinessProbe: 307 | exec: 308 | command: 309 | - /bin/calico-node 310 | - -bird-ready 311 | - -felix-ready 312 | periodSeconds: 10 313 | volumeMounts: 314 | - mountPath: /lib/modules 315 | name: lib-modules 316 | readOnly: true 317 | - mountPath: /run/xtables.lock 318 | name: xtables-lock 319 | readOnly: false 320 | - mountPath: /var/run/calico 321 | name: var-run-calico 322 | readOnly: false 323 | - mountPath: /var/lib/calico 324 | name: var-lib-calico 325 | readOnly: false 326 | # This container installs the Calico CNI binaries 327 | # and CNI network config file on each node. 328 | - name: install-cni 329 | image: quay.io/calico/cni:v3.3.0 330 | command: ["/install-cni.sh"] 331 | env: 332 | # Name of the CNI config file to create. 333 | - name: CNI_CONF_NAME 334 | value: "10-calico.conflist" 335 | # Set the hostname based on the k8s node name. 336 | - name: KUBERNETES_NODE_NAME 337 | valueFrom: 338 | fieldRef: 339 | fieldPath: spec.nodeName 340 | # The CNI network config to install on each node. 341 | - name: CNI_NETWORK_CONFIG 342 | valueFrom: 343 | configMapKeyRef: 344 | name: calico-config 345 | key: cni_network_config 346 | # CNI MTU Config variable 347 | - name: CNI_MTU 348 | valueFrom: 349 | configMapKeyRef: 350 | name: calico-config 351 | key: veth_mtu 352 | volumeMounts: 353 | - mountPath: /host/opt/cni/bin 354 | name: cni-bin-dir 355 | - mountPath: /host/etc/cni/net.d 356 | name: cni-net-dir 357 | volumes: 358 | # Used by calico/node. 359 | - name: lib-modules 360 | hostPath: 361 | path: /lib/modules 362 | - name: var-run-calico 363 | hostPath: 364 | path: /var/run/calico 365 | - name: var-lib-calico 366 | hostPath: 367 | path: /var/lib/calico 368 | - name: xtables-lock 369 | hostPath: 370 | path: /run/xtables.lock 371 | type: FileOrCreate 372 | # Used to install CNI. 373 | - name: cni-bin-dir 374 | hostPath: 375 | path: /opt/cni/bin 376 | - name: cni-net-dir 377 | hostPath: 378 | path: /etc/cni/net.d 379 | --- 380 | 381 | apiVersion: v1 382 | kind: ServiceAccount 383 | metadata: 384 | name: calico-node 385 | namespace: kube-system 386 | 387 | --- 388 | 389 | # Create all the CustomResourceDefinitions needed for 390 | # Calico policy and networking mode. 391 | 392 | apiVersion: apiextensions.k8s.io/v1beta1 393 | kind: CustomResourceDefinition 394 | metadata: 395 | name: felixconfigurations.crd.projectcalico.org 396 | spec: 397 | scope: Cluster 398 | group: crd.projectcalico.org 399 | version: v1 400 | names: 401 | kind: FelixConfiguration 402 | plural: felixconfigurations 403 | singular: felixconfiguration 404 | --- 405 | 406 | apiVersion: apiextensions.k8s.io/v1beta1 407 | kind: CustomResourceDefinition 408 | metadata: 409 | name: bgppeers.crd.projectcalico.org 410 | spec: 411 | scope: Cluster 412 | group: crd.projectcalico.org 413 | version: v1 414 | names: 415 | kind: BGPPeer 416 | plural: bgppeers 417 | singular: bgppeer 418 | 419 | --- 420 | 421 | apiVersion: apiextensions.k8s.io/v1beta1 422 | kind: CustomResourceDefinition 423 | metadata: 424 | name: bgpconfigurations.crd.projectcalico.org 425 | spec: 426 | scope: Cluster 427 | group: crd.projectcalico.org 428 | version: v1 429 | names: 430 | kind: BGPConfiguration 431 | plural: bgpconfigurations 432 | singular: bgpconfiguration 433 | 434 | --- 435 | 436 | apiVersion: apiextensions.k8s.io/v1beta1 437 | kind: CustomResourceDefinition 438 | metadata: 439 | name: ippools.crd.projectcalico.org 440 | spec: 441 | scope: Cluster 442 | group: crd.projectcalico.org 443 | version: v1 444 | names: 445 | kind: IPPool 446 | plural: ippools 447 | singular: ippool 448 | 449 | --- 450 | 451 | apiVersion: apiextensions.k8s.io/v1beta1 452 | kind: CustomResourceDefinition 453 | metadata: 454 | name: hostendpoints.crd.projectcalico.org 455 | spec: 456 | scope: Cluster 457 | group: crd.projectcalico.org 458 | version: v1 459 | names: 460 | kind: HostEndpoint 461 | plural: hostendpoints 462 | singular: hostendpoint 463 | 464 | --- 465 | 466 | apiVersion: apiextensions.k8s.io/v1beta1 467 | kind: CustomResourceDefinition 468 | metadata: 469 | name: clusterinformations.crd.projectcalico.org 470 | spec: 471 | scope: Cluster 472 | group: crd.projectcalico.org 473 | version: v1 474 | names: 475 | kind: ClusterInformation 476 | plural: clusterinformations 477 | singular: clusterinformation 478 | 479 | --- 480 | 481 | apiVersion: apiextensions.k8s.io/v1beta1 482 | kind: CustomResourceDefinition 483 | metadata: 484 | name: globalnetworkpolicies.crd.projectcalico.org 485 | spec: 486 | scope: Cluster 487 | group: crd.projectcalico.org 488 | version: v1 489 | names: 490 | kind: GlobalNetworkPolicy 491 | plural: globalnetworkpolicies 492 | singular: globalnetworkpolicy 493 | 494 | --- 495 | 496 | apiVersion: apiextensions.k8s.io/v1beta1 497 | kind: CustomResourceDefinition 498 | metadata: 499 | name: globalnetworksets.crd.projectcalico.org 500 | spec: 501 | scope: Cluster 502 | group: crd.projectcalico.org 503 | version: v1 504 | names: 505 | kind: GlobalNetworkSet 506 | plural: globalnetworksets 507 | singular: globalnetworkset 508 | 509 | --- 510 | 511 | apiVersion: apiextensions.k8s.io/v1beta1 512 | kind: CustomResourceDefinition 513 | metadata: 514 | name: networkpolicies.crd.projectcalico.org 515 | spec: 516 | scope: Namespaced 517 | group: crd.projectcalico.org 518 | version: v1 519 | names: 520 | kind: NetworkPolicy 521 | plural: networkpolicies 522 | singular: networkpolicy 523 | -------------------------------------------------------------------------------- /plugins/coredns/coredns.yaml.sed: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: coredns 5 | namespace: kube-system 6 | --- 7 | apiVersion: rbac.authorization.k8s.io/v1beta1 8 | kind: ClusterRole 9 | metadata: 10 | labels: 11 | kubernetes.io/bootstrapping: rbac-defaults 12 | name: system:coredns 13 | rules: 14 | - apiGroups: 15 | - "" 16 | resources: 17 | - endpoints 18 | - services 19 | - pods 20 | - namespaces 21 | verbs: 22 | - list 23 | - watch 24 | - apiGroups: 25 | - "" 26 | resources: 27 | - nodes 28 | verbs: 29 | - get 30 | --- 31 | apiVersion: rbac.authorization.k8s.io/v1beta1 32 | kind: ClusterRoleBinding 33 | metadata: 34 | annotations: 35 | rbac.authorization.kubernetes.io/autoupdate: "true" 36 | labels: 37 | kubernetes.io/bootstrapping: rbac-defaults 38 | name: system:coredns 39 | roleRef: 40 | apiGroup: rbac.authorization.k8s.io 41 | kind: ClusterRole 42 | name: system:coredns 43 | subjects: 44 | - kind: ServiceAccount 45 | name: coredns 46 | namespace: kube-system 47 | --- 48 | apiVersion: v1 49 | kind: ConfigMap 50 | metadata: 51 | name: coredns 52 | namespace: kube-system 53 | data: 54 | Corefile: | 55 | .:53 { 56 | errors 57 | health 58 | kubernetes CLUSTER_DOMAIN SERVICE_CIDR { 59 | pods insecure 60 | upstream 61 | fallthrough in-addr.arpa ip6.arpa 62 | } 63 | prometheus :9153 64 | proxy . /etc/resolv.conf 65 | cache 30 66 | loop 67 | reload 68 | loadbalance 69 | } 70 | --- 71 | apiVersion: extensions/v1beta1 72 | kind: Deployment 73 | metadata: 74 | name: coredns 75 | namespace: kube-system 76 | labels: 77 | k8s-app: kube-dns 78 | kubernetes.io/name: "CoreDNS" 79 | spec: 80 | replicas: 2 81 | strategy: 82 | type: RollingUpdate 83 | rollingUpdate: 84 | maxUnavailable: 1 85 | selector: 86 | matchLabels: 87 | k8s-app: kube-dns 88 | template: 89 | metadata: 90 | labels: 91 | k8s-app: kube-dns 92 | spec: 93 | serviceAccountName: coredns 94 | tolerations: 95 | - key: node-role.kubernetes.io/master 96 | effect: NoSchedule 97 | - key: "CriticalAddonsOnly" 98 | operator: "Exists" 99 | nodeSelector: 100 | beta.kubernetes.io/os: linux 101 | containers: 102 | - name: coredns 103 | image: coredns/coredns:1.2.5 104 | imagePullPolicy: IfNotPresent 105 | resources: 106 | limits: 107 | memory: 170Mi 108 | requests: 109 | cpu: 100m 110 | memory: 70Mi 111 | args: [ "-conf", "/etc/coredns/Corefile" ] 112 | volumeMounts: 113 | - name: config-volume 114 | mountPath: /etc/coredns 115 | readOnly: true 116 | ports: 117 | - containerPort: 53 118 | name: dns 119 | protocol: UDP 120 | - containerPort: 53 121 | name: dns-tcp 122 | protocol: TCP 123 | - containerPort: 9153 124 | name: metrics 125 | protocol: TCP 126 | securityContext: 127 | allowPrivilegeEscalation: false 128 | capabilities: 129 | add: 130 | - NET_BIND_SERVICE 131 | drop: 132 | - all 133 | readOnlyRootFilesystem: true 134 | livenessProbe: 135 | httpGet: 136 | path: /health 137 | port: 8080 138 | scheme: HTTP 139 | initialDelaySeconds: 60 140 | timeoutSeconds: 5 141 | successThreshold: 1 142 | failureThreshold: 5 143 | dnsPolicy: Default 144 | volumes: 145 | - name: config-volume 146 | configMap: 147 | name: coredns 148 | items: 149 | - key: Corefile 150 | path: Corefile 151 | --- 152 | apiVersion: v1 153 | kind: Service 154 | metadata: 155 | name: kube-dns 156 | namespace: kube-system 157 | annotations: 158 | prometheus.io/port: "9153" 159 | prometheus.io/scrape: "true" 160 | labels: 161 | k8s-app: kube-dns 162 | kubernetes.io/cluster-service: "true" 163 | kubernetes.io/name: "CoreDNS" 164 | spec: 165 | selector: 166 | k8s-app: kube-dns 167 | clusterIP: CLUSTER_DNS_IP 168 | ports: 169 | - name: dns 170 | port: 53 171 | protocol: UDP 172 | - name: dns-tcp 173 | port: 53 174 | protocol: TCP -------------------------------------------------------------------------------- /plugins/coredns/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Deploys CoreDNS to a cluster currently running Kube-DNS. 4 | 5 | SERVICE_CIDR=$1 6 | CLUSTER_DOMAIN=${2:-cluster.local} 7 | YAML_TEMPLATE=${3:-`pwd`/coredns.yaml.sed} 8 | YAML=${4:-`pwd`/coredns.yaml} 9 | 10 | if [[ -z $SERVICE_CIDR ]]; then 11 | echo "Usage: $0 SERVICE-CIDR [ CLUSTER-DOMAIN ] [ YAML-TEMPLATE ] [ YAML ]" 12 | exit 1 13 | fi 14 | 15 | CLUSTER_DNS_IP="10.100.0.10" 16 | 17 | sed -e s/CLUSTER_DNS_IP/$CLUSTER_DNS_IP/g -e s/CLUSTER_DOMAIN/$CLUSTER_DOMAIN/g -e s?SERVICE_CIDR?$SERVICE_CIDR?g $YAML_TEMPLATE -------------------------------------------------------------------------------- /plugins/dashboard/dashboard-rbac.yaml: -------------------------------------------------------------------------------- 1 | kind: Role 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | metadata: 4 | name: kubernetes-dashboard-minimal 5 | namespace: kube-system 6 | rules: 7 | # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret. 8 | - apiGroups: [""] 9 | resources: ["secrets"] 10 | verbs: ["create"] 11 | # Allow Dashboard to create 'kubernetes-dashboard-settings' config map. 12 | - apiGroups: [""] 13 | resources: ["configmaps"] 14 | verbs: ["create"] 15 | # Allow Dashboard to get, update and delete Dashboard exclusive secrets. 16 | - apiGroups: [""] 17 | resources: ["secrets"] 18 | resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"] 19 | verbs: ["get", "update", "delete"] 20 | # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map. 21 | - apiGroups: [""] 22 | resources: ["configmaps"] 23 | resourceNames: ["kubernetes-dashboard-settings"] 24 | verbs: ["get", "update"] 25 | # Allow Dashboard to get metrics from heapster. 26 | - apiGroups: [""] 27 | resources: ["services"] 28 | resourceNames: ["heapster"] 29 | verbs: ["proxy"] 30 | - apiGroups: [""] 31 | resources: ["services/proxy"] 32 | resourceNames: ["heapster", "http:heapster:", "https:heapster:"] 33 | verbs: ["get"] 34 | --- 35 | apiVersion: rbac.authorization.k8s.io/v1 36 | kind: RoleBinding 37 | metadata: 38 | name: kubernetes-dashboard-minimal 39 | namespace: kube-system 40 | roleRef: 41 | apiGroup: rbac.authorization.k8s.io 42 | kind: Role 43 | name: kubernetes-dashboard-minimal 44 | subjects: 45 | - kind: ServiceAccount 46 | name: kubernetes-dashboard 47 | namespace: kube-system 48 | -------------------------------------------------------------------------------- /plugins/dashboard/dashboard.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | metadata: 4 | labels: 5 | k8s-app: kubernetes-dashboard 6 | name: kubernetes-dashboard-certs 7 | namespace: kube-system 8 | type: Opaque 9 | --- 10 | apiVersion: v1 11 | kind: ServiceAccount 12 | metadata: 13 | labels: 14 | k8s-app: kubernetes-dashboard 15 | name: kubernetes-dashboard 16 | namespace: kube-system 17 | --- 18 | kind: Deployment 19 | apiVersion: apps/v1beta2 20 | metadata: 21 | labels: 22 | k8s-app: kubernetes-dashboard 23 | name: kubernetes-dashboard 24 | namespace: kube-system 25 | spec: 26 | replicas: 1 27 | revisionHistoryLimit: 10 28 | selector: 29 | matchLabels: 30 | k8s-app: kubernetes-dashboard 31 | template: 32 | metadata: 33 | labels: 34 | k8s-app: kubernetes-dashboard 35 | spec: 36 | containers: 37 | - name: kubernetes-dashboard 38 | image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0 39 | ports: 40 | - containerPort: 8443 41 | protocol: TCP 42 | args: 43 | - --auto-generate-certificates 44 | # Uncomment the following line to manually specify Kubernetes API server Host 45 | # If not specified, Dashboard will attempt to auto discover the API server and connect 46 | # to it. Uncomment only if the default does not work. 47 | # - --apiserver-host=http://my-address:port 48 | volumeMounts: 49 | - name: kubernetes-dashboard-certs 50 | mountPath: /certs 51 | # Create on-disk volume to store exec logs 52 | - mountPath: /tmp 53 | name: tmp-volume 54 | livenessProbe: 55 | httpGet: 56 | scheme: HTTPS 57 | path: / 58 | port: 8443 59 | initialDelaySeconds: 30 60 | timeoutSeconds: 30 61 | volumes: 62 | - name: kubernetes-dashboard-certs 63 | secret: 64 | secretName: kubernetes-dashboard-certs 65 | - name: tmp-volume 66 | emptyDir: {} 67 | serviceAccountName: kubernetes-dashboard 68 | # Comment the following tolerations if Dashboard must not be deployed on master 69 | tolerations: 70 | - key: node-role.kubernetes.io/master 71 | effect: NoSchedule 72 | --- 73 | kind: Service 74 | apiVersion: v1 75 | metadata: 76 | labels: 77 | k8s-app: kubernetes-dashboard 78 | name: kubernetes-dashboard 79 | namespace: kube-system 80 | spec: 81 | ports: 82 | - port: 443 83 | targetPort: 8443 84 | selector: 85 | k8s-app: kubernetes-dashboard 86 | -------------------------------------------------------------------------------- /setup.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | PLATFORM="$(uname -s | tr '[:upper:]' '[:lower:]')" 5 | KUBERNETES_VERSION=__KUBERNETES_VERSION__ 6 | KUB_URL="https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/${PLATFORM}/amd64/kubectl" 7 | 8 | scream () { 9 | cat <<< "$@" 1>&2 10 | exit 1 11 | } 12 | 13 | case "$PLATFORM" in 14 | darwin|linux) 15 | targetDir="/usr/local/bin" 16 | if [[ -r /etc/os-release ]]; then 17 | . /etc/os-release 18 | if [[ $ID = coreos ]]; then 19 | targetDir="/opt/bin" 20 | unlink $HOME/.bash_profile 21 | cp /usr/share/skel/.bash_profile $HOME/.bash_profile 22 | chmod 775 $HOME/.bash_profile 23 | fi 24 | fi 25 | ;; 26 | *) 27 | scream "Unknown or unsupported platform: ${PLATFORM}" 28 | ;; 29 | esac 30 | 31 | if [[ "$#" -eq 1 && "$1" == "install" ]] ; then 32 | doinstall="true" 33 | if [ -x ${targetDir}/kubectl ]; then 34 | installedversion=`${targetDir}/kubectl version | awk -F":" '{print $5}' | head -n1 | awk -F"," {'print $1'} | tr -d "\"" | tr -d "v"` 35 | if [ "$installedversion" == "${KUBERNETES_VERSION}" ]; then 36 | echo "kubectl already installed in version '$installedversion'. Skipping install." 37 | doinstall="false" 38 | else 39 | echo "kubectl installed in version '$installedversion' instead of '${KUBERNETES_VERSION}'. Reinstalling." 40 | fi 41 | fi 42 | 43 | if [ "$doinstall" == "true" ]; then 44 | echo "Downloading and installing ${PLATFORM} version of 'kubectl' v${KUBERNETES_VERSION} into ${targetDir}. This may take a couple minutes, depending on your internet speed.." 45 | [ -d ${targetDir} ] || sudo mkdir -p ${targetDir} 46 | sudo -E curl -s -k -L -o ${targetDir}/kubectl "${KUB_URL}" 47 | [ -x ${targetDir}/kubectl ] || sudo chmod +x ${targetDir}/kubectl 48 | fi 49 | 50 | # use sed to replace current values, if any; create profile file if not exists 51 | touch -a $HOME/.bash_profile 52 | echo "Configuring environment.." 53 | __PROXY_LINE__if ! grep -q 'export NO_PROXY' $HOME/.bash_profile ; then 54 | __PROXY_LINE__ echo "export NO_PROXY=__NO_PROXY__" >> $HOME/.bash_profile 55 | __PROXY_LINE__ echo "export no_proxy=__NO_PROXY__" >> $HOME/.bash_profile 56 | __PROXY_LINE__else 57 | __PROXY_LINE__ sed -i'*' 's|.*export NO_PROXY.*|export NO_PROXY=__NO_PROXY__|' $HOME/.bash_profile 58 | __PROXY_LINE__ sed -i'*' 's|.*export no_proxy.*|export no_proxy=__NO_PROXY__|' $HOME/.bash_profile 59 | __PROXY_LINE__fi 60 | __PROXY_LINE__export NO_PROXY=__NO_PROXY__ 61 | __PROXY_LINE__export no_proxy=__NO_PROXY__ 62 | elif [[ "$#" -eq 1 && "$1" == "uninstall" ]] ; then 63 | echo "Removing 'kubectl' v${KUBERNETES_VERSION}.." 64 | [ -f ${targetDir}/kubectl ] && sudo rm -f ${targetDir}/kubectl 65 | else 66 | echo "Usage: ./setup (install|uninstall)" 67 | fi 68 | -------------------------------------------------------------------------------- /synced_folders.yaml: -------------------------------------------------------------------------------- 1 | - name: default 2 | source: . 3 | destination: /vagrant 4 | nfs: true 5 | mount_options: 'nolock,vers=3,udp,noatime' 6 | -------------------------------------------------------------------------------- /temp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pires/kubernetes-vagrant-coreos-cluster/56ebbaa2a972d5412c99324259a7208318d9d9df/temp/.gitkeep -------------------------------------------------------------------------------- /tls/make-certs-master-rbac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | cert_group=kube-cert 8 | cert_dir=/etc/kubernetes/ssl 9 | 10 | pem_ca=$cert_dir/ca.pem 11 | pem_ca_key=$cert_dir/ca-key.pem 12 | pem_server=$cert_dir/apiserver.pem 13 | pem_server_key=$cert_dir/apiserver-key.pem 14 | pem_server_csr=$cert_dir/apiserver-csr.pem 15 | 16 | pem_admin=/vagrant/artifacts/tls/admin.pem 17 | pem_admin_key=/vagrant/artifacts/tls/admin-key.pem 18 | pem_admin_csr=/vagrant/artifacts/tls/admin-csr.pem 19 | 20 | # Generate TLS artifacts 21 | mkdir -p "$cert_dir" 22 | 23 | openssl genrsa -out $pem_ca_key 2048 24 | openssl req -x509 -new -nodes -key $pem_ca_key -days 10000 -out $pem_ca -subj "/CN=kube-ca" 25 | 26 | openssl genrsa -out $pem_server_key 2048 27 | openssl req -new -key $pem_server_key -out $pem_server_csr -subj "/CN=kube-apiserver" -config /tmp/openssl.cnf 28 | openssl x509 -req -in $pem_server_csr -CA $pem_ca -CAkey $pem_ca_key -CAcreateserial -out $pem_server -days 365 -extensions v3_req -extfile /tmp/openssl.cnf 29 | 30 | # Make server certs accessible to apiserver. 31 | chgrp $cert_group $pem_ca $pem_ca_key $pem_server $pem_server_key 32 | chmod 600 $pem_ca_key $pem_server_key 33 | chmod 660 $pem_ca $pem_server 34 | 35 | # Copy CA stuff to host so worked nodes can use it 36 | cp $pem_ca $pem_ca_key /vagrant/artifacts/tls 37 | 38 | # Generate admin 39 | openssl genrsa -out $pem_admin_key 2048 40 | # Add RBAC Support 41 | # Give kube-admin the clusterroles of a system:masters 42 | openssl req -new -key $pem_admin_key -out $pem_admin_csr -subj "/CN=kube-admin/O=system:masters" 43 | openssl x509 -req -in $pem_admin_csr -CA $pem_ca -CAkey $pem_ca_key -CAcreateserial -out $pem_admin -days 365 44 | -------------------------------------------------------------------------------- /tls/make-certs-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | cert_group=kube-cert 8 | cert_dir=/etc/kubernetes/ssl 9 | 10 | pem_ca=$cert_dir/ca.pem 11 | pem_ca_key=$cert_dir/ca-key.pem 12 | pem_server=$cert_dir/apiserver.pem 13 | pem_server_key=$cert_dir/apiserver-key.pem 14 | pem_server_csr=$cert_dir/apiserver-csr.pem 15 | 16 | pem_admin=/vagrant/artifacts/tls/admin.pem 17 | pem_admin_key=/vagrant/artifacts/tls/admin-key.pem 18 | pem_admin_csr=/vagrant/artifacts/tls/admin-csr.pem 19 | 20 | # Generate TLS artifacts 21 | mkdir -p "$cert_dir" 22 | 23 | openssl genrsa -out $pem_ca_key 2048 24 | openssl req -x509 -new -nodes -key $pem_ca_key -days 10000 -out $pem_ca -subj "/CN=kube-ca" 25 | 26 | openssl genrsa -out $pem_server_key 2048 27 | openssl req -new -key $pem_server_key -out $pem_server_csr -subj "/CN=kube-apiserver" -config /tmp/openssl.cnf 28 | openssl x509 -req -in $pem_server_csr -CA $pem_ca -CAkey $pem_ca_key -CAcreateserial -out $pem_server -days 365 -extensions v3_req -extfile /tmp/openssl.cnf 29 | 30 | # Make server certs accessible to apiserver. 31 | chgrp $cert_group $pem_ca $pem_ca_key $pem_server $pem_server_key 32 | chmod 600 $pem_ca_key $pem_server_key 33 | chmod 660 $pem_ca $pem_server 34 | 35 | # Copy CA stuff to host so worked nodes can use it 36 | cp $pem_ca $pem_ca_key /vagrant/artifacts/tls 37 | 38 | # Generate admin 39 | openssl genrsa -out $pem_admin_key 2048 40 | openssl req -new -key $pem_admin_key -out $pem_admin_csr -subj "/CN=kube-admin/O=system:masters" 41 | openssl x509 -req -in $pem_admin_csr -CA $pem_ca -CAkey $pem_ca_key -CAcreateserial -out $pem_admin -days 365 42 | -------------------------------------------------------------------------------- /tls/make-certs-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | cert_group=kube-cert 8 | cert_dir=/etc/kubernetes/ssl 9 | host_cert_dir=/vagrant/artifacts/tls 10 | 11 | mkdir -p "$cert_dir" 12 | 13 | cp $host_cert_dir/ca.pem $cert_dir/ca.pem 14 | cp $host_cert_dir/ca-key.pem $cert_dir/ca-key.pem 15 | 16 | pem_ca=$cert_dir/ca.pem 17 | pem_ca_key=$cert_dir/ca-key.pem 18 | 19 | pem_node=$cert_dir/node.pem 20 | pem_node_key=$cert_dir/node-key.pem 21 | pem_node_csr=$cert_dir/node-csr.pem 22 | 23 | # Generate TLS artifacts 24 | openssl genrsa -out $pem_node_key 2048 25 | openssl req -new -key $pem_node_key -out $pem_node_csr -subj "/CN=__NODE_IP__" -config /tmp/openssl.cnf 26 | openssl x509 -req -in $pem_node_csr -CA $pem_ca -CAkey $pem_ca_key -CAcreateserial -out $pem_node -days 365 -extensions v3_req -extfile /tmp/openssl.cnf 27 | 28 | # Make server certs accessible to apiserver. 29 | chgrp $cert_group $pem_ca $pem_ca_key $pem_node $pem_node_key 30 | chmod 600 $pem_node_key 31 | chmod 660 $pem_node $pem_ca 32 | -------------------------------------------------------------------------------- /tls/master-kubeconfig.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Config 3 | clusters: 4 | - name: local 5 | cluster: 6 | server: http://127.0.0.1:8080 7 | users: 8 | - name: kubelet 9 | contexts: 10 | - context: 11 | cluster: local 12 | user: kubelet 13 | name: kubelet-context 14 | current-context: kubelet-context -------------------------------------------------------------------------------- /tls/node-kubeconfig.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Config 3 | clusters: 4 | - name: local 5 | cluster: 6 | server: https://__MASTER_IP__:443 7 | certificate-authority: /etc/kubernetes/ssl/ca.pem 8 | users: 9 | - name: kubelet 10 | user: 11 | client-certificate: /etc/kubernetes/ssl/node.pem 12 | client-key: /etc/kubernetes/ssl/node-key.pem 13 | contexts: 14 | - context: 15 | cluster: local 16 | user: kubelet 17 | name: kubelet-context 18 | current-context: kubelet-context -------------------------------------------------------------------------------- /tls/openssl-master.cnf.tmpl: -------------------------------------------------------------------------------- 1 | [req] 2 | req_extensions = v3_req 3 | distinguished_name = req_distinguished_name 4 | [req_distinguished_name] 5 | [ v3_req ] 6 | basicConstraints = CA:FALSE 7 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 8 | subjectAltName = @alt_names 9 | [alt_names] 10 | DNS.1 = kubernetes 11 | DNS.2 = kubernetes.default 12 | DNS.3 = kubernetes.default.svc 13 | DNS.4 = kubernetes.default.svc.__DNS_DOMAIN__ 14 | IP.1 = 10.100.0.1 15 | IP.2 = __MASTER_IP__ -------------------------------------------------------------------------------- /tls/openssl-node.cnf.tmpl: -------------------------------------------------------------------------------- 1 | [req] 2 | req_extensions = v3_req 3 | distinguished_name = req_distinguished_name 4 | [req_distinguished_name] 5 | [ v3_req ] 6 | basicConstraints = CA:FALSE 7 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 8 | subjectAltName = @alt_names 9 | [alt_names] 10 | IP.1 = __NODE_IP__ --------------------------------------------------------------------------------