├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── ansible.cfg ├── docs └── architecture.png ├── group_vars └── all ├── hosts ├── k8s.yml ├── roles ├── addons │ ├── tasks │ │ └── main.yml │ └── templates │ │ ├── coredns.yml │ │ ├── dashboard-admin.yml │ │ └── kubernetes-dashboard.yml ├── docker │ ├── defaults │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ └── lib │ │ └── systemd │ │ └── system │ │ └── docker.service.j2 ├── etcd │ ├── handlers │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ └── lib │ │ └── systemd │ │ └── system │ │ └── etcd.service.j2 ├── flannel │ ├── defaults │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ └── lib │ │ └── systemd │ │ └── system │ │ └── flannel.service.j2 ├── k8s-download │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── k8s-master │ ├── handlers │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ ├── lib │ │ └── systemd │ │ │ └── system │ │ │ ├── kube-apiserver.service.j2 │ │ │ ├── kube-controller-manager.service.j2 │ │ │ └── kube-scheduler.service.j2 │ │ └── rbac-conf │ │ └── rbac.yml ├── k8s-monitoring │ ├── tasks │ │ └── main.yml │ └── templates │ │ ├── grafana.yml │ │ ├── heapster-rbac.yml │ │ ├── heapster.yml │ │ └── influxdb.yml ├── k8s-worker │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ └── lib │ │ └── systemd │ │ └── system │ │ ├── kube-proxy.service.j2 │ │ └── kubelet.service.j2 ├── kubeconfig │ └── tasks │ │ └── main.yml ├── loadbalancer │ ├── handlers │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── pki │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml └── ssh │ └── tasks │ └── main.yml └── ssh.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/* 2 | bin/* 3 | kubeconfig/* 4 | pki/* 5 | ubuntu-xenial-16.04-cloudimg-console.log 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 2 | 3 | ## Introduction 4 | This is an attempt to automate the creation of k8s cluster proposed in the tutorial [kubernetes-the-hard-way](https://github.com/kelseyhightower/kubernetes-the-hard-way). 5 | 6 |

7 | 8 |

9 | 10 | ## Cluster details 11 | * k8s version: **1.10.2** 12 | * Container runtime: [Docker](https://www.docker.com/) 13 | * Network plugin: [Flannel](https://github.com/coreos/flannel) 14 | * DNS plugin: [CoreDNS](https://github.com/coredns/coredns) 15 | * [gVisor](https://github.com/google/gvisor) supported. 16 | 17 | ## Prerequisites 18 | Before you begin, you need to install all these tools: 19 | - [Ansible](https://www.ansible.com/) 20 | - [Vagrant](https://www.vagrantup.com/) 21 | - [Virtualbox](https://www.virtualbox.org/wiki/Downloads) 22 | - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) 23 | 24 | You need also to have at least 4 GB of free memory. 25 | ## How to use 26 | 27 | Create the VMs with Vagrant 28 | ``` 29 | $ vagrant up 30 | ``` 31 | 32 | Deploy k8s cluster 33 | ``` 34 | $ ansible-playbook k8s.yml 35 | ``` 36 | ## Verification 37 | *Check the k8s master's components* 38 | ``` 39 | $ kubectl get componentstatus 40 | NAME STATUS MESSAGE ERROR 41 | controller-manager Healthy ok 42 | scheduler Healthy ok 43 | etcd-2 Healthy {"health": "true"} 44 | etcd-0 Healthy {"health": "true"} 45 | etcd-1 Healthy {"health": "true"} 46 | ``` 47 | 48 | *Check the k8s workers* 49 | ``` 50 | $ kubectl get nodes 51 | NAME STATUS ROLES AGE VERSION 52 | k8s-worker1 Ready 19s v1.10.2 53 | k8s-worker2 Ready 20s v1.10.2 54 | k8s-worker3 Ready 20s v1.10.2 55 | 56 | ``` 57 | 58 | *Check DNS add-on* 59 | ``` 60 | $ kubectl get pod -l k8s-app=coredns -n kube-system 61 | NAME READY STATUS RESTARTS AGE 62 | coredns-b8d4b46c8-t2zpf 1/1 Running 0 37m 63 | ``` 64 | 65 | *Check Dashboard* 66 | ``` 67 | $ kubectl get pod -l k8s-app=kubernetes-dashboard -n kube-system 68 | NAME READY STATUS RESTARTS AGE 69 | kubernetes-dashboard-7c5d596d8c-vp85k 1/1 Running 0 8m 70 | ``` 71 | 72 | *Accessing Dashboard* 73 | 74 | Get the port on which the dashbord is exposed 75 | ``` 76 | $ kubectl -n kube-system get service kubernetes-dashboard 77 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 78 | kubernetes-dashboard NodePort 10.32.0.63 443:30585/TCP 23m 79 | ``` 80 | 81 | The Dashbord is accessible at `https://:30585` 82 | 83 | To log in, select Token and insert the token given by the following command: 84 | 85 | ``` 86 | $ kubectl describe serviceaccount kubernetes-dashboard -n kube-system | grep Tokens | awk '{print $2}' | xargs kubectl -n kube-system describe secret | grep '^token' | awk -F ':' '{print $2}' 87 | ``` 88 | 89 | *Check the monitoring pods* 90 | ``` 91 | $ kubectl get pods -l task=monitoring --all-namespaces 92 | NAMESPACE NAME READY STATUS RESTARTS AGE 93 | kube-system heapster-69b5d4974d-kxgjw 1/1 Running 0 2m 94 | kube-system monitoring-grafana-69df66f668-m59hp 1/1 Running 0 2m 95 | kube-system monitoring-influxdb-78d4c6f5b6-gh56w 1/1 Running 0 2m 96 | ``` 97 | 98 | *Access Grafana* 99 | 100 | Get the port on which grafana is exposed: 101 | ``` 102 | $ kubectl -n kube-system get service monitoring-grafana 103 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 104 | monitoring-grafana NodePort 10.32.0.238 80:31244/TCP 7m 105 | ``` 106 | 107 | the dashboard is accessible at `http://:31244` 108 | 109 | ## License 110 | The source code in this repo is licenced under the GPL 3 111 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | 6 | config.vm.box = "ubuntu/xenial64" 7 | config.vm.synced_folder ".", "/vagrant", disabled: true 8 | config.vm.provider "virtualbox" do |vb| 9 | vb.gui = false 10 | vb.memory = "512" 11 | vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] 12 | end 13 | 14 | config.vm.synced_folder ".", "/vagrant", disabled: true 15 | 16 | config.vm.define "lb" do |lb| 17 | lb.vm.hostname = "loadbalancer" 18 | lb.vm.network "private_network", ip: "10.0.0.100" 19 | lb.vm.provider "virtualbox" do |vb| 20 | vb.name = "k8s-loadbalancer" 21 | vb.customize ["modifyvm", :id, "--memory", "256"] 22 | end 23 | end 24 | 25 | config.vm.define "master1" do |master1| 26 | master1.vm.hostname = "k8s-master1" 27 | master1.vm.network "private_network", ip: "10.0.0.101" 28 | master1.vm.provider "virtualbox" do |vb| 29 | vb.name = "k8s-master1" 30 | end 31 | end 32 | 33 | config.vm.define "master2" do |master2| 34 | master2.vm.hostname = "k8s-master2" 35 | master2.vm.network "private_network", ip: "10.0.0.102" 36 | master2.vm.provider "virtualbox" do |vb| 37 | vb.name = "k8s-master2" 38 | end 39 | end 40 | 41 | config.vm.define "master3" do |master3| 42 | master3.vm.hostname = "k8s-master3" 43 | master3.vm.network "private_network", ip: "10.0.0.103" 44 | master3.vm.provider "virtualbox" do |vb| 45 | vb.name = "k8s-master3" 46 | end 47 | end 48 | 49 | config.vm.define "worker1" do |worker1| 50 | worker1.vm.hostname = "k8s-worker1" 51 | worker1.vm.network "private_network", ip: "10.0.0.110" 52 | worker1.vm.provider "virtualbox" do |vb| 53 | vb.name = "k8s-worker1" 54 | end 55 | end 56 | 57 | config.vm.define "worker2" do |worker2| 58 | worker2.vm.hostname = "k8s-worker2" 59 | worker2.vm.network "private_network", ip: "10.0.0.111" 60 | worker2.vm.provider "virtualbox" do |vb| 61 | vb.name = "k8s-worker2" 62 | end 63 | end 64 | 65 | config.vm.define "worker3" do |worker3| 66 | worker3.vm.hostname = "k8s-worker3" 67 | worker3.vm.network "private_network", ip: "10.0.0.112" 68 | worker3.vm.provider "virtualbox" do |vb| 69 | vb.name = "k8s-worker3" 70 | end 71 | end 72 | 73 | config.vm.provision "ansible" do |ansible| 74 | ansible.playbook = "ssh.yml" 75 | end 76 | 77 | end 78 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | # config file for ansible -- https://ansible.com/ 2 | # =============================================== 3 | 4 | # nearly all parameters can be overridden in ansible-playbook 5 | # or with command line flags. ansible will read ANSIBLE_CONFIG, 6 | # ansible.cfg in the current working directory, .ansible.cfg in 7 | # the home directory or /etc/ansible/ansible.cfg, whichever it 8 | # finds first 9 | 10 | [defaults] 11 | 12 | # some basic default values... 13 | 14 | inventory = ./hosts 15 | #library = /usr/share/my_modules/ 16 | #module_utils = /usr/share/my_module_utils/ 17 | #remote_tmp = ~/.ansible/tmp 18 | #local_tmp = ~/.ansible/tmp 19 | #forks = 5 20 | #poll_interval = 15 21 | #sudo_user = root 22 | #ask_sudo_pass = True 23 | #ask_pass = True 24 | #transport = smart 25 | #remote_port = 22 26 | #module_lang = C 27 | #module_set_locale = False 28 | 29 | # plays will gather facts by default, which contain information about 30 | # the remote system. 31 | # 32 | # smart - gather by default, but don't regather if already gathered 33 | # implicit - gather by default, turn off with gather_facts: False 34 | # explicit - do not gather by default, must say gather_facts: True 35 | #gathering = implicit 36 | 37 | # This only affects the gathering done by a play's gather_facts directive, 38 | # by default gathering retrieves all facts subsets 39 | # all - gather all subsets 40 | # network - gather min and network facts 41 | # hardware - gather hardware facts (longest facts to retrieve) 42 | # virtual - gather min and virtual facts 43 | # facter - import facts from facter 44 | # ohai - import facts from ohai 45 | # You can combine them using comma (ex: network,virtual) 46 | # You can negate them using ! (ex: !hardware,!facter,!ohai) 47 | # A minimal set of facts is always gathered. 48 | #gather_subset = all 49 | 50 | # some hardware related facts are collected 51 | # with a maximum timeout of 10 seconds. This 52 | # option lets you increase or decrease that 53 | # timeout to something more suitable for the 54 | # environment. 55 | # gather_timeout = 10 56 | 57 | # additional paths to search for roles in, colon separated 58 | #roles_path = /etc/ansible/roles 59 | 60 | # uncomment this to disable SSH key host checking 61 | host_key_checking = False 62 | 63 | # change the default callback 64 | #stdout_callback = skippy 65 | # enable additional callbacks 66 | #callback_whitelist = timer, mail 67 | 68 | # Determine whether includes in tasks and handlers are "static" by 69 | # default. As of 2.0, includes are dynamic by default. Setting these 70 | # values to True will make includes behave more like they did in the 71 | # 1.x versions. 72 | #task_includes_static = True 73 | #handler_includes_static = True 74 | 75 | # Controls if a missing handler for a notification event is an error or a warning 76 | #error_on_missing_handler = True 77 | 78 | # change this for alternative sudo implementations 79 | #sudo_exe = sudo 80 | 81 | # What flags to pass to sudo 82 | # WARNING: leaving out the defaults might create unexpected behaviours 83 | #sudo_flags = -H -S -n 84 | 85 | # SSH timeout 86 | #timeout = 10 87 | 88 | # default user to use for playbooks if user is not specified 89 | # (/usr/bin/ansible will use current user as default) 90 | #remote_user = root 91 | 92 | # logging is off by default unless this path is defined 93 | # if so defined, consider logrotate 94 | #log_path = /var/log/ansible.log 95 | 96 | # default module name for /usr/bin/ansible 97 | #module_name = command 98 | 99 | # use this shell for commands executed under sudo 100 | # you may need to change this to bin/bash in rare instances 101 | # if sudo is constrained 102 | #executable = /bin/sh 103 | 104 | # if inventory variables overlap, does the higher precedence one win 105 | # or are hash values merged together? The default is 'replace' but 106 | # this can also be set to 'merge'. 107 | #hash_behaviour = replace 108 | 109 | # by default, variables from roles will be visible in the global variable 110 | # scope. To prevent this, the following option can be enabled, and only 111 | # tasks and handlers within the role will see the variables there 112 | #private_role_vars = yes 113 | 114 | # list any Jinja2 extensions to enable here: 115 | #jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n 116 | 117 | # if set, always use this private key file for authentication, same as 118 | # if passing --private-key to ansible or ansible-playbook 119 | #private_key_file = /path/to/file 120 | 121 | # If set, configures the path to the Vault password file as an alternative to 122 | # specifying --vault-password-file on the command line. 123 | #vault_password_file = /path/to/vault_password_file 124 | 125 | # format of string {{ ansible_managed }} available within Jinja2 126 | # templates indicates to users editing templates files will be replaced. 127 | # replacing {file}, {host} and {uid} and strftime codes with proper values. 128 | #ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host} 129 | # {file}, {host}, {uid}, and the timestamp can all interfere with idempotence 130 | # in some situations so the default is a static string: 131 | #ansible_managed = Ansible managed 132 | 133 | # by default, ansible-playbook will display "Skipping [host]" if it determines a task 134 | # should not be run on a host. Set this to "False" if you don't want to see these "Skipping" 135 | # messages. NOTE: the task header will still be shown regardless of whether or not the 136 | # task is skipped. 137 | #display_skipped_hosts = True 138 | 139 | # by default, if a task in a playbook does not include a name: field then 140 | # ansible-playbook will construct a header that includes the task's action but 141 | # not the task's args. This is a security feature because ansible cannot know 142 | # if the *module* considers an argument to be no_log at the time that the 143 | # header is printed. If your environment doesn't have a problem securing 144 | # stdout from ansible-playbook (or you have manually specified no_log in your 145 | # playbook on all of the tasks where you have secret information) then you can 146 | # safely set this to True to get more informative messages. 147 | #display_args_to_stdout = False 148 | 149 | # by default (as of 1.3), Ansible will raise errors when attempting to dereference 150 | # Jinja2 variables that are not set in templates or action lines. Uncomment this line 151 | # to revert the behavior to pre-1.3. 152 | #error_on_undefined_vars = False 153 | 154 | # by default (as of 1.6), Ansible may display warnings based on the configuration of the 155 | # system running ansible itself. This may include warnings about 3rd party packages or 156 | # other conditions that should be resolved if possible. 157 | # to disable these warnings, set the following value to False: 158 | #system_warnings = True 159 | 160 | # by default (as of 1.4), Ansible may display deprecation warnings for language 161 | # features that should no longer be used and will be removed in future versions. 162 | # to disable these warnings, set the following value to False: 163 | #deprecation_warnings = True 164 | 165 | # (as of 1.8), Ansible can optionally warn when usage of the shell and 166 | # command module appear to be simplified by using a default Ansible module 167 | # instead. These warnings can be silenced by adjusting the following 168 | # setting or adding warn=yes or warn=no to the end of the command line 169 | # parameter string. This will for example suggest using the git module 170 | # instead of shelling out to the git command. 171 | # command_warnings = False 172 | 173 | 174 | # set plugin path directories here, separate with colons 175 | #action_plugins = /usr/share/ansible/plugins/action 176 | #cache_plugins = /usr/share/ansible/plugins/cache 177 | #callback_plugins = /usr/share/ansible/plugins/callback 178 | #connection_plugins = /usr/share/ansible/plugins/connection 179 | #lookup_plugins = /usr/share/ansible/plugins/lookup 180 | #inventory_plugins = /usr/share/ansible/plugins/inventory 181 | #vars_plugins = /usr/share/ansible/plugins/vars 182 | #filter_plugins = /usr/share/ansible/plugins/filter 183 | #test_plugins = /usr/share/ansible/plugins/test 184 | #terminal_plugins = /usr/share/ansible/plugins/terminal 185 | #strategy_plugins = /usr/share/ansible/plugins/strategy 186 | 187 | 188 | # by default, ansible will use the 'linear' strategy but you may want to try 189 | # another one 190 | #strategy = free 191 | 192 | # by default callbacks are not loaded for /bin/ansible, enable this if you 193 | # want, for example, a notification or logging callback to also apply to 194 | # /bin/ansible runs 195 | #bin_ansible_callbacks = False 196 | 197 | 198 | # don't like cows? that's unfortunate. 199 | # set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1 200 | #nocows = 1 201 | 202 | # set which cowsay stencil you'd like to use by default. When set to 'random', 203 | # a random stencil will be selected for each task. The selection will be filtered 204 | # against the `cow_whitelist` option below. 205 | #cow_selection = default 206 | #cow_selection = random 207 | 208 | # when using the 'random' option for cowsay, stencils will be restricted to this list. 209 | # it should be formatted as a comma-separated list with no spaces between names. 210 | # NOTE: line continuations here are for formatting purposes only, as the INI parser 211 | # in python does not support them. 212 | #cow_whitelist=bud-frogs,bunny,cheese,daemon,default,dragon,elephant-in-snake,elephant,eyes,\ 213 | # hellokitty,kitty,luke-koala,meow,milk,moofasa,moose,ren,sheep,small,stegosaurus,\ 214 | # stimpy,supermilker,three-eyes,turkey,turtle,tux,udder,vader-koala,vader,www 215 | 216 | # don't like colors either? 217 | # set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1 218 | #nocolor = 1 219 | 220 | # if set to a persistent type (not 'memory', for example 'redis') fact values 221 | # from previous runs in Ansible will be stored. This may be useful when 222 | # wanting to use, for example, IP information from one group of servers 223 | # without having to talk to them in the same playbook run to get their 224 | # current IP information. 225 | #fact_caching = memory 226 | 227 | 228 | # retry files 229 | # When a playbook fails by default a .retry file will be created in ~/ 230 | # You can disable this feature by setting retry_files_enabled to False 231 | # and you can change the location of the files by setting retry_files_save_path 232 | 233 | retry_files_enabled = False 234 | #retry_files_save_path = ~/.ansible-retry 235 | 236 | # squash actions 237 | # Ansible can optimise actions that call modules with list parameters 238 | # when looping. Instead of calling the module once per with_ item, the 239 | # module is called once with all items at once. Currently this only works 240 | # under limited circumstances, and only with parameters named 'name'. 241 | #squash_actions = apk,apt,dnf,homebrew,pacman,pkgng,yum,zypper 242 | 243 | # prevents logging of task data, off by default 244 | #no_log = False 245 | 246 | # prevents logging of tasks, but only on the targets, data is still logged on the master/controller 247 | #no_target_syslog = False 248 | 249 | # controls whether Ansible will raise an error or warning if a task has no 250 | # choice but to create world readable temporary files to execute a module on 251 | # the remote machine. This option is False by default for security. Users may 252 | # turn this on to have behaviour more like Ansible prior to 2.1.x. See 253 | # https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user 254 | # for more secure ways to fix this than enabling this option. 255 | #allow_world_readable_tmpfiles = False 256 | 257 | # controls the compression level of variables sent to 258 | # worker processes. At the default of 0, no compression 259 | # is used. This value must be an integer from 0 to 9. 260 | #var_compression_level = 9 261 | 262 | # controls what compression method is used for new-style ansible modules when 263 | # they are sent to the remote system. The compression types depend on having 264 | # support compiled into both the controller's python and the client's python. 265 | # The names should match with the python Zipfile compression types: 266 | # * ZIP_STORED (no compression. available everywhere) 267 | # * ZIP_DEFLATED (uses zlib, the default) 268 | # These values may be set per host via the ansible_module_compression inventory 269 | # variable 270 | #module_compression = 'ZIP_DEFLATED' 271 | 272 | # This controls the cutoff point (in bytes) on --diff for files 273 | # set to 0 for unlimited (RAM may suffer!). 274 | #max_diff_size = 1048576 275 | 276 | # This controls how ansible handles multiple --tags and --skip-tags arguments 277 | # on the CLI. If this is True then multiple arguments are merged together. If 278 | # it is False, then the last specified argument is used and the others are ignored. 279 | #merge_multiple_cli_flags = False 280 | 281 | # Controls showing custom stats at the end, off by default 282 | #show_custom_stats = True 283 | 284 | # Controlls which files to ignore when using a directory as inventory with 285 | # possibly multiple sources (both static and dynamic) 286 | #inventory_ignore_extensions = ~, .orig, .bak, .ini, .cfg, .retry, .pyc, .pyo 287 | 288 | # This family of modules use an alternative execution path optimized for network appliances 289 | # only update this setting if you know how this works, otherwise it can break module execution 290 | #network_group_modules=['eos', 'nxos', 'ios', 'iosxr', 'junos', 'vyos'] 291 | 292 | [privilege_escalation] 293 | #become=True 294 | #become_method=sudo 295 | #become_user=root 296 | #become_ask_pass=False 297 | 298 | [paramiko_connection] 299 | 300 | # uncomment this line to cause the paramiko connection plugin to not record new host 301 | # keys encountered. Increases performance on new host additions. Setting works independently of the 302 | # host key checking setting above. 303 | #record_host_keys=False 304 | 305 | # by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this 306 | # line to disable this behaviour. 307 | #pty=False 308 | 309 | # paramiko will default to looking for SSH keys initially when trying to 310 | # authenticate to remote devices. This is a problem for some network devices 311 | # that close the connection after a key failure. Uncomment this line to 312 | # disable the Paramiko look for keys function 313 | #look_for_keys = False 314 | 315 | # When using persistent connections with Paramiko, the connection runs in a 316 | # background process. If the host doesn't already have a valid SSH key, by 317 | # default Ansible will prompt to add the host key. This will cause connections 318 | # running in background processes to fail. Uncomment this line to have 319 | # Paramiko automatically add host keys. 320 | #host_key_auto_add = True 321 | 322 | [ssh_connection] 323 | 324 | # ssh arguments to use 325 | # Leaving off ControlPersist will result in poor performance, so use 326 | # paramiko on older platforms rather than removing it, -C controls compression use 327 | #ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s 328 | 329 | # The base directory for the ControlPath sockets. 330 | # This is the "%(directory)s" in the control_path option 331 | # 332 | # Example: 333 | # control_path_dir = /tmp/.ansible/cp 334 | #control_path_dir = ~/.ansible/cp 335 | 336 | # The path to use for the ControlPath sockets. This defaults to a hashed string of the hostname, 337 | # port and username (empty string in the config). The hash mitigates a common problem users 338 | # found with long hostames and the conventional %(directory)s/ansible-ssh-%%h-%%p-%%r format. 339 | # In those cases, a "too long for Unix domain socket" ssh error would occur. 340 | # 341 | # Example: 342 | # control_path = %(directory)s/%%h-%%r 343 | #control_path = 344 | 345 | # Enabling pipelining reduces the number of SSH operations required to 346 | # execute a module on the remote server. This can result in a significant 347 | # performance improvement when enabled, however when using "sudo:" you must 348 | # first disable 'requiretty' in /etc/sudoers 349 | # 350 | # By default, this option is disabled to preserve compatibility with 351 | # sudoers configurations that have requiretty (the default on many distros). 352 | # 353 | #pipelining = False 354 | 355 | # Control the mechanism for transferring files (old) 356 | # * smart = try sftp and then try scp [default] 357 | # * True = use scp only 358 | # * False = use sftp only 359 | #scp_if_ssh = smart 360 | 361 | # Control the mechanism for transferring files (new) 362 | # If set, this will override the scp_if_ssh option 363 | # * sftp = use sftp to transfer files 364 | # * scp = use scp to transfer files 365 | # * piped = use 'dd' over SSH to transfer files 366 | # * smart = try sftp, scp, and piped, in that order [default] 367 | #transfer_method = smart 368 | 369 | # if False, sftp will not use batch mode to transfer files. This may cause some 370 | # types of file transfer failures impossible to catch however, and should 371 | # only be disabled if your sftp version has problems with batch mode 372 | #sftp_batch_mode = False 373 | 374 | [persistent_connection] 375 | 376 | # Configures the persistent connection timeout value in seconds. This value is 377 | # how long the persistent connection will remain idle before it is destroyed. 378 | # If the connection doesn't receive a request before the timeout value 379 | # expires, the connection is shutdown. The default value is 30 seconds. 380 | connect_timeout = 30 381 | 382 | # Configures the persistent connection retries. This value configures the 383 | # number of attempts the ansible-connection will make when trying to connect 384 | # to the local domain socket. The default value is 30. 385 | connect_retries = 30 386 | 387 | # Configures the amount of time in seconds to wait between connection attempts 388 | # to the local unix domain socket. This value works in conjunction with the 389 | # connect_retries value to define how long to try to connect to the local 390 | # domain socket when setting up a persistent connection. The default value is 391 | # 1 second. 392 | connect_interval = 1 393 | 394 | [accelerate] 395 | #accelerate_port = 5099 396 | #accelerate_timeout = 30 397 | #accelerate_connect_timeout = 5.0 398 | 399 | # The daemon timeout is measured in minutes. This time is measured 400 | # from the last activity to the accelerate daemon. 401 | #accelerate_daemon_timeout = 30 402 | 403 | # If set to yes, accelerate_multi_key will allow multiple 404 | # private keys to be uploaded to it, though each user must 405 | # have access to the system via SSH to add a new key. The default 406 | # is "no". 407 | #accelerate_multi_key = yes 408 | 409 | [selinux] 410 | # file systems that require special treatment when dealing with security context 411 | # the default behaviour that copies the existing context or uses the user default 412 | # needs to be changed to use the file system dependent context. 413 | #special_context_filesystems=nfs,vboxsf,fuse,ramfs,9p 414 | 415 | # Set this to yes to allow libvirt_lxc connections to work without SELinux. 416 | #libvirt_lxc_noseclabel = yes 417 | 418 | [colors] 419 | #highlight = white 420 | #verbose = blue 421 | #warn = bright purple 422 | #error = red 423 | #debug = dark gray 424 | #deprecate = purple 425 | #skip = cyan 426 | #unreachable = red 427 | #ok = green 428 | #changed = yellow 429 | #diff_add = green 430 | #diff_remove = red 431 | #diff_lines = cyan 432 | 433 | 434 | [diff] 435 | # Always print diff when running ( same as always running with -D/--diff ) 436 | # always = no 437 | 438 | # Set how many context lines to show in diff 439 | # context = 3 440 | -------------------------------------------------------------------------------- /docs/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythops/Kubernetes-the-hard-way-with-Ansible/5e836713b7452564b219d02694c47c4624664b4b/docs/architecture.png -------------------------------------------------------------------------------- /group_vars/all: -------------------------------------------------------------------------------- 1 | CLUSETER_IP: 10.32.0.0/24 2 | 3 | APISERVER_SERVICE_IP: 10.32.0.1 4 | 5 | # PKI directory 6 | PKI_DIR: '{{ playbook_dir }}/pki' 7 | 8 | # Kubeconfig directory 9 | CONF_DIR: '{{ playbook_dir }}/kubeconfig' 10 | 11 | # Binaries directory 12 | BIN_DIR: '{{ playbook_dir }}/bin' 13 | -------------------------------------------------------------------------------- /hosts: -------------------------------------------------------------------------------- 1 | [all:vars] 2 | ansible_python_interpreter=/usr/bin/python3 3 | 4 | [loadbalancer] 5 | 10.0.0.100 6 | 7 | [k8s-masters] 8 | 10.0.0.101 9 | 10.0.0.102 10 | 10.0.0.103 11 | 12 | [k8s-workers] 13 | 10.0.0.110 14 | 10.0.0.111 15 | 10.0.0.112 16 | -------------------------------------------------------------------------------- /k8s.yml: -------------------------------------------------------------------------------- 1 | - name: Create the PKI 2 | hosts: localhost 3 | connection: local 4 | roles: 5 | - pki 6 | 7 | - name: Generate the Kubeconfig files 8 | hosts: localhost 9 | connection: local 10 | roles: 11 | - kubeconfig 12 | 13 | - name: Download the k8s components 14 | hosts: localhost 15 | connection: local 16 | roles: 17 | - k8s-download 18 | 19 | - name: Deploy loadbalancer 20 | hosts: loadbalancer 21 | remote_user: vagrant 22 | become: yes 23 | roles: 24 | - loadbalancer 25 | 26 | - name: Deploy Etcd cluster 27 | hosts: k8s-masters 28 | remote_user: vagrant 29 | become: yes 30 | roles: 31 | - etcd 32 | 33 | - name: Deploy k8s master components 34 | hosts: k8s-masters 35 | remote_user: vagrant 36 | become: yes 37 | roles: 38 | - k8s-master 39 | 40 | - name: Deploy k8s worker components 41 | hosts: k8s-workers 42 | remote_user: vagrant 43 | become: yes 44 | roles: 45 | - k8s-worker 46 | 47 | - name: Install add-ons 48 | hosts: localhost 49 | roles: 50 | - addons 51 | 52 | - name: Setup the monitoring stack 53 | hosts: localhost 54 | roles: 55 | - k8s-monitoring 56 | -------------------------------------------------------------------------------- /roles/addons/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Install CoreDNS add-on 2 | shell: "kubectl apply -f roles/addons/templates/coredns.yml" 3 | 4 | - name: Store Dashboard certificate in a secret 5 | shell: "kubectl create secret generic kubernetes-dashboard-certs --from-file={{ PKI_DIR }}/k8s-dashboard.bundle -n kube-system" 6 | register: create_secret 7 | failed_when: "'already exists' not in create_secret.stderr" 8 | 9 | - name: Install Dashboard 10 | shell: "kubectl apply -f roles/addons/templates/kubernetes-dashboard.yml" 11 | 12 | - name: Granting admin privileges to Dashboard's Service Account 13 | shell: "kubectl apply -f roles/addons/templates/dashboard-admin.yml" 14 | -------------------------------------------------------------------------------- /roles/addons/templates/coredns.yml: -------------------------------------------------------------------------------- 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 | --- 25 | apiVersion: rbac.authorization.k8s.io/v1beta1 26 | kind: ClusterRoleBinding 27 | metadata: 28 | annotations: 29 | rbac.authorization.kubernetes.io/autoupdate: "true" 30 | labels: 31 | kubernetes.io/bootstrapping: rbac-defaults 32 | name: system:coredns 33 | roleRef: 34 | apiGroup: rbac.authorization.k8s.io 35 | kind: ClusterRole 36 | name: system:coredns 37 | subjects: 38 | - kind: ServiceAccount 39 | name: coredns 40 | namespace: kube-system 41 | --- 42 | apiVersion: v1 43 | kind: ConfigMap 44 | metadata: 45 | name: coredns 46 | namespace: kube-system 47 | data: 48 | Corefile: | 49 | .:53 { 50 | errors 51 | log 52 | health 53 | kubernetes cluster.local 10.32.0.0/24 10.244.0.0/16 54 | proxy . /etc/resolv.conf 55 | cache 30 56 | } 57 | --- 58 | apiVersion: extensions/v1beta1 59 | kind: Deployment 60 | metadata: 61 | name: coredns 62 | namespace: kube-system 63 | labels: 64 | k8s-app: coredns 65 | kubernetes.io/name: "CoreDNS" 66 | spec: 67 | replicas: 1 68 | selector: 69 | matchLabels: 70 | k8s-app: coredns 71 | template: 72 | metadata: 73 | labels: 74 | k8s-app: coredns 75 | spec: 76 | serviceAccountName: coredns 77 | tolerations: 78 | - key: node-role.kubernetes.io/master 79 | effect: NoSchedule 80 | - key: "CriticalAddonsOnly" 81 | operator: "Exists" 82 | containers: 83 | - name: coredns 84 | image: coredns/coredns:0.9.10 85 | imagePullPolicy: Always 86 | args: [ "-conf", "/etc/coredns/Corefile" ] 87 | volumeMounts: 88 | - name: config-volume 89 | mountPath: /etc/coredns 90 | ports: 91 | - containerPort: 53 92 | name: dns 93 | protocol: UDP 94 | - containerPort: 53 95 | name: dns-tcp 96 | protocol: TCP 97 | - containerPort: 9153 98 | name: metrics 99 | protocol: TCP 100 | livenessProbe: 101 | httpGet: 102 | path: /health 103 | port: 8080 104 | scheme: HTTP 105 | initialDelaySeconds: 60 106 | timeoutSeconds: 5 107 | successThreshold: 1 108 | failureThreshold: 5 109 | dnsPolicy: Default 110 | volumes: 111 | - name: config-volume 112 | configMap: 113 | name: coredns 114 | items: 115 | - key: Corefile 116 | path: Corefile 117 | --- 118 | apiVersion: v1 119 | kind: Service 120 | metadata: 121 | name: kube-dns 122 | namespace: kube-system 123 | labels: 124 | k8s-app: coredns 125 | kubernetes.io/cluster-service: "true" 126 | kubernetes.io/name: "CoreDNS" 127 | spec: 128 | selector: 129 | k8s-app: coredns 130 | clusterIP: 10.32.0.10 131 | ports: 132 | - name: dns 133 | port: 53 134 | protocol: UDP 135 | - name: dns-tcp 136 | port: 53 137 | protocol: TCP 138 | - name: metrics 139 | port: 9153 140 | protocol: TCP 141 | -------------------------------------------------------------------------------- /roles/addons/templates/dashboard-admin.yml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1beta1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | name: kubernetes-dashboard 5 | labels: 6 | k8s-app: kubernetes-dashboard 7 | roleRef: 8 | apiGroup: rbac.authorization.k8s.io 9 | kind: ClusterRole 10 | name: cluster-admin 11 | subjects: 12 | - kind: ServiceAccount 13 | name: kubernetes-dashboard 14 | namespace: kube-system 15 | -------------------------------------------------------------------------------- /roles/addons/templates/kubernetes-dashboard.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Kubernetes Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Configuration to deploy release version of the Dashboard UI compatible with 16 | # Kubernetes 1.8. 17 | # 18 | # Example usage: kubectl create -f 19 | 20 | # ------------------- Dashboard Secret ------------------- # 21 | 22 | apiVersion: v1 23 | kind: Secret 24 | metadata: 25 | labels: 26 | k8s-app: kubernetes-dashboard 27 | name: kubernetes-dashboard-certs 28 | namespace: kube-system 29 | type: Opaque 30 | 31 | --- 32 | # ------------------- Dashboard Service Account ------------------- # 33 | 34 | apiVersion: v1 35 | kind: ServiceAccount 36 | metadata: 37 | labels: 38 | k8s-app: kubernetes-dashboard 39 | name: kubernetes-dashboard 40 | namespace: kube-system 41 | 42 | --- 43 | # ------------------- Dashboard Role & Role Binding ------------------- # 44 | 45 | kind: Role 46 | apiVersion: rbac.authorization.k8s.io/v1 47 | metadata: 48 | name: kubernetes-dashboard-minimal 49 | namespace: kube-system 50 | rules: 51 | # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret. 52 | - apiGroups: [""] 53 | resources: ["secrets"] 54 | verbs: ["create"] 55 | # Allow Dashboard to create 'kubernetes-dashboard-settings' config map. 56 | - apiGroups: [""] 57 | resources: ["configmaps"] 58 | verbs: ["create"] 59 | # Allow Dashboard to get, update and delete Dashboard exclusive secrets. 60 | - apiGroups: [""] 61 | resources: ["secrets"] 62 | resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"] 63 | verbs: ["get", "update", "delete"] 64 | # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map. 65 | - apiGroups: [""] 66 | resources: ["configmaps"] 67 | resourceNames: ["kubernetes-dashboard-settings"] 68 | verbs: ["get", "update"] 69 | # Allow Dashboard to get metrics from heapster. 70 | - apiGroups: [""] 71 | resources: ["services"] 72 | resourceNames: ["heapster"] 73 | verbs: ["proxy"] 74 | - apiGroups: [""] 75 | resources: ["services/proxy"] 76 | resourceNames: ["heapster", "http:heapster:", "https:heapster:"] 77 | verbs: ["get"] 78 | 79 | --- 80 | apiVersion: rbac.authorization.k8s.io/v1 81 | kind: RoleBinding 82 | metadata: 83 | name: kubernetes-dashboard-minimal 84 | namespace: kube-system 85 | roleRef: 86 | apiGroup: rbac.authorization.k8s.io 87 | kind: Role 88 | name: kubernetes-dashboard-minimal 89 | subjects: 90 | - kind: ServiceAccount 91 | name: kubernetes-dashboard 92 | namespace: kube-system 93 | 94 | --- 95 | # ------------------- Dashboard Deployment ------------------- # 96 | 97 | kind: Deployment 98 | apiVersion: apps/v1beta2 99 | metadata: 100 | labels: 101 | k8s-app: kubernetes-dashboard 102 | name: kubernetes-dashboard 103 | namespace: kube-system 104 | spec: 105 | replicas: 1 106 | revisionHistoryLimit: 10 107 | selector: 108 | matchLabels: 109 | k8s-app: kubernetes-dashboard 110 | template: 111 | metadata: 112 | labels: 113 | k8s-app: kubernetes-dashboard 114 | spec: 115 | containers: 116 | - name: kubernetes-dashboard 117 | image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3 118 | ports: 119 | - containerPort: 8443 120 | protocol: TCP 121 | args: 122 | - --auto-generate-certificates 123 | # Uncomment the following line to manually specify Kubernetes API server Host 124 | # If not specified, Dashboard will attempt to auto discover the API server and connect 125 | # to it. Uncomment only if the default does not work. 126 | # - --apiserver-host=http://my-address:port 127 | volumeMounts: 128 | - name: kubernetes-dashboard-certs 129 | mountPath: /certs 130 | # Create on-disk volume to store exec logs 131 | - mountPath: /tmp 132 | name: tmp-volume 133 | livenessProbe: 134 | httpGet: 135 | scheme: HTTPS 136 | path: / 137 | port: 8443 138 | initialDelaySeconds: 30 139 | timeoutSeconds: 30 140 | volumes: 141 | - name: kubernetes-dashboard-certs 142 | secret: 143 | secretName: kubernetes-dashboard-certs 144 | - name: tmp-volume 145 | emptyDir: {} 146 | serviceAccountName: kubernetes-dashboard 147 | # Comment the following tolerations if Dashboard must not be deployed on master 148 | tolerations: 149 | - key: node-role.kubernetes.io/master 150 | effect: NoSchedule 151 | 152 | --- 153 | # ------------------- Dashboard Service ------------------- # 154 | 155 | kind: Service 156 | apiVersion: v1 157 | metadata: 158 | labels: 159 | k8s-app: kubernetes-dashboard 160 | name: kubernetes-dashboard 161 | namespace: kube-system 162 | spec: 163 | ports: 164 | - port: 443 165 | targetPort: 8443 166 | selector: 167 | k8s-app: kubernetes-dashboard 168 | type: NodePort 169 | -------------------------------------------------------------------------------- /roles/docker/defaults/main.yml: -------------------------------------------------------------------------------- 1 | docker_key: "https://download.docker.com/linux/ubuntu/gpg" 2 | docker_repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" 3 | -------------------------------------------------------------------------------- /roles/docker/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: restart docker 4 | systemd: 5 | daemon_reload: yes 6 | name: docker 7 | state: restarted 8 | enabled: yes 9 | 10 | -------------------------------------------------------------------------------- /roles/docker/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | dependencies: 4 | - { role: flannel } 5 | -------------------------------------------------------------------------------- /roles/docker/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Add Docker key 4 | apt_key: 5 | url: "{{ docker_key }}" 6 | state: present 7 | 8 | - name: Add Docker repository 9 | apt_repository: 10 | repo: "{{ docker_repo }}" 11 | state: present 12 | update_cache: yes 13 | 14 | - name: Install Docker 15 | apt: 16 | name: docker-ce 17 | state: present 18 | 19 | - name: copy systemd unit file 20 | template: 21 | src: "lib/systemd/system/docker.service.j2" 22 | dest: "/lib/systemd/system/docker.service" 23 | owner: root 24 | group: root 25 | mode: 0644 26 | notify: 27 | - restart docker 28 | tags: 29 | - config 30 | 31 | - name: Download gvisor 32 | get_url: 33 | url: https://storage.googleapis.com/gvisor/releases/nightly/latest/runsc 34 | dest: /usr/local/bin/ 35 | owner: root 36 | group: root 37 | mode: 0755 38 | 39 | - name: Configure gvisor for docker 40 | copy: 41 | content: | 42 | { 43 | "runtimes": { 44 | "runsc": { 45 | "path": "/usr/local/bin/runsc" 46 | } 47 | } 48 | } 49 | dest: /etc/docker/daemon.json 50 | owner: root 51 | group: root 52 | mode: 0644 53 | notify: 54 | - restart docker 55 | 56 | - meta: flush_handlers 57 | -------------------------------------------------------------------------------- /roles/docker/templates/lib/systemd/system/docker.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Docker Application Container Engine 5 | Documentation=https://docs.docker.com 6 | After=network-online.target docker.socket 7 | Wants=network-online.target 8 | Requires=docker.socket 9 | 10 | [Service] 11 | Type=notify 12 | EnvironmentFile=-/run/flannel/subnet.env 13 | ExecStart=/usr/bin/dockerd -H fd:// --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} 14 | ExecReload=/bin/kill -s HUP $MAINPID 15 | LimitNOFILE=1048576 16 | LimitNPROC=infinity 17 | LimitCORE=infinity 18 | TasksMax=infinity 19 | TimeoutStartSec=0 20 | Delegate=yes 21 | KillMode=process 22 | Restart=on-failure 23 | StartLimitBurst=3 24 | StartLimitInterval=60s 25 | 26 | [Install] 27 | WantedBy=multi-user.target 28 | -------------------------------------------------------------------------------- /roles/etcd/handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart etcd 2 | systemd: 3 | name: etcd 4 | daemon_reload: yes 5 | state: restarted 6 | enabled: yes 7 | -------------------------------------------------------------------------------- /roles/etcd/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Copy etcd binaries 2 | copy: 3 | src: '{{ BIN_DIR }}/etcd' 4 | dest: /usr/local/bin/ 5 | owner: root 6 | group: root 7 | mode: 0755 8 | 9 | - name: Create config directory 10 | file: 11 | path: /etc/etcd 12 | state: directory 13 | owner: root 14 | group: root 15 | mode: 0755 16 | 17 | - name: Create etcd user 18 | user: 19 | name: etcd 20 | shell: /usr/sbin/nologin 21 | comment: "etcd user" 22 | createhome: no 23 | system: yes 24 | state: present 25 | 26 | - name: Create /var/lib/etcd directory 27 | file: 28 | path: /var/lib/etcd 29 | state: directory 30 | owner: etcd 31 | group: etcd 32 | mode: 0755 33 | 34 | - name: Copy certificates and keys 35 | copy: 36 | src: "{{ item }}" 37 | dest: /etc/etcd 38 | owner: root 39 | group: root 40 | mode: 0644 41 | loop: 42 | - '{{ PKI_DIR }}/ca.pem' 43 | - '{{ PKI_DIR }}/k8s-master-key.pem' 44 | - '{{ PKI_DIR }}/k8s-master.pem' 45 | 46 | - name: Copy systemd unit file 47 | template: 48 | src: "lib/systemd/system/etcd.service.j2" 49 | dest: "/lib/systemd/system/etcd.service" 50 | owner: root 51 | group: root 52 | mode: 0644 53 | notify: 54 | - restart etcd 55 | tags: 56 | - config 57 | -------------------------------------------------------------------------------- /roles/etcd/templates/lib/systemd/system/etcd.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=etcd 5 | Documentation=https://github.com/coreos 6 | 7 | [Service] 8 | Type=notify 9 | User=etcd 10 | Group=etcd 11 | ExecStart=/usr/local/bin/etcd \ 12 | --name {{ ansible_hostname }} \ 13 | --cert-file=/etc/etcd/k8s-master.pem \ 14 | --key-file=/etc/etcd/k8s-master-key.pem \ 15 | --peer-cert-file=/etc/etcd/k8s-master.pem \ 16 | --peer-key-file=/etc/etcd/k8s-master-key.pem \ 17 | --trusted-ca-file=/etc/etcd/ca.pem \ 18 | --peer-trusted-ca-file=/etc/etcd/ca.pem \ 19 | --peer-client-cert-auth \ 20 | --client-cert-auth \ 21 | --initial-advertise-peer-urls https://{{ inventory_hostname }}:2380 \ 22 | --listen-peer-urls https://{{ inventory_hostname }}:2380 \ 23 | --listen-client-urls https://{{ inventory_hostname }}:2379,http://127.0.0.1:2379 \ 24 | --advertise-client-urls https://{{ inventory_hostname }}:2379 \ 25 | --initial-cluster-token etcd-cluster-0 \ 26 | --initial-cluster k8s-master1=https://{{ groups['k8s-masters'][0] }}:2380,k8s-master2=https://{{ groups['k8s-masters'][1] }}:2380,k8s-master3=https://{{ groups['k8s-masters'][2] }}:2380 \ 27 | --initial-cluster-state new \ 28 | --data-dir=/var/lib/etcd 29 | Restart=on-failure 30 | RestartSec=5 31 | ProtectSystem=full 32 | ReadWritePaths=/var/lib/etcd 33 | PrivateTmp=true 34 | ProtectHome=true 35 | PrivateDevices=true 36 | ProtectKernelTunables=true 37 | ProtectKernelModules=true 38 | ProtectControlGroups=true 39 | NoNewPrivileges=true 40 | LimitNOFILE=40000 41 | 42 | 43 | [Install] 44 | WantedBy=multi-user.target 45 | -------------------------------------------------------------------------------- /roles/flannel/defaults/main.yml: -------------------------------------------------------------------------------- 1 | ETCD_NET_CONFIG: > 2 | { 3 | "Network": "10.200.0.0/16", 4 | "SubnetLen": 24, 5 | "Backend": { 6 | "Type": "vxlan", 7 | "VNI": 1 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /roles/flannel/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: restart flannel 4 | systemd: 5 | daemon_reload: yes 6 | enabled: yes 7 | name: flannel 8 | state: restarted 9 | -------------------------------------------------------------------------------- /roles/flannel/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Copy flanneld binary 4 | copy: 5 | src: "{{ BIN_DIR }}/flanneld" 6 | dest: "/usr/local/bin/" 7 | owner: root 8 | group: root 9 | mode: 0755 10 | 11 | - name: Set flannel network conf on etcd 12 | uri: 13 | client_cert: /var/lib/kubelet/{{ ansible_hostname }}.pem 14 | client_key: /var/lib/kubelet/{{ ansible_hostname }}-key.pem 15 | validate_certs: no 16 | url: https://10.0.0.100:2379/v2/keys/kubernetes-cluster/network/config 17 | body: "value={{ ETCD_NET_CONFIG }}" 18 | status_code: 200,201 19 | method: PUT 20 | return_content: yes 21 | run_once: true 22 | 23 | - name: Copy flannel systemd unit file 24 | template: 25 | src: "lib/systemd/system/flannel.service.j2" 26 | dest: "/lib/systemd/system/flannel.service" 27 | owner: root 28 | group: root 29 | mode: 0644 30 | notify: 31 | - restart flannel 32 | 33 | - meta: flush_handlers 34 | -------------------------------------------------------------------------------- /roles/flannel/templates/lib/systemd/system/flannel.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Flanneld overlay address etcd agent 5 | Documentation=https://github.com/coreos/flannel 6 | After=network.target 7 | Before=docker.service 8 | 9 | [Service] 10 | Type=notify 11 | ExecStart=/usr/local/bin/flanneld \ 12 | -etcd-cafile=/var/lib/kubernetes/ca.pem \ 13 | -etcd-certfile=/var/lib/kubelet/{{ ansible_hostname }}.pem \ 14 | -etcd-keyfile=/var/lib/kubelet/{{ ansible_hostname }}-key.pem \ 15 | -etcd-endpoints=https://10.0.0.100:2379 \ 16 | -etcd-prefix=/kubernetes-cluster/network \ 17 | -public-ip={{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }} \ 18 | -iface=enp0s8 19 | Restart=on-failure 20 | 21 | [Install] 22 | WantedBy=multi-user.target 23 | RequiredBy=docker.service 24 | -------------------------------------------------------------------------------- /roles/k8s-download/defaults/main.yml: -------------------------------------------------------------------------------- 1 | k8s_version: v1.10.2 2 | flannel_version: v0.10.0 3 | etcd_version: v3.3.5 4 | -------------------------------------------------------------------------------- /roles/k8s-download/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Create binary directory 2 | file: 3 | path: '{{ BIN_DIR }}' 4 | state: directory 5 | 6 | - name: Download k8s binaries 7 | get_url: 8 | url: "{{ item.url }}" 9 | dest: "{{ item.dest }}" 10 | mode: 0664 11 | with_items: 12 | - { url: "https://storage.googleapis.com/kubernetes-release/release/{{ k8s_version }}/bin/linux/amd64/kube-apiserver", dest: "{{ BIN_DIR }}/kube-apiserver" } 13 | - { url: "https://storage.googleapis.com/kubernetes-release/release/{{ k8s_version }}/bin/linux/amd64/kube-controller-manager", dest: "{{ BIN_DIR }}/kube-controller-manager" } 14 | - { url: "https://storage.googleapis.com/kubernetes-release/release/{{ k8s_version }}/bin/linux/amd64/kube-scheduler", dest: "{{ BIN_DIR }}/kube-scheduler" } 15 | - { url: "https://storage.googleapis.com/kubernetes-release/release/{{ k8s_version }}/bin/linux/amd64/kubelet", dest: "{{ BIN_DIR }}/kubelet" } 16 | - { url: "https://storage.googleapis.com/kubernetes-release/release/{{ k8s_version }}/bin/linux/amd64/kube-proxy", dest: "{{ BIN_DIR }}/kube-proxy" } 17 | 18 | - name: Download Flannel 19 | get_url: 20 | url: 'https://github.com/coreos/flannel/releases/download/{{ flannel_version }}/flannel-{{ flannel_version }}-linux-amd64.tar.gz' 21 | dest: '{{ BIN_DIR }}/flannel-{{ flannel_version }}-linux-amd64.tar.gz' 22 | mode: 0644 23 | 24 | - name: Download Etcd 25 | get_url: 26 | url: 'https://github.com/coreos/etcd/releases/download/{{ etcd_version }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz' 27 | dest: '{{ BIN_DIR }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz' 28 | mode: 0644 29 | 30 | - name: Extract Flannel archive 31 | unarchive: 32 | src: '{{ BIN_DIR }}/flannel-{{ flannel_version }}-linux-amd64.tar.gz' 33 | dest: "{{ BIN_DIR }}" 34 | exclude: 35 | - mk-docker-opts.sh 36 | - README.md 37 | mode: 0554 38 | 39 | - name: Extract Etcd archive 40 | unarchive: 41 | src: '{{ BIN_DIR }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz' 42 | dest: "{{ BIN_DIR }}" 43 | exclude: 44 | - Documentation 45 | - README-etcdctl.md 46 | - README.md 47 | - READMEv2-etcdctl.md 48 | extra_opts: "--strip-components=1" 49 | -------------------------------------------------------------------------------- /roles/k8s-master/handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart k8s-master 2 | systemd: 3 | name: "{{ item }}" 4 | daemon_reload: yes 5 | enabled: yes 6 | state: restarted 7 | with_items: 8 | - kube-apiserver 9 | - kube-controller-manager 10 | - kube-scheduler 11 | -------------------------------------------------------------------------------- /roles/k8s-master/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Add workers IPs to /etc/hosts 2 | blockinfile: 3 | path: /etc/hosts 4 | block: | 5 | 10.0.0.110 k8s-worker1 6 | 10.0.0.111 k8s-worker2 7 | 10.0.0.112 k8s-worker3 8 | 9 | - name: Copy binaries 10 | copy: 11 | src: "{{ item }}" 12 | dest: /usr/local/bin/ 13 | owner: root 14 | group: root 15 | mode: 0554 16 | loop: 17 | - '{{ BIN_DIR }}/kube-apiserver' 18 | - '{{ BIN_DIR }}/kube-controller-manager' 19 | - '{{ BIN_DIR }}/kube-scheduler' 20 | 21 | - name: Create config directory 22 | file: 23 | path: /var/lib/kubernetes 24 | state: directory 25 | owner: root 26 | group: root 27 | mode: 0755 28 | 29 | - name: Copy certificates and keys 30 | copy: 31 | src: "{{ item }}" 32 | dest: /var/lib/kubernetes/ 33 | owner: root 34 | group: root 35 | mode: 0644 36 | loop: 37 | - '{{ PKI_DIR }}/ca.pem' 38 | - '{{ PKI_DIR }}/ca-key.pem' 39 | - '{{ PKI_DIR }}/k8s-master.pem' 40 | - '{{ PKI_DIR }}/k8s-master-key.pem' 41 | - '{{ PKI_DIR }}/encryption-config.yml' 42 | 43 | - name: Copy systemd unit file 44 | template: 45 | src: "{{ item.src }}" 46 | dest: "{{ item.dest }}" 47 | owner: root 48 | group: root 49 | mode: 0644 50 | with_items: 51 | - { src: "lib/systemd/system/kube-apiserver.service.j2" , dest: "/lib/systemd/system/kube-apiserver.service" } 52 | - { src: "lib/systemd/system/kube-controller-manager.service.j2" , dest: "/lib/systemd/system/kube-controller-manager.service" } 53 | - { src: "lib/systemd/system/kube-scheduler.service.j2" , dest: "/lib/systemd/system/kube-scheduler.service" } 54 | notify: 55 | - restart k8s-master 56 | tags: 57 | - config 58 | 59 | - meta: flush_handlers 60 | 61 | - name: Configure RBAC for kubelet authorization 62 | run_once: yes 63 | local_action: shell kubectl apply -f roles/k8s-master/templates/rbac-conf/rbac.yml 64 | become_user: "{{ lookup('env','USER') }}" 65 | register: rbac_conf 66 | until: rbac_conf.stderr == '' 67 | retries: 3 68 | delay: 10 69 | 70 | -------------------------------------------------------------------------------- /roles/k8s-master/templates/lib/systemd/system/kube-apiserver.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Kubernetes API Server 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | Type=notify 9 | ExecStart=/usr/local/bin/kube-apiserver \ 10 | --admission-control=Initializers,NamespaceLifecycle,NodeRestriction,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota \ 11 | --advertise-address={{ inventory_hostname }} \ 12 | --allow-privileged=true \ 13 | --apiserver-count=3 \ 14 | --audit-log-maxage=30 \ 15 | --audit-log-maxbackup=3 \ 16 | --audit-log-maxsize=100 \ 17 | --audit-log-path=/var/log/audit.log \ 18 | --authorization-mode=Node,RBAC \ 19 | --bind-address=0.0.0.0 \ 20 | --client-ca-file=/var/lib/kubernetes/ca.pem \ 21 | --enable-swagger-ui=true \ 22 | --etcd-cafile=/var/lib/kubernetes/ca.pem \ 23 | --etcd-certfile=/var/lib/kubernetes/k8s-master.pem \ 24 | --etcd-keyfile=/var/lib/kubernetes/k8s-master-key.pem \ 25 | --etcd-servers=https://{{ groups['k8s-masters'][0] }}:2379,https://{{ groups['k8s-masters'][1] }}:2379,https://{{ groups['k8s-masters'][2] }}:2379 \ 26 | --event-ttl=1h \ 27 | --experimental-encryption-provider-config=/var/lib/kubernetes/encryption-config.yml \ 28 | --insecure-bind-address=127.0.0.1 \ 29 | --kubelet-certificate-authority=/var/lib/kubernetes/ca.pem \ 30 | --kubelet-client-certificate=/var/lib/kubernetes/k8s-master.pem \ 31 | --kubelet-client-key=/var/lib/kubernetes/k8s-master-key.pem \ 32 | --kubelet-https=true \ 33 | --runtime-config=api/all \ 34 | --service-account-key-file=/var/lib/kubernetes/ca-key.pem \ 35 | --service-cluster-ip-range=10.32.0.0/24 \ 36 | --service-node-port-range=30000-32767 \ 37 | --tls-ca-file=/var/lib/kubernetes/ca.pem \ 38 | --tls-cert-file=/var/lib/kubernetes/k8s-master.pem \ 39 | --tls-private-key-file=/var/lib/kubernetes/k8s-master-key.pem \ 40 | --v=2 41 | Restart=on-failure 42 | RestartSec=5 43 | 44 | [Install] 45 | WantedBy=multi-user.target 46 | 47 | -------------------------------------------------------------------------------- /roles/k8s-master/templates/lib/systemd/system/kube-controller-manager.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Kubernetes Controller Manager 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | ExecStart=/usr/local/bin/kube-controller-manager \ 9 | --address=0.0.0.0 \ 10 | --cluster-cidr=10.200.0.0/16 \ 11 | --cluster-name=kubernetes \ 12 | --cluster-signing-cert-file=/var/lib/kubernetes/ca.pem \ 13 | --cluster-signing-key-file=/var/lib/kubernetes/ca-key.pem \ 14 | --leader-elect=true \ 15 | --master=http://127.0.0.1:8080 \ 16 | --root-ca-file=/var/lib/kubernetes/ca.pem \ 17 | --service-account-private-key-file=/var/lib/kubernetes/ca-key.pem \ 18 | --service-cluster-ip-range=10.32.0.0/24 \ 19 | --v=2 20 | Restart=on-failure 21 | RestartSec=5 22 | 23 | [Install] 24 | WantedBy=multi-user.target 25 | -------------------------------------------------------------------------------- /roles/k8s-master/templates/lib/systemd/system/kube-scheduler.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Kubernetes Scheduler 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | ExecStart=/usr/local/bin/kube-scheduler \ 9 | --leader-elect=true \ 10 | --master=http://127.0.0.1:8080 \ 11 | --v=2 12 | Restart=on-failure 13 | RestartSec=5 14 | 15 | [Install] 16 | WantedBy=multi-user.target 17 | -------------------------------------------------------------------------------- /roles/k8s-master/templates/rbac-conf/rbac.yml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1beta1 2 | kind: ClusterRole 3 | metadata: 4 | annotations: 5 | rbac.authorization.kubernetes.io/autoupdate: "true" 6 | labels: 7 | kubernetes.io/bootstrapping: rbac-defaults 8 | name: system:kube-apiserver-to-kubelet 9 | rules: 10 | - apiGroups: 11 | - "" 12 | resources: 13 | - nodes/proxy 14 | - nodes/stats 15 | - nodes/log 16 | - nodes/spec 17 | - nodes/metrics 18 | verbs: 19 | - "*" 20 | --- 21 | 22 | apiVersion: rbac.authorization.k8s.io/v1beta1 23 | kind: ClusterRoleBinding 24 | metadata: 25 | name: system:kube-apiserver 26 | namespace: "" 27 | roleRef: 28 | apiGroup: rbac.authorization.k8s.io 29 | kind: ClusterRole 30 | name: system:kube-apiserver-to-kubelet 31 | subjects: 32 | - apiGroup: rbac.authorization.k8s.io 33 | kind: User 34 | name: kubernetes 35 | -------------------------------------------------------------------------------- /roles/k8s-monitoring/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Setup heapster 2 | shell: "kubectl create -f roles/k8s-monitoring/templates/heapster.yml" 3 | 4 | - name: Setup influxdb 5 | shell: "kubectl create -f roles/k8s-monitoring/templates/influxdb.yml" 6 | 7 | - name: Setup grafna 8 | shell: "kubectl create -f roles/k8s-monitoring/templates/grafana.yml" 9 | 10 | - name: Setup heapster rbac 11 | shell: "kubectl create -f roles/k8s-monitoring/templates/heapster-rbac.yml" 12 | -------------------------------------------------------------------------------- /roles/k8s-monitoring/templates/grafana.yml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | name: monitoring-grafana 5 | namespace: kube-system 6 | spec: 7 | replicas: 1 8 | template: 9 | metadata: 10 | labels: 11 | task: monitoring 12 | k8s-app: grafana 13 | spec: 14 | containers: 15 | - name: grafana 16 | image: k8s.gcr.io/heapster-grafana-amd64:v4.4.3 17 | ports: 18 | - containerPort: 3000 19 | protocol: TCP 20 | volumeMounts: 21 | - mountPath: /etc/ssl/certs 22 | name: ca-certificates 23 | readOnly: true 24 | - mountPath: /var 25 | name: grafana-storage 26 | env: 27 | - name: INFLUXDB_HOST 28 | value: monitoring-influxdb 29 | - name: GF_SERVER_HTTP_PORT 30 | value: "3000" 31 | - name: GF_AUTH_BASIC_ENABLED 32 | value: "false" 33 | - name: GF_AUTH_ANONYMOUS_ENABLED 34 | value: "true" 35 | - name: GF_AUTH_ANONYMOUS_ORG_ROLE 36 | value: Admin 37 | - name: GF_SERVER_ROOT_URL 38 | value: / 39 | volumes: 40 | - name: ca-certificates 41 | hostPath: 42 | path: /etc/ssl/certs 43 | - name: grafana-storage 44 | emptyDir: {} 45 | --- 46 | apiVersion: v1 47 | kind: Service 48 | metadata: 49 | labels: 50 | kubernetes.io/cluster-service: 'true' 51 | kubernetes.io/name: monitoring-grafana 52 | name: monitoring-grafana 53 | namespace: kube-system 54 | spec: 55 | ports: 56 | - port: 80 57 | targetPort: 3000 58 | selector: 59 | k8s-app: grafana 60 | type: NodePort 61 | -------------------------------------------------------------------------------- /roles/k8s-monitoring/templates/heapster-rbac.yml: -------------------------------------------------------------------------------- 1 | kind: ClusterRoleBinding 2 | apiVersion: rbac.authorization.k8s.io/v1beta1 3 | metadata: 4 | name: heapster 5 | roleRef: 6 | apiGroup: rbac.authorization.k8s.io 7 | kind: ClusterRole 8 | name: system:heapster 9 | subjects: 10 | - kind: ServiceAccount 11 | name: heapster 12 | namespace: kube-system 13 | -------------------------------------------------------------------------------- /roles/k8s-monitoring/templates/heapster.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: heapster 5 | namespace: kube-system 6 | --- 7 | apiVersion: extensions/v1beta1 8 | kind: Deployment 9 | metadata: 10 | name: heapster 11 | namespace: kube-system 12 | spec: 13 | replicas: 1 14 | template: 15 | metadata: 16 | labels: 17 | task: monitoring 18 | k8s-app: heapster 19 | spec: 20 | serviceAccountName: heapster 21 | containers: 22 | - name: heapster 23 | image: k8s.gcr.io/heapster-amd64:v1.5.3 24 | imagePullPolicy: IfNotPresent 25 | command: 26 | - /heapster 27 | - --source=kubernetes:https://kubernetes.default 28 | - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086 29 | --- 30 | apiVersion: v1 31 | kind: Service 32 | metadata: 33 | labels: 34 | task: monitoring 35 | kubernetes.io/cluster-service: 'true' 36 | kubernetes.io/name: Heapster 37 | name: heapster 38 | namespace: kube-system 39 | spec: 40 | ports: 41 | - port: 80 42 | targetPort: 8082 43 | selector: 44 | k8s-app: heapster 45 | -------------------------------------------------------------------------------- /roles/k8s-monitoring/templates/influxdb.yml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | name: monitoring-influxdb 5 | namespace: kube-system 6 | spec: 7 | replicas: 1 8 | template: 9 | metadata: 10 | labels: 11 | task: monitoring 12 | k8s-app: influxdb 13 | spec: 14 | containers: 15 | - name: influxdb 16 | image: k8s.gcr.io/heapster-influxdb-amd64:v1.3.3 17 | volumeMounts: 18 | - mountPath: /data 19 | name: influxdb-storage 20 | volumes: 21 | - name: influxdb-storage 22 | emptyDir: {} 23 | --- 24 | apiVersion: v1 25 | kind: Service 26 | metadata: 27 | labels: 28 | task: monitoring 29 | kubernetes.io/cluster-service: 'true' 30 | kubernetes.io/name: monitoring-influxdb 31 | name: monitoring-influxdb 32 | namespace: kube-system 33 | spec: 34 | ports: 35 | - port: 8086 36 | targetPort: 8086 37 | selector: 38 | k8s-app: influxdb 39 | -------------------------------------------------------------------------------- /roles/k8s-worker/handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart kubelet 2 | systemd: 3 | name: kubelet 4 | daemon_reload: yes 5 | state: restarted 6 | enabled: yes 7 | 8 | - name: restart kube-proxy 9 | systemd: 10 | daemon_reload: yes 11 | enabled: yes 12 | name: kube-proxy 13 | state: restarted 14 | -------------------------------------------------------------------------------- /roles/k8s-worker/meta/main.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythops/Kubernetes-the-hard-way-with-Ansible/5e836713b7452564b219d02694c47c4624664b4b/roles/k8s-worker/meta/main.yml -------------------------------------------------------------------------------- /roles/k8s-worker/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Install socat 2 | apt: 3 | name: socat 4 | state: latest 5 | update_cache: yes 6 | 7 | - name: Create config directories 8 | file: 9 | path: "{{ item }}" 10 | state: directory 11 | owner: root 12 | group: root 13 | mode: 0755 14 | with_items: 15 | - /var/lib/kubelet 16 | - /var/lib/kubernetes 17 | - /var/lib/kube-proxy 18 | 19 | - name: Copy binaries 20 | copy: 21 | src: "{{ item }}" 22 | dest: /usr/local/bin/ 23 | owner: root 24 | group: root 25 | mode: 0554 26 | with_items: 27 | - '{{ BIN_DIR }}/kubelet' 28 | - '{{ BIN_DIR }}/kube-proxy' 29 | 30 | - name: Copy certificates and config files 31 | copy: 32 | src: "{{ item.src }}" 33 | dest: "{{ item.dest }}" 34 | owner: root 35 | group: root 36 | mode: 0644 37 | with_items: 38 | - { src: "{{ PKI_DIR }}/ca.pem" , dest: "/var/lib/kubernetes/" } 39 | - { src: "{{ PKI_DIR }}/{{ ansible_hostname }}.pem" , dest: "/var/lib/kubelet/" } 40 | - { src: "{{ PKI_DIR }}/{{ ansible_hostname }}-key.pem" , dest: "/var/lib/kubelet/" } 41 | - { src: "{{ CONF_DIR }}/{{ ansible_hostname }}.kubeconfig" , dest: "/var/lib/kubelet/" } 42 | - { src: "{{ CONF_DIR }}/kube-proxy.kubeconfig" , dest: "/var/lib/kube-proxy/kubeconfig"} 43 | 44 | - name: Include docker role 45 | include_role: 46 | name: docker 47 | 48 | - name: Copy config file for kubelet 49 | template: 50 | src: "lib/systemd/system/kubelet.service.j2" 51 | dest: "/lib/systemd/system/kubelet.service" 52 | owner: root 53 | group: root 54 | mode: 0644 55 | notify: 56 | - restart kubelet 57 | tags: 58 | - config 59 | 60 | - name: Copy config file for kube-proxy 61 | template: 62 | src: "lib/systemd/system/kube-proxy.service.j2" 63 | dest: "/lib/systemd/system/kube-proxy.service" 64 | owner: root 65 | group: root 66 | mode: 0664 67 | notify: 68 | - restart kube-proxy 69 | -------------------------------------------------------------------------------- /roles/k8s-worker/templates/lib/systemd/system/kube-proxy.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Kubernetes Kube Proxy 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | ExecStart=/usr/local/bin/kube-proxy \ 9 | --cluster-cidr=10.200.0.0/16 \ 10 | --kubeconfig=/var/lib/kube-proxy/kubeconfig \ 11 | --proxy-mode=iptables \ 12 | --v=2 13 | Restart=on-failure 14 | RestartSec=5 15 | 16 | [Install] 17 | WantedBy=multi-user.target 18 | -------------------------------------------------------------------------------- /roles/k8s-worker/templates/lib/systemd/system/kubelet.service.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | [Unit] 4 | Description=Kubernetes Kubelet 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | ExecStart=/usr/local/bin/kubelet \ 9 | --allow-privileged=true \ 10 | --anonymous-auth=false \ 11 | --authorization-mode=Webhook \ 12 | --container-runtime=docker \ 13 | --client-ca-file=/var/lib/kubernetes/ca.pem \ 14 | --cluster-dns=10.32.0.10 \ 15 | --cluster-domain=cluster.local \ 16 | --image-pull-progress-deadline=2m \ 17 | --kubeconfig=/var/lib/kubelet/{{ ansible_hostname }}.kubeconfig \ 18 | --node-ip={{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }} \ 19 | --register-node=true \ 20 | --tls-cert-file=/var/lib/kubelet/{{ ansible_hostname }}.pem \ 21 | --tls-private-key-file=/var/lib/kubelet/{{ ansible_hostname }}-key.pem \ 22 | --v=2 23 | Restart=on-failure 24 | RestartSec=5 25 | 26 | [Install] 27 | WantedBy=multi-user.target 28 | -------------------------------------------------------------------------------- /roles/kubeconfig/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Create kubeconfig directory 2 | file: 3 | path: '{{ CONF_DIR }}' 4 | state: directory 5 | 6 | - name: Generate kubeconfig file for Admin 7 | shell: | 8 | kubectl config set-cluster k8s-the-hard-way \ 9 | --certificate-authority={{ PKI_DIR }}/ca.pem \ 10 | --embed-certs=true \ 11 | --server=https://{{ groups['loadbalancer'][0] }}:6443 12 | 13 | kubectl config set-credentials admin \ 14 | --client-certificate={{ PKI_DIR }}/admin.pem \ 15 | --client-key={{ PKI_DIR }}/admin-key.pem 16 | 17 | kubectl config set-context k8s-the-hard-way \ 18 | --cluster=k8s-the-hard-way \ 19 | --user=admin 20 | 21 | kubectl config use-context k8s-the-hard-way 22 | 23 | - name: Configure kubeconf files for Kubelet 24 | shell: | 25 | kubectl config set-cluster k8s-the-hard-way \ 26 | --certificate-authority={{ PKI_DIR }}/ca.pem \ 27 | --embed-certs=true \ 28 | --server=https://{{ groups['loadbalancer'][0] }}:6443 \ 29 | --kubeconfig={{ CONF_DIR }}/{{ item }}.kubeconfig 30 | 31 | kubectl config set-credentials system:node:{{ item }} \ 32 | --client-certificate={{ PKI_DIR }}/{{ item }}.pem \ 33 | --client-key={{ PKI_DIR }}/{{ item }}-key.pem \ 34 | --embed-certs=true \ 35 | --kubeconfig={{ CONF_DIR }}/{{ item }}.kubeconfig 36 | 37 | kubectl config set-context default \ 38 | --cluster=k8s-the-hard-way \ 39 | --user=system:node:{{ item }} \ 40 | --kubeconfig={{ CONF_DIR }}/{{ item }}.kubeconfig 41 | 42 | kubectl config use-context default --kubeconfig={{ CONF_DIR }}/{{ item }}.kubeconfig 43 | args: 44 | creates: '{{ CONF_DIR }}/{{ item }}.kubeconfig' 45 | loop: 46 | - k8s-worker1 47 | - k8s-worker2 48 | - k8s-worker3 49 | 50 | - name: Generate kubeconf files for Kube-Proxy 51 | shell: | 52 | kubectl config set-cluster k8s-the-hard-way \ 53 | --certificate-authority={{ PKI_DIR }}/ca.pem \ 54 | --embed-certs=true \ 55 | --server=https://{{ groups['loadbalancer'][0] }}:6443 \ 56 | --kubeconfig={{ CONF_DIR }}/kube-proxy.kubeconfig 57 | 58 | kubectl config set-credentials kube-proxy \ 59 | --client-certificate={{ PKI_DIR }}/kube-proxy.pem \ 60 | --client-key={{ PKI_DIR }}/kube-proxy-key.pem \ 61 | --embed-certs=true \ 62 | --kubeconfig={{ CONF_DIR }}/kube-proxy.kubeconfig 63 | 64 | kubectl config set-context default \ 65 | --cluster=k8s-the-hard-way \ 66 | --user=kube-proxy \ 67 | --kubeconfig={{ CONF_DIR }}/kube-proxy.kubeconfig 68 | 69 | kubectl config use-context default --kubeconfig={{ CONF_DIR }}/kube-proxy.kubeconfig 70 | args: 71 | creates: '{{ CONF_DIR }}/kube-proxy.kubeconfig' 72 | -------------------------------------------------------------------------------- /roles/loadbalancer/handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: reload nginx 2 | systemd: 3 | name: nginx 4 | state: reloaded 5 | -------------------------------------------------------------------------------- /roles/loadbalancer/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Install nginx 2 | apt: 3 | name: nginx 4 | state: latest 5 | update_cache: yes 6 | 7 | - name: Configure nginx 8 | blockinfile: 9 | path: /etc/nginx/nginx.conf 10 | block: | 11 | stream { 12 | upstream k8s-api { 13 | {% for host in groups['k8s-masters'] %} 14 | server {{ host }}:6443; 15 | {% endfor %} 16 | } 17 | upstream etcd { 18 | {% for host in groups['k8s-masters'] %} 19 | server {{ host }}:2379; 20 | {% endfor %} 21 | } 22 | 23 | server { 24 | listen 6443; 25 | proxy_pass k8s-api; 26 | } 27 | 28 | server { 29 | listen 2379; 30 | proxy_pass etcd; 31 | } 32 | } 33 | notify: 34 | - reload nginx 35 | -------------------------------------------------------------------------------- /roles/pki/defaults/main.yml: -------------------------------------------------------------------------------- 1 | encryption_config: | 2 | kind: EncryptionConfig 3 | apiVersion: v1 4 | resources: 5 | - resources: 6 | - secrets 7 | providers: 8 | - aescbc: 9 | keys: 10 | - name: key1 11 | secret: $(head -c 32 /dev/urandom | base64) 12 | - identity: {} 13 | -------------------------------------------------------------------------------- /roles/pki/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - name: Create PKI directory 2 | file: 3 | path: '{{ PKI_DIR }}' 4 | state: directory 5 | 6 | - name: Generate CA private key 7 | openssl_privatekey: 8 | path: '{{ PKI_DIR }}/ca-key.pem' 9 | 10 | - name: Generate CA CSR 11 | openssl_csr: 12 | path: '{{ PKI_DIR }}/ca.csr' 13 | privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 14 | basic_constraints: "CA:TRUE" 15 | basic_constraints_critical: True 16 | key_usage: cRLSign, keyCertSign 17 | key_usage_critical: True 18 | organizational_unit_name: 'k8s the hard way' 19 | common_name: k8s-CA 20 | 21 | - name: Generate CA certificate 22 | openssl_certificate: 23 | path: '{{ PKI_DIR }}/ca.pem' 24 | privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 25 | csr_path: '{{ PKI_DIR }}/ca.csr' 26 | provider: selfsigned 27 | 28 | - name: Generate Admin private key 29 | openssl_privatekey: 30 | path: '{{ PKI_DIR }}/admin-key.pem' 31 | 32 | - name: Generate Admin CSR 33 | openssl_csr: 34 | path: '{{ PKI_DIR }}/admin.csr' 35 | privatekey_path: '{{ PKI_DIR }}/admin-key.pem' 36 | basic_constraints: "CA:FALSE" 37 | basic_constraints_critical: True 38 | key_usage: digitalSignature, keyEncipherment 39 | key_usage_critical: True 40 | extended_key_usage: serverAuth, clientAuth 41 | common_name: k8s-admin 42 | organization_name: "system:masters" 43 | organizational_unit_name: k8s the hard way 44 | 45 | - name: Generate Admin certificate 46 | openssl_certificate: 47 | path: '{{ PKI_DIR }}/admin.pem' 48 | csr_path: '{{ PKI_DIR }}/admin.csr' 49 | ownca_path: '{{ PKI_DIR }}/ca.pem' 50 | ownca_privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 51 | provider: ownca 52 | 53 | - name: Generate Masters private key 54 | openssl_privatekey: 55 | path: '{{ PKI_DIR }}/k8s-master-key.pem' 56 | 57 | - name: Generate Masters CSR 58 | openssl_csr: 59 | path: '{{ PKI_DIR }}/k8s-master.csr' 60 | privatekey_path: '{{ PKI_DIR }}/k8s-master-key.pem' 61 | common_name: 'k8s-master' 62 | basic_constraints: "CA:FALSE" 63 | basic_constraints_critical: True 64 | key_usage: digitalSignature, keyEncipherment 65 | key_usage_critical: True 66 | extended_key_usage: serverAuth, clientAuth 67 | organization_name: 'system:masters' 68 | organizational_unit_name: 'k8s the hard way' 69 | subject_alt_name: "DNS:kubernetes.default, IP:{{ groups['k8s-masters'][0] }}, IP:{{ groups['k8s-masters'][1] }}, IP:{{ groups['k8s-masters'][2] }}, IP:{{ groups['loadbalancer'][0] }}, IP:127.0.0.1, IP:{{ APISERVER_SERVICE_IP }}" 70 | 71 | - name: Generate Masters certificate 72 | openssl_certificate: 73 | path: '{{ PKI_DIR }}/k8s-master.pem' 74 | csr_path: '{{ PKI_DIR }}/k8s-master.csr' 75 | ownca_path: '{{ PKI_DIR }}/ca.pem' 76 | ownca_privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 77 | provider: ownca 78 | 79 | - name: Generate Workers private keys 80 | openssl_privatekey: 81 | path: '{{ PKI_DIR }}/{{ item }}-key.pem' 82 | loop: 83 | - k8s-worker1 84 | - k8s-worker2 85 | - k8s-worker3 86 | 87 | - name: Generate Workers CSRs 88 | openssl_csr: 89 | path: '{{ PKI_DIR }}/{{ item[0] }}.csr' 90 | privatekey_path: '{{ PKI_DIR }}/{{ item[0] }}-key.pem' 91 | common_name: 'system:node:{{ item[0] }}' 92 | basic_constraints: "CA:FALSE" 93 | basic_constraints_critical: True 94 | key_usage: digitalSignature, keyEncipherment 95 | key_usage_critical: True 96 | extended_key_usage: serverAuth, clientAuth 97 | organization_name: 'system:nodes' 98 | organizational_unit_name: 'k8s the hard way' 99 | subject_alt_name: 'DNS:{{ item[0] }}, IP:{{ item[1] }}' 100 | loop: 101 | - ["k8s-worker1", "{{ groups['k8s-workers'][0] }}" ] 102 | - ["k8s-worker2", "{{ groups['k8s-workers'][1] }}" ] 103 | - ["k8s-worker3", "{{ groups['k8s-workers'][2] }}" ] 104 | 105 | - name: Generate Workers certificates 106 | openssl_certificate: 107 | path: '{{ PKI_DIR }}/{{ item }}.pem' 108 | csr_path: '{{ PKI_DIR }}/{{ item }}.csr' 109 | ownca_path: '{{ PKI_DIR }}/ca.pem' 110 | ownca_privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 111 | provider: ownca 112 | loop: 113 | - k8s-worker1 114 | - k8s-worker2 115 | - k8s-worker3 116 | 117 | - name: Generating Kube Proxy private key 118 | openssl_privatekey: 119 | path: '{{ PKI_DIR }}/kube-proxy-key.pem' 120 | 121 | - name: Generate Kube Proxy CSR 122 | openssl_csr: 123 | path: '{{ PKI_DIR }}/kube-proxy.csr' 124 | privatekey_path: '{{ PKI_DIR }}/kube-proxy-key.pem' 125 | basic_constraints: "CA:FALSE" 126 | basic_constraints_critical: True 127 | key_usage: digitalSignature, keyEncipherment 128 | key_usage_critical: True 129 | extended_key_usage: serverAuth, clientAuth 130 | common_name: 'system:kube-proxy' 131 | organization_name: 'system:node-proxier' 132 | organizational_unit_name: 'k8s the hard way' 133 | 134 | - name: Generate Kube Proxy certificate 135 | openssl_certificate: 136 | path: '{{ PKI_DIR }}/kube-proxy.pem' 137 | csr_path: '{{ PKI_DIR }}/kube-proxy.csr' 138 | ownca_path: '{{ PKI_DIR }}/ca.pem' 139 | ownca_privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 140 | provider: ownca 141 | 142 | - name: Generate k8s Dashboard private key 143 | openssl_privatekey: 144 | path: '{{ PKI_DIR }}/k8s-dashboard-key.pem' 145 | 146 | - name: Generate k8s Dashboard CSR 147 | openssl_csr: 148 | path: '{{ PKI_DIR }}/k8s-dashboard.csr' 149 | privatekey_path: '{{ PKI_DIR }}/k8s-dashboard-key.pem' 150 | basic_constraints: "CA:FALSE" 151 | basic_constraints_critical: True 152 | key_usage: digitalSignature, keyEncipherment 153 | key_usage_critical: True 154 | extended_key_usage: serverAuth, clientAuth 155 | common_name: 'k8s-Dashboard' 156 | organization_name: 'addons:Dashboard' 157 | organizational_unit_name: 'k8s the hard way' 158 | 159 | - name: Generate k8s Dashboard certificate 160 | openssl_certificate: 161 | path: '{{ PKI_DIR }}/k8s-dashboard.pem' 162 | csr_path: '{{ PKI_DIR }}/k8s-dashboard.csr' 163 | ownca_path: '{{ PKI_DIR }}/ca.pem' 164 | ownca_privatekey_path: '{{ PKI_DIR }}/ca-key.pem' 165 | provider: ownca 166 | 167 | - name: Generate k8s-dashboard bundle 168 | shell: "cat {{ PKI_DIR }}/k8s-dashboard.pem {{ PKI_DIR }}/k8s-dashboard-key.pem > {{ PKI_DIR }}/k8s-dashboard.bundle" 169 | args: 170 | creates: '{{ PKI_DIR }}/k8s-dashboard.bundle' 171 | 172 | - name: Generate encryption-config.yml 173 | shell: echo "{{ encryption_config }}" > {{ PKI_DIR }}/encryption-config.yml 174 | args: 175 | creates: '{{ PKI_DIR }}/encryption-config.yml' 176 | -------------------------------------------------------------------------------- /roles/ssh/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Add ssh keys 4 | authorized_key: 5 | user: vagrant 6 | state: present 7 | key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}" 8 | -------------------------------------------------------------------------------- /ssh.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - hosts: all 4 | remote_user: vagrant 5 | vars: 6 | ansible_python_interpreter: /usr/bin/python3 7 | roles: 8 | - ssh 9 | --------------------------------------------------------------------------------