├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── README_PKI.md ├── init.sls ├── k8s-certs ├── ca-config.json ├── ca-csr.json ├── files.sls ├── init.sls ├── k8s_params.jinja ├── kubernetes-csr.json ├── signing_policies.conf ├── token.csv ├── x509-base.sls ├── x509-ca.sls ├── x509-files.sls └── x509-req.sls ├── k8s-master ├── encryption-config.yaml ├── etcd │ ├── etcd-ha.service │ ├── etcd.service │ └── init.sls ├── init.sls ├── kube-apiserver-ha.service ├── kube-apiserver.service ├── kube-controller-manager.service └── kube-scheduler.service ├── k8s-worker ├── cni │ ├── calico │ │ ├── 10-calico.conf │ │ ├── calico.tmpl.yaml │ │ ├── calicoctl.cfg │ │ ├── init.sls │ │ └── kubeconfig │ ├── flannel │ │ └── init.sls │ └── init.sls ├── cri │ ├── containerd │ │ └── init.sls │ └── docker │ │ ├── docker.service │ │ └── init.sls ├── init.sls ├── kube-proxy.service ├── kubeconfig ├── kubelet.service └── wireguard │ └── .placeholder ├── pillar ├── cluster_config.sls └── top.sls ├── post_install ├── coredns.yaml ├── grafana.yaml ├── heapster-rbac.yaml ├── heapster.yaml ├── influxdb.yaml ├── metallb-configmap.yaml ├── policy-controller.yaml ├── rbac-calico.yaml ├── rbac-tiller.yaml └── setup.sh └── top.sls /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: ValentinOuvrard 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /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 | 2 | 3 | Kubernetes-Saltstack provide an easy way to deploy H/A **Kubernetes Cluster** using Salt. 4 | 5 | ## Features 6 | 7 | - Cloud-provider **agnostic** 8 | - Support **high-available** clusters 9 | - Use the power of **`Saltstack`** 10 | - Made for **`systemd`** based Linux systems 11 | - **Layer 3** networking by default (**`Calico`**) 12 | - **`CoreDNS`** as internal DNS resolver 13 | - Highly **Composable** (CNI, CRI, Add-ons) 14 | - Integrated **add-ons** (Helm, CoreDNS, MetalLB, Dashboard, Nginx-Ingress, ...) 15 | - **RBAC** & **TLS** by default 16 | - Support **IPv6** 17 | 18 | ## Getting started 19 | 20 | ### I. Generate CA and TLS certificates using CfSSL 21 | 22 | Let's clone the git repo on Salt-master and create CA & certificates on the `k8s-certs/` directory using **`CfSSL`** tools: 23 | 24 | ```bash 25 | git clone https://github.com/valentin2105/Kubernetes-Saltstack.git /srv/salt 26 | ln -s /srv/salt/pillar /srv/pillar 27 | 28 | wget -q --show-progress --https-only --timestamping \ 29 | https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 \ 30 | https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 31 | 32 | chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 33 | sudo mv cfssl_linux-amd64 /usr/local/bin/cfssl 34 | sudo mv cfssljson_linux-amd64 /usr/local/bin/cfssljson 35 | ``` 36 | 37 | ##### IMPORTANT Point 38 | 39 | Because we generate our own CA and certificates for the cluster, 40 | 41 | You MUST put **every hostnames and IPs of the Kubernetes cluster** (master & workers) in the `certs/kubernetes-csr.json` (**`hosts`** field). 42 | 43 | You can also modify the `certs/*json` files to match your cluster-name / country. (optional) 44 | 45 | You can use **either public or private names**, but they must be registered somewhere (DNS provider, internal DNS server, `/etc/hosts` file) or use **IP records instead of names**. 46 | 47 | ```bash 48 | cd /srv/salt/k8s-certs 49 | cfssl gencert -initca ca-csr.json | cfssljson -bare ca 50 | 51 | # !!!!!!!!! 52 | # Don't forget to edit kubernetes-csr.json before this point ! 53 | # !!!!!!!!! 54 | 55 | cfssl gencert \ 56 | -ca=ca.pem \ 57 | -ca-key=ca-key.pem \ 58 | -config=ca-config.json \ 59 | -profile=kubernetes \ 60 | kubernetes-csr.json | cfssljson -bare kubernetes 61 | 62 | chown salt: /srv/salt/k8s-certs/ -R 63 | ``` 64 | 65 | After that, edit the `pillar/cluster_config.sls` to tweak your future Kubernetes cluster : 66 | 67 | ```yaml 68 | kubernetes: 69 | version: v1.16.1 70 | domain: cluster.local 71 | 72 | master: 73 | count: 1 74 | hostname: 75 | ipaddr: 10.240.0.10 76 | 77 | etcd: 78 | version: v3.3.12 79 | encryption-key: '0Wh+uekJUj3SzaKt+BcHUEJX/9Vo2PLGiCoIsND9GyY=' 80 | 81 | pki: 82 | enable: false 83 | host: master01.domain.tld 84 | wildcard: '*.domain.tld' 85 | 86 | worker: 87 | runtime: 88 | provider: docker 89 | docker: 90 | version: 18.09.9 91 | data-dir: /dockerFS 92 | networking: 93 | cni-version: v0.7.1 94 | provider: calico 95 | calico: 96 | version: v3.9.0 97 | cni-version: v3.9.0 98 | calicoctl-version: v3.9.0 99 | controller-version: 3.9-release 100 | as-number: 64512 101 | token: hu0daeHais3a--CHANGEME--hu0daeHais3a 102 | ipv4: 103 | range: 192.168.0.0/16 104 | nat: true 105 | ip-in-ip: true 106 | ipv6: 107 | enable: false 108 | nat: true 109 | interface: eth0 110 | range: fd80:24e2:f998:72d6::/64 111 | 112 | global: 113 | clusterIP-range: 10.32.0.0/16 114 | helm-version: v2.14.3 115 | dashboard-version: v2.0.0-beta4 116 | coredns-version: 1.6.4 117 | admin-token: Haim8kay1rar--CHANGEME--Haim8kay11ra 118 | kubelet-token: ahT1eipae1wi--CHANGEME--ahT1eipa1e1w 119 | metallb: 120 | enable: false 121 | version: v0.8.1 122 | protocol: layer2 123 | addresses: 10.100.0.0/24 124 | nginx-ingress: 125 | enable: false 126 | version: 0.26.1 127 | service-type: LoadBalancer 128 | cert-manager: 129 | enable: false 130 | version: v0.11.0 131 | ``` 132 | 133 | ###### Don't forget to change Master's hostname & Tokens using `pwgen` for example ! 134 | 135 | If you want to enable IPv6 on pod's side, you need to change `kubernetes.worker.networking.calico.ipv6.enable` to `true`. 136 | 137 | ### II. Cluster deployment 138 | 139 | To deploy your Kubernetes cluster using this formula, you first need to setup your Saltstack master/Minion. 140 | 141 | You can use [Salt-Bootstrap](https://docs.saltstack.com/en/stage/topics/tutorials/salt_bootstrap.html) or [Salt-Cloud](https://docs.saltstack.com/en/latest/topics/cloud/) to enhance the process. 142 | 143 | The configuration is done to use the Salt-master as the Kubernetes master. 144 | 145 | You can have them as different nodes if needed but the `post_install/script.sh` require `kubectl` and access to the `pillar` files. 146 | 147 | #### The recommended configuration is : 148 | 149 | - one or three Kubernetes-master (Salt-master & minion) 150 | 151 | - one or more Kubernetes-workers (Salt-minion) 152 | 153 | The Minion's roles are matched with `Salt Grains` (kind of inventory), so you need to define theses grains on your servers : 154 | 155 | If you want a small cluster, a master can be a worker too. 156 | 157 | ```bash 158 | # Kubernetes masters 159 | cat << EOF > /etc/salt/grains 160 | role: k8s-master 161 | EOF 162 | 163 | # Kubernetes workers 164 | cat << EOF > /etc/salt/grains 165 | role: k8s-worker 166 | EOF 167 | 168 | # Kubernetes master & workers 169 | cat << EOF > /etc/salt/grains 170 | role: 171 | - k8s-master 172 | - k8s-worker 173 | EOF 174 | 175 | service salt-minion restart 176 | ``` 177 | 178 | After that, you can apply your configuration with a (`highstate`) : 179 | 180 | ```bash 181 | # Apply Kubernetes master configurations : 182 | ~ salt -G 'role:k8s-master' state.highstate 183 | 184 | ~ kubectl get componentstatuses 185 | NAME STATUS MESSAGE ERROR 186 | scheduler Healthy ok 187 | controller-manager Healthy ok 188 | etcd-0 Healthy {"health": "true"} 189 | etcd-1 Healthy {"health": "true"} 190 | etcd-2 Healthy {"health": "true"} 191 | 192 | # Apply Kubernetes worker configurations : 193 | ~ salt -G 'role:k8s-worker' state.highstate 194 | 195 | ~ kubectl get nodes 196 | NAME STATUS ROLES AGE VERSION OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME 197 | k8s-worker01 Ready 3h56m v1.16.1 Ubuntu 18.04.3 LTS 4.15.0-58-generic docker://18.9.9 198 | k8s-worker02 Ready 3h56m v1.16.1 Ubuntu 18.04.3 LTS 4.15.0-58-generic docker://18.9.9 199 | k8s-worker03 Ready 91m v1.16.1 Debian GNU/Linux 10 (buster) 4.19.0-6-cloud-amd64 docker://18.9.9 200 | k8s-worker04 Ready 67m v1.16.1 Fedora 30 (Cloud Edition) 5.2.18-200.fc30.x86_64 docker://18.9.9 201 | 202 | # Deploy Calico and Add-ons : 203 | ~ /opt/kubernetes/post_install/setup.sh 204 | 205 | ~# kubectl get pod --all-namespaces 206 | cert-manager pod/cert-manager-55c44f98f-vmpcm 1/1 Running 207 | cert-manager pod/cert-manager-cainjector-576978ffc8-w7m5j 1/1 Running 208 | cert-manager pod/cert-manager-webhook-c67fbc858-tjcvm 1/1 Running 209 | default pod/debug-85d7f9799-dtc6c 1/1 Running 210 | kube-system pod/calico-kube-controllers-5979855b8-vdpvw 1/1 Running 211 | kube-system pod/calico-node-h7n58 1/1 Running 212 | kube-system pod/calico-node-jl4fc 1/1 Running 213 | kube-system pod/calico-node-tv5cq 1/1 Running 214 | kube-system pod/calico-node-xxbgh 1/1 Running 215 | kube-system pod/coredns-7c7c6c44bf-4lxn4 1/1 Running 216 | kube-system pod/coredns-7c7c6c44bf-t9g7v 1/1 Running 217 | kube-system pod/tiller-deploy-6966cf57d8-jpf5k 1/1 Running 218 | kubernetes-dashboard pod/dashboard-metrics-scraper-566cddb686-mf8xn 1/1 Running 219 | kubernetes-dashboard pod/kubernetes-dashboard-7b5bf5d559-25cdb 1/1 Running 220 | metallb-system pod/controller-6bcfdfd677-g9s6f 1/1 Running 221 | metallb-system pod/speaker-bmx5p 1/1 Running 222 | metallb-system pod/speaker-g8cqr 1/1 Running 223 | metallb-system pod/speaker-mklzd 1/1 Running 224 | metallb-system pod/speaker-xmhkm 1/1 Running 225 | nginx-ingress pod/nginx-ingress-controller-5dcb7b4488-b68zj 1/1 Running 226 | nginx-ingress pod/nginx-ingress-controller-5dcb7b4488-n7kwc 1/1 Running 227 | nginx-ingress pod/nginx-ingress-default-backend-659bd647bd-5l2km 1/1 Running 228 | ``` 229 | 230 | ### III. Add nodes afterwards 231 | 232 | If you want add a node on your Kubernetes cluster, just add the new **Hostname** and *IPs* on `kubernetes-csr.json` and run theses commands to regenerate your cluster certificates : 233 | 234 | ```bash 235 | cd /srv/salt/k8s-certs 236 | 237 | cfssl gencert \ 238 | -ca=ca.pem \ 239 | -ca-key=ca-key.pem \ 240 | -config=ca-config.json \ 241 | -profile=kubernetes \ 242 | kubernetes-csr.json | cfssljson -bare kubernetes 243 | 244 | # Reload k8s components on Master and Workers. 245 | salt -G 'role:k8s-master' state.highstate 246 | salt -G 'role:k8s-worker' state.highstate 247 | ``` 248 | 249 | The `highstate` configure automatically new workers (if it match the k8s-worker role in Grains). 250 | 251 | - Tested on Debian, Ubuntu and Fedora. 252 | - You can easily upgrade software version on your cluster by changing values in `pillar/cluster_config.sls` and apply a `highstate`. 253 | - This configuration use ECDSA certificates (you can switch to `rsa` in `certs/*.json`). 254 | - You can change IPv4 IPPool, enable IPv6, change IPv6 IPPool, enable IPv6 NAT (for no-public networks), change BGP AS number, Enable IPinIP (to allow routes sharing between subnets). 255 | - If you use `salt-ssh` or `salt-cloud` you can quickly scale new workers. 256 | 257 | ## Support me on Patreon 258 | Help me out for a couple of :beers:! 259 | 260 | https://www.patreon.com/ValentinOuvrard 261 | -------------------------------------------------------------------------------- /README_PKI.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Kubernetes-Saltstack provide an easy way to deploy H/A **Kubernetes Cluster** using Salt. 4 | 5 | ## Features 6 | 7 | - Cloud-provider **agnostic** 8 | - Support **high-available** clusters 9 | - Use the power of **`Saltstack`** 10 | - Made for **`systemd`** based Linux systems 11 | - **Routed** networking by default (**`Calico`**) 12 | - **CoreDNS** as internal DNS provider 13 | - Support **IPv6** 14 | - Integrated **add-ons** 15 | - **Composable** (CNI, CRI) 16 | - **RBAC** & **TLS** by default 17 | 18 | ## Getting started 19 | 20 | There a two possibilities, you can create and manage CA and certificates manualy with **`CFSSL`** or you can use **`salted`** managed PKI 21 | 22 | ### With static CA using cfssl 23 | 24 | Let's clone the git repo on Salt-master and create CA & certificates on the `k8s-certs/` directory using **`CfSSL`** tools: 25 | 26 | ```bash 27 | git clone https://github.com/valentin2105/Kubernetes-Saltstack.git /srv/salt 28 | ln -s /srv/salt/pillar /srv/pillar 29 | 30 | wget -q --show-progress --https-only --timestamping \ 31 | https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 \ 32 | https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 33 | 34 | chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 35 | sudo mv cfssl_linux-amd64 /usr/local/bin/cfssl 36 | sudo mv cfssljson_linux-amd64 /usr/local/bin/cfssljson 37 | ``` 38 | 39 | #### IMPORTANT Point 40 | 41 | Because we need to generate our own CA and certificates for the cluster, You MUST put **every hostnames of the Kubernetes cluster** (master & workers) in the `certs/kubernetes-csr.json` (`hosts` field). You can also modify the `certs/*json` files to match your cluster-name / country. (optional) 42 | 43 | You can use either public or private names, but they must be registered somewhere (DNS provider, internal DNS server, `/etc/hosts` file). 44 | 45 | ```bash 46 | cd /srv/salt/k8s-certs 47 | cfssl gencert -initca ca-csr.json | cfssljson -bare ca 48 | 49 | # Don't forget to edit kubernetes-csr.json before this point ! 50 | 51 | cfssl gencert \ 52 | -ca=ca.pem \ 53 | -ca-key=ca-key.pem \ 54 | -config=ca-config.json \ 55 | -profile=kubernetes \ 56 | kubernetes-csr.json | cfssljson -bare kubernetes 57 | 58 | chown salt: /srv/salt/k8s-certs/ -R 59 | ``` 60 | ### With internal salt PKI (auto create certificates) 61 | 62 | Let's clone the git repo on Salt-master 63 | 64 | ```bash 65 | git clone https://github.com/valentin2105/Kubernetes-Saltstack.git /srv/salt 66 | ln -s /srv/salt/pillar /srv/pillar 67 | ``` 68 | 69 | After that, edit the `pillar/cluster_config.sls` to configure your future Kubernetes cluster : 70 | 71 | ```yaml 72 | kubernetes: 73 | pki: 74 | enable: true 75 | host: 76 | wildcard: '*' 77 | ``` 78 | and you need to verify your salt master grant peers to use x509.sign_remote_certificate update the file `/etc/salt/master.d/client_acl.conf` 79 | 80 | ```yaml 81 | peer: 82 | .*: 83 | - x509.sign_remote_certificate 84 | ``` 85 | 86 | and then restart the salt master 87 | 88 | ##### Don't forget to change hostnames & tokens using command like `pwgen 64` ! 89 | 90 | If you want to enable IPv6 on pod's side, you need to change `kubernetes.worker.networking.calico.ipv6.enable` to `true`. 91 | 92 | ## Deployment 93 | 94 | To deploy your Kubernetes cluster using this formula, you first need to setup your Saltstack master/Minion. 95 | You can use [Salt-Bootstrap](https://docs.saltstack.com/en/stage/topics/tutorials/salt_bootstrap.html) or [Salt-Cloud](https://docs.saltstack.com/en/latest/topics/cloud/) to enhance the process. 96 | 97 | The configuration is done to use the Salt-master as the Kubernetes master. You can have them as different nodes if needed but the `post_install/script.sh` require `kubectl` and access to the `pillar` files. 98 | 99 | #### The recommended configuration is : 100 | 101 | - one or three Kubernetes-master (Salt-master & minion) 102 | 103 | - one or more Kubernetes-workers (Salt-minion) 104 | 105 | The Minion's roles are matched with `Salt Grains` (kind of inventory), so you need to define theses grains on your servers : 106 | 107 | If you want a small cluster, a master can be a worker too. 108 | 109 | ```bash 110 | # Kubernetes masters 111 | cat << EOF > /etc/salt/grains 112 | role: k8s-master 113 | EOF 114 | 115 | # Kubernetes workers 116 | cat << EOF > /etc/salt/grains 117 | role: k8s-worker 118 | EOF 119 | 120 | # Kubernetes master & workers 121 | cat << EOF > /etc/salt/grains 122 | role: 123 | - k8s-master 124 | - k8s-worker 125 | EOF 126 | 127 | service salt-minion restart 128 | ``` 129 | 130 | After that, you can apply your configuration (`highstate`) : 131 | 132 | ```bash 133 | # Apply Kubernetes master configurations 134 | salt -G 'role:k8s-master' state.highstate 135 | 136 | ~# kubectl get componentstatuses 137 | NAME STATUS MESSAGE ERROR 138 | scheduler Healthy ok 139 | controller-manager Healthy ok 140 | etcd-0 Healthy {"health": "true"} 141 | etcd-1 Healthy {"health": "true"} 142 | etcd-2 Healthy {"health": "true"} 143 | 144 | # Apply Kubernetes worker configurations 145 | salt -G 'role:k8s-worker' state.highstate 146 | 147 | ~# kubectl get nodes 148 | NAME STATUS ROLES AGE VERSION EXTERNAL-IP OS-IMAGE 149 | k8s-salt-worker01 Ready 5m v1.11.2 Ubuntu 18.04.1 LTS 150 | k8s-salt-worker02 Ready 5m v1.11.2 Ubuntu 18.04.1 LTS 151 | k8s-salt-worker03 Ready 5m v1.11.2 Ubuntu 18.04.1 LTS 152 | k8s-salt-worker04 Ready 5m v1.11.2 Ubuntu 18.04.1 LTS 153 | ``` 154 | 155 | To enable add-ons on the Kubernetes cluster, you can launch the `post_install/setup.sh` script : 156 | 157 | ```bash 158 | /srv/salt/post_install/setup.sh 159 | 160 | ~# kubectl get pod --all-namespaces 161 | NAMESPACE NAME READY STATUS RESTARTS AGE 162 | kube-system calico-kube-controllers-fcc5cb8ff-tfm7v 1/1 Running 0 1m 163 | kube-system calico-node-bntsh 1/1 Running 0 1m 164 | kube-system calico-node-fbicr 1/1 Running 0 1m 165 | kube-system calico-node-badop 1/1 Running 0 1m 166 | kube-system calico-node-rcrze 1/1 Running 0 1m 167 | kube-system coredns-d44664bbd-596tr 1/1 Running 0 1m 168 | kube-system coredns-d44664bbd-h8h6m 1/1 Running 0 1m 169 | kube-system kubernetes-dashboard-7c5d596d8c-4zmt4 1/1 Running 0 1m 170 | kube-system tiller-deploy-546cf9696c-hjdbm 1/1 Running 0 1m 171 | kube-system heapster-55c5d9c56b-7drzs 1/1 Running 0 1m 172 | kube-system monitoring-grafana-5bccc9f786-f4lf2 1/1 Running 0 1m 173 | kube-system monitoring-influxdb-85cb4985d4-rd776 1/1 Running 0 1m 174 | ``` 175 | 176 | ## Good to know with internal salt PKI 177 | 178 | you need to start the pki at first, so you must add acl peer settings file `/etc/salt/master.d/client_acl.conf` to the salt master 179 | 180 | ```yaml 181 | ## use .* or another regexp rule 182 | peer: 183 | .*: 184 | - x509.sign_remote_certificate 185 | ``` 186 | 187 | and then add the `/etc/salt/minion.d/signing_policies.conf` on node01 (k8s master) 188 | ```bash 189 | salt 'node01*' k8s-certs 190 | ``` 191 | 192 | if `k8s-certs` is not a top folder, you need to add the relative path like `git.kubernetes.Kubernetes-Saltstack.k8s-certs` 193 | 194 | If you want add a node on your Kubernetes cluster, just add the role into the grains of the server, and then run the command on the new node 195 | 196 | ```bash 197 | salt -G 'role:k8s-master' state.highstate 198 | salt -G 'role:k8s-worker' state.highstate 199 | ``` 200 | 201 | ## Good to know with cfssl 202 | 203 | If you want add a node on your Kubernetes cluster, just add the new **Hostname** on `kubernetes-csr.json` and run theses commands : 204 | 205 | ```bash 206 | cd /srv/salt/k8s-certs 207 | 208 | cfssl gencert \ 209 | -ca=ca.pem \ 210 | -ca-key=ca-key.pem \ 211 | -config=ca-config.json \ 212 | -profile=kubernetes \ 213 | kubernetes-csr.json | cfssljson -bare kubernetes 214 | 215 | salt -G 'role:k8s-master' state.highstate 216 | salt -G 'role:k8s-worker' state.highstate 217 | ``` 218 | 219 | Last `highstate` reload your Kubernetes master and configure automatically new workers. 220 | 221 | - Tested on Debian, Ubuntu and Fedora. 222 | - You can easily upgrade software version on your cluster by changing values in `pillar/cluster_config.sls` and apply a `state.highstate`. 223 | - This configuration use ECDSA certificates (you can switch to `rsa` if needed in `certs/*.json`). 224 | - You can tweak Pod's IPv4 pool, enable IPv6, change IPv6 pool, enable IPv6 NAT (for no-public networks), change BGP AS number, Enable IPinIP (to allow routes sharing of different cloud providers). 225 | - If you use `salt-ssh` or `salt-cloud` you can quickly scale new workers. 226 | 227 | 228 | ## Support me on Patreon 229 | Help me out for a couple of :beers:! 230 | 231 | https://www.patreon.com/ValentinOuvrard 232 | -------------------------------------------------------------------------------- /init.sls: -------------------------------------------------------------------------------- 1 | --- 2 | {% if "k8s-master" in grains.get('role', []) or "k8s-worker" in grains.get('role', []) %} 3 | include: 4 | - .k8s-certs 5 | {% if "k8s-master" in grains.get('role', []) %} 6 | - .k8s-master 7 | {% endif %} 8 | {% if "k8s-worker" in grains.get('role', []) %} 9 | - .k8s-worker 10 | {% endif %} 11 | {% endif %} 12 | -------------------------------------------------------------------------------- /k8s-certs/ca-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "signing": { 3 | "default": { 4 | "expiry": "12000h" 5 | }, 6 | "profiles": { 7 | "kubernetes": { 8 | "usages": ["signing", "key encipherment", "server auth", "client auth"], 9 | "expiry": "12000h" 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /k8s-certs/ca-csr.json: -------------------------------------------------------------------------------- 1 | { 2 | "CN": "Kubernetes", 3 | "key": { 4 | "algo": "ecdsa", 5 | "size": 256 6 | }, 7 | "names": [ 8 | { 9 | "C": "ANY", 10 | "L": "Country", 11 | "O": "Kubernetes", 12 | "OU": "Cluster", 13 | "ST": "Local" 14 | } 15 | ] 16 | } 17 | 18 | -------------------------------------------------------------------------------- /k8s-certs/files.sls: -------------------------------------------------------------------------------- 1 | /var/lib/kubernetes: 2 | file.directory: 3 | - user: root 4 | - group: root 5 | - dir_mode: 750 6 | 7 | /var/lib/kubernetes/ca.pem: 8 | file.managed: 9 | - source: salt://{{ slspath }}/ca.pem 10 | - group: root 11 | - mode: 644 12 | 13 | /var/lib/kubernetes/ca-key.pem: 14 | file.managed: 15 | - source: salt://{{ slspath }}/ca-key.pem 16 | - group: root 17 | - mode: 600 18 | 19 | /var/lib/kubernetes/kubernetes-key.pem: 20 | file.managed: 21 | - source: salt://{{ slspath }}/kubernetes-key.pem 22 | - group: root 23 | - mode: 600 24 | 25 | /var/lib/kubernetes/kubernetes.pem: 26 | file.managed: 27 | - source: salt://{{ slspath }}/kubernetes.pem 28 | - group: root 29 | - mode: 644 30 | 31 | ## Token & Auth Policy 32 | /var/lib/kubernetes/token.csv: 33 | file.managed: 34 | - source: salt://{{ slspath }}/token.csv 35 | - template: jinja 36 | - group: root 37 | - mode: 600 38 | -------------------------------------------------------------------------------- /k8s-certs/init.sls: -------------------------------------------------------------------------------- 1 | {%- from slspath + "/k8s_params.jinja" import ca_host with context %} 2 | include: 3 | {%- if salt["pillar.get"]("kubernetes:pki:enable") %} 4 | - .x509-base 5 | {%- if ca_host == salt["grains.get"]("fqdn") %} 6 | - .x509-ca 7 | {%- endif %} 8 | {%- if ('/etc/salt/minion.d/signing_policies.conf' | is_text_file) and (salt["mine.get"](ca_host, "x509.get_pem_entries") or ca_host == salt["grains.get"]("fqdn")) %} 9 | - .x509-req 10 | - .x509-files 11 | {%- endif %} 12 | {% else %} 13 | - .files 14 | {%- endif %} 15 | -------------------------------------------------------------------------------- /k8s-certs/k8s_params.jinja: -------------------------------------------------------------------------------- 1 | {% set ca_certificates = salt['grains.filter_by']({ 2 | 'Debian': { 3 | 'path': '/usr/local/share/ca-certificates', 4 | 'command' : 'update-ca-certificates --fresh' 5 | }, 6 | 'RedHat': { 7 | 'path': '/etc/pki/ca-trust/source/anchors', 8 | 'command' : 'update-ca-trust' 9 | } 10 | }) 11 | %} 12 | {% set default_ca_host = salt["pillar.get"]("kubernetes:master:cluster:node01:hostname", salt["pillar.get"]("kubernetes:master:hostname")) %} 13 | {% set ca_host = salt["pillar.get"]("kubernetes:pki:host", default_ca_host) %} 14 | {% set pki_path = salt["pillar.get"]("kubernetes:pki:path","/opt/kubernetes/pki") %} 15 | {% set pki_cert = salt["pillar.get"]("kubernetes:pki:cert","kubernetes") %} 16 | {% set pki_ca = salt["pillar.get"]("kubernetes:pki:ca","kubernetes-ca") %} 17 | {% set wildcard = salt["pillar.get"]("kubernetes:pki:wildcard","*") %} 18 | 19 | # Select the m2crypt python pkg, depend of the osmalily and os version 20 | {% set m2crypto = salt['grains.filter_by']({ 21 | 'Debian': 'python3-m2crypto', 22 | 'RedHat': salt['grains.filter_by']({ 23 | '8': 'python3-m2crypto', 24 | '7': 'm2crypto' 25 | }, grain='osmajorrelease', default='8'), 26 | }) 27 | %} 28 | -------------------------------------------------------------------------------- /k8s-certs/kubernetes-csr.json: -------------------------------------------------------------------------------- 1 | { 2 | "CN": "kubernetes", 3 | "hosts": [ 4 | "10.32.0.1", 5 | "kubernetes.default", 6 | "kubernetes.default.svc.cluster.local", 7 | "ha-master-hostname.domain.tld", 8 | "", 9 | "", 10 | "127.0.0.1" 11 | ], 12 | "key": { 13 | "algo": "ecdsa", 14 | "size": 256 15 | }, 16 | "names": [ 17 | { 18 | "C": "ANY", 19 | "L": "Country", 20 | "O": "Kubernetes", 21 | "OU": "Cluster", 22 | "ST": "Local" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /k8s-certs/signing_policies.conf: -------------------------------------------------------------------------------- 1 | x509_signing_policies: 2 | internal: 3 | - minions: '{{ wildcard }}' 4 | - signing_private_key: {{ pki_path }}/{{ pki_ca }}.key 5 | - signing_cert: {{ pki_path }}/{{ pki_ca }}.crt 6 | - basicConstraints: "critical CA:false" 7 | - keyUsage: "critical keyEncipherment" 8 | - subjectKeyIdentifier: hash 9 | - authorityKeyIdentifier: keyid,issuer:always 10 | - copypath: {{ pki_path }}/issued_certs 11 | -------------------------------------------------------------------------------- /k8s-certs/token.csv: -------------------------------------------------------------------------------- 1 | {%- set adminToken = pillar['kubernetes']['global']['admin-token'] -%} 2 | {%- set kubeletToken = pillar['kubernetes']['global']['kubelet-token'] -%} 3 | {%- set calicoToken = pillar['kubernetes']['worker']['networking']['calico']['token'] -%} 4 | 5 | {{ adminToken }},admin,admin,"cluster-admin,system:masters" 6 | {{ calicoToken }},calico,calico,"cluster-admin,system:masters" 7 | {{ kubeletToken }},kubelet,kubelet,"cluster-admin,system:masters" 8 | -------------------------------------------------------------------------------- /k8s-certs/x509-base.sls: -------------------------------------------------------------------------------- 1 | --- 2 | {%- import slspath + "/k8s_params.jinja" as params with context %} 3 | /var/lib/kubernetes: 4 | file.directory: 5 | - user: root 6 | - group: root 7 | - dir_mode: 750 8 | 9 | k8s_salt_x509_module: 10 | pkg.installed: 11 | - name: {{ params.m2crypto }} 12 | - reload_modules: True 13 | file.directory: 14 | - name: {{ params.pki_path }} 15 | - makedirs: True 16 | - mode: 0700 17 | -------------------------------------------------------------------------------- /k8s-certs/x509-ca.sls: -------------------------------------------------------------------------------- 1 | --- 2 | {%- import slspath + "/k8s_params.jinja" as params with context %} 3 | k8s_ca_certs_dir: 4 | file.directory: 5 | - name: "{{ params.pki_path }}/issued_certs" 6 | - makedirs: True 7 | 8 | k8s_ca_signing_key: 9 | x509.private_key_managed: 10 | - name: "{{ params.pki_path }}/{{ params.pki_ca }}.key" 11 | - bits: 4096 12 | - require: 13 | - file: k8s_ca_certs_dir 14 | 15 | k8s_ca_root_cert: 16 | x509.certificate_managed: 17 | - name: "{{ params.pki_path }}/{{ params.pki_ca }}.crt" 18 | - signing_private_key: "{{ params.pki_path }}/{{ params.pki_ca }}.key" 19 | - CN: {{grains['id']}} 20 | - basicConstraints: "critical CA:true" 21 | - keyUsage: "critical cRLSign, keyCertSign" 22 | - subjectKeyIdentifier: hash 23 | - authorityKeyIdentifier: keyid,issuer:always 24 | - days_valid: 3650 25 | - days_remaining: 0 26 | - backup: True 27 | - require: 28 | - x509: k8s_ca_signing_key 29 | 30 | mine.send: 31 | module.run: 32 | - func: x509.get_pem_entries 33 | - kwargs: 34 | glob_path: "{{ params.pki_path }}/{{ params.pki_ca }}.*" 35 | - onchanges: 36 | - x509: k8s_ca_root_cert 37 | 38 | k8s_ca_signing_policies: 39 | file.managed: 40 | - name: /etc/salt/minion.d/signing_policies.conf 41 | - source: salt://{{ slspath }}/signing_policies.conf 42 | - template: jinja 43 | - context: 44 | pki_path: {{ params.pki_path }} 45 | pki_ca: {{ params.pki_ca }} 46 | wildcard: '{{ params.wildcard }}' 47 | service.running: 48 | - name: salt-minion 49 | - watch: 50 | - file: k8s_ca_signing_policies 51 | -------------------------------------------------------------------------------- /k8s-certs/x509-files.sls: -------------------------------------------------------------------------------- 1 | --- 2 | {%- import slspath + "/k8s_params.jinja" as params with context %} 3 | /var/lib/kubernetes/ca.pem: 4 | file.managed: 5 | - source: {{ params.ca_certificates.path }}/{{ params.pki_ca }}.crt 6 | - group: root 7 | - mode: 644 8 | 9 | /var/lib/kubernetes/kubernetes-key.pem: 10 | file.managed: 11 | - source: {{ params.pki_path }}/{{ params.pki_cert }}.key 12 | - group: root 13 | - mode: 600 14 | 15 | /var/lib/kubernetes/kubernetes.pem: 16 | file.managed: 17 | - source: {{ params.pki_path }}/{{ params.pki_cert }}.crt 18 | - group: root 19 | - mode: 644 20 | 21 | ## Token & Auth Policy 22 | /var/lib/kubernetes/token.csv: 23 | file.managed: 24 | - source: salt://{{ slspath }}/token.csv 25 | - template: jinja 26 | - group: root 27 | - mode: 600 28 | -------------------------------------------------------------------------------- /k8s-certs/x509-req.sls: -------------------------------------------------------------------------------- 1 | --- 2 | {%- import slspath + "/k8s_params.jinja" as params with context %} 3 | {%- set ten_days = salt['x509.will_expire'](params.pki_path + '/' + params.pki_cert +'.crt',10) %} 4 | k8s_internal_ca: 5 | {%- if params.ca_host == salt["grains.get"]("fqdn") %} 6 | file.managed: 7 | - name: "{{ params.ca_certificates.path }}/{{ params.pki_ca }}.crt" 8 | - source: "{{ params.pki_path }}/{{ params.pki_ca }}.crt" 9 | - makedirs: True 10 | {% else %} 11 | file.directory: 12 | - name: "{{ params.ca_certificates.path }}" 13 | x509.pem_managed: 14 | - name: "{{ params.ca_certificates.path }}/{{ params.pki_ca }}.crt" 15 | - text: {{ salt["mine.get"](params.ca_host, "x509.get_pem_entries") | traverse(params.ca_host + ":" + params.pki_path + "/" + params.pki_ca + ".crt") | replace("\n", "") }} 16 | {%- endif %} 17 | cmd.run: 18 | - name: {{ params.ca_certificates.command }} 19 | - onchanges: 20 | {%- if params.ca_host == salt["grains.get"]("fqdn") %} 21 | - file: k8s_internal_ca 22 | {% else %} 23 | - x509: k8s_internal_ca 24 | {%- endif %} 25 | 26 | k8s_internal_ca_key: 27 | {%- if params.ca_host == salt["grains.get"]("fqdn") %} 28 | file.managed: 29 | - name: "/var/lib/kubernetes/ca-key.pem" 30 | - source: "{{ params.pki_path }}/{{ params.pki_ca }}.key" 31 | {% else %} 32 | x509.pem_managed: 33 | - name: "/var/lib/kubernetes/ca-key.pem" 34 | - text: {{ salt["mine.get"](params.ca_host, "x509.get_pem_entries") | traverse(params.ca_host + ":" + params.pki_path + "/" + params.pki_ca + ".key") | replace("\n", "") }} 35 | - makedirs: True 36 | {%- endif %} 37 | 38 | k8s_key: 39 | x509.private_key_managed: 40 | - name: "{{ params.pki_path }}/{{ params.pki_cert }}.key" 41 | - bits: 4096 42 | 43 | {%- set ip_list = [] %} 44 | {%- do ip_list.append("IP:" + ((salt["pillar.get"]("kubernetes:global:clusterIP-range","10.32.0.0/16").split("/")[0] + "/30") | ipaddr | network_hosts)[0]) %} 45 | {%- for ip in salt['grains.get']('ipv4') %} 46 | {%- do ip_list.append("IP:" + ip) %} 47 | {%- endfor %} 48 | 49 | {%- if ten_days.will_expire | default(True) %} 50 | k8s_cert: 51 | x509.certificate_managed: 52 | - name: "{{ params.pki_path }}/{{ params.pki_cert }}.crt" 53 | - ca_server: {{ params.ca_host }} 54 | - signing_policy: internal 55 | - public_key: "{{ params.pki_path }}/{{ params.pki_cert }}.key" 56 | - CN: {{ salt['grains.get']('fqdn') }} 57 | - subjectAltName: 'DNS:{{ salt["grains.get"]("fqdn") }}, {{ ip_list | join(", ") }}' 58 | - days_valid: 365 59 | - days_remaining: 10 60 | {%- endif %} 61 | -------------------------------------------------------------------------------- /k8s-master/encryption-config.yaml: -------------------------------------------------------------------------------- 1 | {%- set encryptionKey = pillar['kubernetes']['master']['encryption-key'] -%} 2 | kind: EncryptionConfig 3 | apiVersion: v1 4 | resources: 5 | - resources: 6 | - secrets 7 | providers: 8 | - aescbc: 9 | keys: 10 | - name: key1 11 | secret: {{ encryptionKey }} 12 | - identity: {} 13 | -------------------------------------------------------------------------------- /k8s-master/etcd/etcd-ha.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | {%- set clusterDomain = pillar['kubernetes']['domain'] -%} 3 | {%- set hostname = salt['grains.get']('fqdn') -%} 4 | {%- set ip = salt['grains.get']('fqdn_ip4') -%} 5 | {%- set node01ip = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 6 | {%- set node02ip = pillar['kubernetes']['master']['cluster']['node02']['ipaddr'] -%} 7 | {%- set node03ip = pillar['kubernetes']['master']['cluster']['node03']['ipaddr'] -%} 8 | {%- set node01 = pillar['kubernetes']['master']['cluster']['node01']['hostname'] -%} 9 | {%- set node02 = pillar['kubernetes']['master']['cluster']['node02']['hostname'] -%} 10 | {%- set node03 = pillar['kubernetes']['master']['cluster']['node03']['hostname'] -%} 11 | {%- set clustername = pillar['kubernetes']['master']['cluster']['name'] | default("kubernetes-cluster")-%} 12 | {% if hostname == node01 %} 13 | {% set currentip = node01ip %} 14 | {% elif hostname == node02 %} 15 | {% set currentip = node02ip %} 16 | {% elif hostname == node03 %} 17 | {% set currentip = node03ip %} 18 | {% else %} 19 | {% set currentip = "0.0.0.0" %} 20 | {% endif %} 21 | 22 | [Unit] 23 | Description=etcd 24 | Documentation=https://github.com/coreos 25 | 26 | [Service] 27 | ExecStart=/usr/bin/etcd \ 28 | --name={{ hostname }} \ 29 | --data-dir=/var/lib/etcd \ 30 | --cert-file=/etc/etcd/kubernetes.pem \ 31 | --key-file=/etc/etcd/kubernetes-key.pem \ 32 | --peer-cert-file=/etc/etcd/kubernetes.pem \ 33 | --peer-key-file=/etc/etcd/kubernetes-key.pem \ 34 | --trusted-ca-file=/etc/etcd/ca.pem \ 35 | --peer-trusted-ca-file=/etc/etcd/ca.pem \ 36 | --listen-client-urls https://{{ currentip }}:2379 \ 37 | --advertise-client-urls https://{{ currentip }}:2379 \ 38 | --listen-peer-urls https://{{ currentip }}:2380 \ 39 | --initial-advertise-peer-urls https://{{ currentip }}:2380 \ 40 | --initial-cluster {{ node01 }}=https://{{ node01ip }}:2380,{{ node02 }}=https://{{ node02ip }}:2380,{{ node03 }}=https://{{ node03ip }}:2380 \ 41 | --initial-cluster-state new \ 42 | --peer-client-cert-auth \ 43 | --client-cert-auth 44 | 45 | Restart=on-failure 46 | RestartSec=5 47 | LimitNOFILE=30000 48 | 49 | [Install] 50 | WantedBy=multi-user.target 51 | 52 | 53 | 54 | #--initial-cluster-token {{ clustername }} \ 55 | -------------------------------------------------------------------------------- /k8s-master/etcd/etcd.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | {%- set clusterDomain = pillar['kubernetes']['domain'] -%} 3 | [Unit] 4 | Description=etcd 5 | Documentation=https://github.com/coreos 6 | 7 | [Service] 8 | ExecStart=/usr/bin/etcd \ 9 | --name {{ clusterDomain }} \ 10 | --data-dir=/var/lib/etcd \ 11 | --cert-file=/etc/etcd/kubernetes.pem \ 12 | --key-file=/etc/etcd/kubernetes-key.pem \ 13 | --peer-cert-file=/etc/etcd/kubernetes.pem \ 14 | --peer-key-file=/etc/etcd/kubernetes-key.pem \ 15 | --trusted-ca-file=/etc/etcd/ca.pem \ 16 | --listen-client-urls https://0.0.0.0:2379 \ 17 | --advertise-client-urls https://0.0.0.0:2379 \ 18 | --listen-peer-urls https://0.0.0.0:2380 \ 19 | --initial-advertise-peer-urls https://0.0.0.0:2380 \ 20 | --peer-client-cert-auth \ 21 | --client-cert-auth 22 | 23 | Restart=on-failure 24 | RestartSec=5 25 | LimitNOFILE=30000 26 | 27 | [Install] 28 | WantedBy=multi-user.target 29 | -------------------------------------------------------------------------------- /k8s-master/etcd/init.sls: -------------------------------------------------------------------------------- 1 | {%- set etcdVersion = pillar['kubernetes']['master']['etcd']['version'] -%} 2 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 3 | 4 | /etc/etcd: 5 | file.directory: 6 | - user: root 7 | - group: root 8 | - dir_mode: 750 9 | 10 | /etc/etcd/kubernetes-key.pem: 11 | file.symlink: 12 | - target: /var/lib/kubernetes/kubernetes-key.pem 13 | /etc/etcd/kubernetes.pem: 14 | file.symlink: 15 | - target: /var/lib/kubernetes/kubernetes.pem 16 | /etc/etcd/ca.pem: 17 | file.symlink: 18 | - target: /var/lib/kubernetes/ca.pem 19 | 20 | etcd-latest-archive: 21 | archive.extracted: 22 | - name: /opt/ 23 | - source: https://github.com/coreos/etcd/releases/download/{{ etcdVersion }}/etcd-{{ etcdVersion }}-linux-amd64.tar.gz 24 | - skip_verify: true 25 | - archive_format: tar 26 | 27 | /usr/bin/etcd: 28 | file.symlink: 29 | - target: /opt/etcd-{{ etcdVersion }}-linux-amd64/etcd 30 | /usr/bin/etcdctl: 31 | file.symlink: 32 | - target: /opt/etcd-{{ etcdVersion }}-linux-amd64/etcdctl 33 | 34 | {% if masterCount == 1 %} 35 | /etc/systemd/system/etcd.service: 36 | file.managed: 37 | - source: salt://{{ slspath }}/etcd.service 38 | - user: root 39 | - template: jinja 40 | - group: root 41 | - mode: 644 42 | {% elif masterCount == 3 %} 43 | /etc/systemd/system/etcd.service: 44 | file.managed: 45 | - source: salt://{{ slspath }}/etcd-ha.service 46 | - user: root 47 | - template: jinja 48 | - group: root 49 | - mode: 644 50 | {% endif %} 51 | 52 | etcd: 53 | service.running: 54 | - enable: True 55 | - watch: 56 | - /etc/systemd/system/etcd.service 57 | - /etc/etcd/kubernetes.pem 58 | - /etc/etcd/ca.pem 59 | - /usr/bin/etcd 60 | -------------------------------------------------------------------------------- /k8s-master/init.sls: -------------------------------------------------------------------------------- 1 | {%- set k8sVersion = pillar['kubernetes']['version'] -%} 2 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 3 | {% set post_install_files = [ 4 | "coredns.yaml", "grafana.yaml", "heapster-rbac.yaml", "heapster.yaml", 5 | "influxdb.yaml", "metallb-configmap.yaml", "policy-controller.yaml", "rbac-calico.yaml", "rbac-tiller.yaml", "setup.sh"] %} 6 | 7 | # set empty if k8s-master is at the same level of top.sls 8 | # set if k8s-master is in a sub folder 9 | {% set root_path = "" if ((slspath | wordcount) < 3) else slspath.split("/")[0] %} 10 | 11 | include: 12 | - .etcd 13 | 14 | /usr/bin/kube-apiserver: 15 | file.managed: 16 | - source: https://storage.googleapis.com/kubernetes-release/release/{{ k8sVersion }}/bin/linux/amd64/kube-apiserver 17 | - skip_verify: true 18 | - group: root 19 | - mode: 755 20 | 21 | /usr/bin/kube-controller-manager: 22 | file.managed: 23 | - source: https://storage.googleapis.com/kubernetes-release/release/{{ k8sVersion }}/bin/linux/amd64/kube-controller-manager 24 | - skip_verify: true 25 | - group: root 26 | - mode: 755 27 | 28 | /usr/bin/kube-scheduler: 29 | file.managed: 30 | - source: https://storage.googleapis.com/kubernetes-release/release/{{ k8sVersion }}/bin/linux/amd64/kube-scheduler 31 | - skip_verify: true 32 | - group: root 33 | - mode: 755 34 | 35 | /usr/bin/kubectl: 36 | file.managed: 37 | - source: https://storage.googleapis.com/kubernetes-release/release/{{ k8sVersion }}/bin/linux/amd64/kubectl 38 | - skip_verify: true 39 | - group: root 40 | - mode: 755 41 | {% if masterCount == 1 %} 42 | /etc/systemd/system/kube-apiserver.service: 43 | file.managed: 44 | - source: salt://{{ slspath }}/kube-apiserver.service 45 | - user: root 46 | - template: jinja 47 | - group: root 48 | - mode: 644 49 | {% elif masterCount == 3 %} 50 | /etc/systemd/system/kube-apiserver.service: 51 | file.managed: 52 | - source: salt://{{ slspath }}/kube-apiserver-ha.service 53 | - user: root 54 | - template: jinja 55 | - group: root 56 | - mode: 644 57 | {% endif %} 58 | 59 | /etc/systemd/system/kube-controller-manager.service: 60 | file.managed: 61 | - source: salt://{{ slspath }}/kube-controller-manager.service 62 | - user: root 63 | - template: jinja 64 | - group: root 65 | - mode: 644 66 | 67 | /etc/systemd/system/kube-scheduler.service: 68 | file.managed: 69 | - source: salt://{{ slspath }}/kube-scheduler.service 70 | - user: root 71 | - template: jinja 72 | - group: root 73 | - mode: 644 74 | 75 | /var/lib/kubernetes/encryption-config.yaml: 76 | file.managed: 77 | - source: salt://{{ slspath }}/encryption-config.yaml 78 | - user: root 79 | - template: jinja 80 | - group: root 81 | - mode: 644 82 | 83 | {%- set cniProvider = pillar['kubernetes']['worker']['networking']['provider'] -%} 84 | {% if cniProvider == "calico" %} 85 | 86 | /opt/calico.yaml: 87 | file.managed: 88 | - source: salt://{{ root_path }}/k8s-worker/cni/calico/calico.tmpl.yaml 89 | - user: root 90 | - template: jinja 91 | - group: root 92 | - mode: 644 93 | {% endif %} 94 | 95 | {% for file in post_install_files %} 96 | /opt/kubernetes/post_install/{{ file }}: 97 | file.managed: 98 | - source: salt://{{ root_path }}/post_install/{{ file }} 99 | - makedirs: true 100 | - template: jinja 101 | - user: root 102 | - group: root 103 | {% if file == "setup.sh" %} 104 | - mode: 755 105 | {% else %} 106 | - mode: 644 107 | {% endif %} 108 | {% endfor %} 109 | 110 | 111 | {% set cniProvider = pillar['kubernetes']['worker']['networking']['provider'] %} 112 | {% if cniProvider == "calico" %} 113 | {% set calicoctlVersion = pillar['kubernetes']['worker']['networking']['calico']['calicoctl-version'] %} 114 | 115 | /etc/calico: 116 | file.directory: 117 | - user: root 118 | - group: root 119 | - dir_mode: 750 120 | 121 | /etc/calico/calicoctl.cfg-master: 122 | file.managed: 123 | - name: /etc/calico/calicoctl.cfg 124 | - source: salt://k8s-worker/cni/calico/calicoctl.cfg 125 | - user: root 126 | - template: jinja 127 | - group: root 128 | - mode: 640 129 | 130 | /usr/bin/calicoctl-master: 131 | file.managed: 132 | - name: /usr/bin/calicoctl 133 | - source: https://github.com/projectcalico/calicoctl/releases/download/{{ calicoctlVersion }}/calicoctl 134 | - skip_verify: true 135 | - group: root 136 | - mode: 755 137 | 138 | {% endif %} 139 | 140 | kube-apiserver: 141 | service.running: 142 | - enable: True 143 | - watch: 144 | - /etc/systemd/system/kube-apiserver.service 145 | - /var/lib/kubernetes/kubernetes.pem 146 | - /var/lib/kubernetes/ca.pem 147 | - /usr/bin/kube-apiserver 148 | kube-controller-manager: 149 | service.running: 150 | - enable: True 151 | - watch: 152 | - /etc/systemd/system/kube-controller-manager.service 153 | - /var/lib/kubernetes/kubernetes.pem 154 | - /var/lib/kubernetes/ca.pem 155 | - /usr/bin/kube-controller-manager 156 | kube-scheduler: 157 | service.running: 158 | - enable: True 159 | - watch: 160 | - /etc/systemd/system/kube-scheduler.service 161 | - /var/lib/kubernetes/kubernetes.pem 162 | - /var/lib/kubernetes/ca.pem 163 | - /usr/bin/kube-scheduler 164 | -------------------------------------------------------------------------------- /k8s-master/kube-apiserver-ha.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | {%- set clusterIpRange = pillar['kubernetes']['global']['clusterIP-range'] -%} 3 | {%- set hostname = salt['grains.get']('fqdn') -%} 4 | {%- set node01 = pillar['kubernetes']['master']['cluster']['node01']['hostname'] -%} 5 | {%- set node02 = pillar['kubernetes']['master']['cluster']['node02']['hostname'] -%} 6 | {%- set node03 = pillar['kubernetes']['master']['cluster']['node03']['hostname'] -%} 7 | {%- set node01ip = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 8 | {%- set node02ip = pillar['kubernetes']['master']['cluster']['node02']['ipaddr'] -%} 9 | {%- set node03ip = pillar['kubernetes']['master']['cluster']['node03']['ipaddr'] -%} 10 | {% if hostname == node01 %} 11 | {% set currentip = node01ip %} 12 | {% elif hostname == node02 %} 13 | {% set currentip = node02ip %} 14 | {% elif hostname == node03 %} 15 | {% set currentip = node03ip %} 16 | {% else %} 17 | {% set currentip = "127.0.0.1" %} 18 | {% endif %} 19 | 20 | [Unit] 21 | Description=Kubernetes API Server 22 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 23 | 24 | [Service] 25 | ExecStart=/usr/bin/kube-apiserver \ 26 | --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota \ 27 | --advertise-address={{ currentip }} \ 28 | --bind-address=0.0.0.0 \ 29 | --audit-log-maxage=30 \ 30 | --audit-log-maxbackup=3 \ 31 | --audit-log-maxsize=100 \ 32 | --audit-log-path=/var/lib/audit.log \ 33 | --allow-privileged=true \ 34 | --authorization-mode=RBAC \ 35 | --enable-swagger-ui=true \ 36 | --etcd-cafile=/var/lib/kubernetes/ca.pem \ 37 | --etcd-certfile=/var/lib/kubernetes/kubernetes.pem \ 38 | --etcd-keyfile=/var/lib/kubernetes/kubernetes-key.pem \ 39 | --kubelet-certificate-authority=/var/lib/kubernetes/ca.pem \ 40 | --client-ca-file=/var/lib/kubernetes/ca.pem \ 41 | --service-cluster-ip-range={{ clusterIpRange }} \ 42 | --service-node-port-range=30000-32767 \ 43 | --tls-cert-file=/var/lib/kubernetes/kubernetes.pem \ 44 | --tls-private-key-file=/var/lib/kubernetes/kubernetes-key.pem \ 45 | --enable-bootstrap-token-auth \ 46 | --token-auth-file=/var/lib/kubernetes/token.csv \ 47 | --service-account-key-file=/var/lib/kubernetes/ca-key.pem \ 48 | --runtime-config=batch/v2alpha1=true \ 49 | --insecure-bind-address=127.0.0.1 \ 50 | --event-ttl=1h \ 51 | --apiserver-count=1 \ 52 | --kubelet-https=true \ 53 | --apiserver-count=3 \ 54 | --runtime-config=api/all \ 55 | --experimental-encryption-provider-config=/var/lib/kubernetes/encryption-config.yaml \ 56 | --etcd-servers=https://{{ node01ip }}:2379,https://{{ node02ip }}:2379,https://{{ node03ip }}:2379 \ 57 | --v=2 58 | Restart=on-failure 59 | RestartSec=5 60 | 61 | [Install] 62 | WantedBy=multi-user.target 63 | -------------------------------------------------------------------------------- /k8s-master/kube-apiserver.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | {%- set clusterIpRange = pillar['kubernetes']['global']['clusterIP-range'] -%} 3 | [Unit] 4 | Description=Kubernetes API Server 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | ExecStart=/usr/bin/kube-apiserver \ 9 | --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota \ 10 | --advertise-address=0.0.0.0 \ 11 | --bind-address=0.0.0.0 \ 12 | --audit-log-maxage=30 \ 13 | --audit-log-maxbackup=3 \ 14 | --audit-log-maxsize=100 \ 15 | --audit-log-path=/var/lib/audit.log \ 16 | --allow-privileged=true \ 17 | --authorization-mode=RBAC \ 18 | --enable-swagger-ui=true \ 19 | --enable-bootstrap-token-auth \ 20 | --etcd-cafile=/var/lib/kubernetes/ca.pem \ 21 | --etcd-certfile=/var/lib/kubernetes/kubernetes.pem \ 22 | --etcd-keyfile=/var/lib/kubernetes/kubernetes-key.pem \ 23 | --kubelet-certificate-authority=/var/lib/kubernetes/ca.pem \ 24 | --client-ca-file=/var/lib/kubernetes/ca.pem \ 25 | --service-cluster-ip-range={{ clusterIpRange }} \ 26 | --service-node-port-range=30000-32767 \ 27 | --tls-cert-file=/var/lib/kubernetes/kubernetes.pem \ 28 | --tls-private-key-file=/var/lib/kubernetes/kubernetes-key.pem \ 29 | --token-auth-file=/var/lib/kubernetes/token.csv \ 30 | --service-account-key-file=/var/lib/kubernetes/ca-key.pem \ 31 | --runtime-config=batch/v2alpha1=true \ 32 | --etcd-servers=https://127.0.0.1:2379 \ 33 | --insecure-bind-address=127.0.0.1 \ 34 | --event-ttl=1h \ 35 | --apiserver-count=1 \ 36 | --kubelet-https=true \ 37 | --v=2 38 | Restart=on-failure 39 | RestartSec=5 40 | 41 | [Install] 42 | WantedBy=multi-user.target 43 | -------------------------------------------------------------------------------- /k8s-master/kube-controller-manager.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | {%- set clusterIpRange = pillar['kubernetes']['global']['clusterIP-range'] -%} 3 | [Unit] 4 | Description=Kubernetes Controller Manager 5 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 6 | 7 | [Service] 8 | ExecStart=/usr/bin/kube-controller-manager \ 9 | --cluster-name=kubernetes \ 10 | --leader-elect=true \ 11 | --master=http://127.0.0.1:8080 \ 12 | --root-ca-file=/var/lib/kubernetes/ca.pem \ 13 | --pod-eviction-timeout 30s \ 14 | --service-account-private-key-file=/var/lib/kubernetes/ca-key.pem \ 15 | --cluster-name=kubernetes \ 16 | --cluster-signing-cert-file=/var/lib/kubernetes/ca.pem \ 17 | --cluster-signing-key-file=/var/lib/kubernetes/ca-key.pem \ 18 | --service-cluster-ip-range={{ clusterIpRange }} \ 19 | --node-startup-grace-period 30s \ 20 | --v=2 21 | 22 | Restart=on-failure 23 | RestartSec=5 24 | 25 | [Install] 26 | WantedBy=multi-user.target 27 | -------------------------------------------------------------------------------- /k8s-master/kube-scheduler.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | [Unit] 3 | Description=Kubernetes Scheduler 4 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 5 | 6 | [Service] 7 | ExecStart=/usr/bin/kube-scheduler \ 8 | --leader-elect=true \ 9 | --master=http://127.0.0.1:8080 \ 10 | --v=2 11 | Restart=on-failure 12 | RestartSec=5 13 | 14 | [Install] 15 | WantedBy=multi-user.target 16 | -------------------------------------------------------------------------------- /k8s-worker/cni/calico/10-calico.conf: -------------------------------------------------------------------------------- 1 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 2 | {% if masterCount == 1 %} 3 | {%- set k8sMaster = pillar['kubernetes']['master']['ipaddr'] -%} 4 | {% elif masterCount == 3 %} 5 | {%- set k8sMaster = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 6 | {% endif %} 7 | {%- set enableIPv6 = pillar['kubernetes']['worker']['networking']['calico']['ipv6']['enable'] -%} 8 | {% if enableIPv6 == true %} 9 | {%- set IPv6env = "true" -%} 10 | {% else %} 11 | {%- set IPv6env = "false" -%} 12 | {% endif %} 13 | { 14 | "name": "calico-k8s-network", 15 | "cniVersion": "0.1.0", 16 | "type": "calico", 17 | "datastore_type": "etcdv3", 18 | "etcd_endpoints": "https://{{ k8sMaster }}:2379", 19 | "etcd_key_file": "/var/lib/kubernetes/kubernetes-key.pem", 20 | "etcd_cert_file": "/var/lib/kubernetes/kubernetes.pem", 21 | "etcd_ca_cert_file": "/var/lib/kubernetes/ca.pem", 22 | "ipam": { 23 | "type": "calico-ipam", 24 | "assign_ipv4": "true", 25 | "assign_ipv6": "{{ IPv6env }}" 26 | }, 27 | "policy": { 28 | "type": "k8s" 29 | }, 30 | "kubernetes": { 31 | "kubeconfig": "/etc/calico/kube/kubeconfig" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /k8s-worker/cni/calico/calico.tmpl.yaml: -------------------------------------------------------------------------------- 1 | {%- set calicoNodeVersion = pillar['kubernetes']['worker']['networking']['calico']['version'] -%} 2 | {%- set ipv4Range = pillar['kubernetes']['worker']['networking']['calico']['ipv4']['range'] -%} 3 | {%- set ipv6Interface = pillar['kubernetes']['worker']['networking']['calico']['ipv6']['interface'] -%} 4 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 5 | {%- set enableIPv6 = pillar['kubernetes']['worker']['networking']['calico']['ipv6']['enable'] -%} 6 | {%- set enableNATIPv6 = pillar['kubernetes']['worker']['networking']['calico']['ipv6']['nat'] -%} 7 | {%- set ipv6Range = pillar['kubernetes']['worker']['networking']['calico']['ipv6']['range'] -%} 8 | {% if masterCount == 1 %} 9 | {%- set etcdEndpoint = pillar['kubernetes']['master']['ipaddr'] -%} 10 | {%- set hostname = pillar['kubernetes']['master']['hostname'] -%} 11 | {% elif masterCount == 3 %} 12 | {%- set etcdEndpoint = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 13 | {%- set hostname = pillar['kubernetes']['master']['cluster']['node01']['hostname'] -%} 14 | {% endif %} 15 | {%- set IpIp = pillar['kubernetes']['worker']['networking']['calico']['ipv4']['ip-in-ip'] -%} 16 | {% if IpIp == true %} 17 | {%- set IpIpenv = "always" -%} 18 | {% else %} 19 | {%- set IpIpenv = "off" -%} 20 | {% endif %} 21 | {% if enableIPv6 == true %} 22 | {%- set IPv6env = "autodetect" -%} 23 | {%- set ipv6preInterface = "interface=" -%} 24 | {% else %} 25 | {%- set IPv6env = "none" -%} 26 | {%- set ipv6preInterface = "interface=" -%} 27 | {% endif %} 28 | # Calico Version master 29 | # https://docs.projectcalico.org/master/releases#master 30 | # This manifest includes the following component versions: 31 | # calico/node:master 32 | # calico/cni:master 33 | # calico/kube-controllers:master 34 | kind: DaemonSet 35 | apiVersion: apps/v1 36 | metadata: 37 | name: calico-node 38 | namespace: kube-system 39 | labels: 40 | k8s-app: calico-node 41 | spec: 42 | selector: 43 | matchLabels: 44 | k8s-app: calico-node 45 | updateStrategy: 46 | type: RollingUpdate 47 | rollingUpdate: 48 | maxUnavailable: 1 49 | template: 50 | metadata: 51 | labels: 52 | k8s-app: calico-node 53 | annotations: 54 | scheduler.alpha.kubernetes.io/critical-pod: '' 55 | scheduler.alpha.kubernetes.io/tolerations: | 56 | [{"key": "dedicated", "value": "master", "effect": "NoSchedule" }, 57 | {"key":"CriticalAddonsOnly", "operator":"Exists"}] 58 | spec: 59 | hostNetwork: true 60 | serviceAccountName: calico-node 61 | # Minimize downtime during a rolling upgrade or deletion; tell Kubernetes to do a "force 62 | # deletion": https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods. 63 | terminationGracePeriodSeconds: 0 64 | containers: 65 | # Runs calico/node container on each Kubernetes node. This 66 | # container programs network policy and routes on each 67 | # host. 68 | - name: calico-node 69 | image: quay.io/calico/node:{{ calicoNodeVersion }} 70 | env: 71 | # The location of the Calico etcd cluster. 72 | - name: ETCD_ENDPOINTS 73 | value: "https://{{ etcdEndpoint }}:2379" 74 | - name: ETCD_CA_CERT_FILE 75 | value: "/var/lib/kubernetes/ca.pem" 76 | # Location of the client key for etcd. 77 | - name: ETCD_KEY_FILE 78 | value: "/var/lib/kubernetes/kubernetes-key.pem" 79 | # Location of the client certificate for etcd. 80 | - name: ETCD_CERT_FILE 81 | value: "/var/lib/kubernetes/kubernetes.pem" 82 | # Choose the backend to use. 83 | - name: CALICO_NETWORKING_BACKEND 84 | value: bird 85 | # Cluster type to identify the deployment type 86 | - name: CLUSTER_TYPE 87 | value: "k8s,bgp" 88 | # Disable file logging so `kubectl logs` works. 89 | - name: CALICO_DISABLE_FILE_LOGGING 90 | value: "true" 91 | # Set noderef for node controller. 92 | - name: CALICO_K8S_NODE_REF 93 | valueFrom: 94 | fieldRef: 95 | fieldPath: spec.nodeName 96 | # Set Felix endpoint to host default action to ACCEPT. 97 | - name: FELIX_DEFAULTENDPOINTTOHOSTACTION 98 | value: "ACCEPT" 99 | - name: FELIX_HEALTHHOST 100 | value: "0.0.0.0" 101 | # Configure the IP Pool from which Pod IPs will be chosen. 102 | - name: CALICO_IPV4POOL_CIDR 103 | value: "{{ ipv4Range }}" 104 | - name: CALICO_IPV4POOL_IPIP 105 | value: "{{ IpIpenv }}" 106 | - name: CALICO_IPV6POOL_CIDR 107 | value: "{{ ipv6Range }}" 108 | - name: FELIX_IPV6SUPPORT 109 | value: "true" 110 | # Set Felix logging to "info" 111 | - name: FELIX_LOGSEVERITYSCREEN 112 | value: "info" 113 | # Auto-detect the BGP IP address. 114 | - name: IP 115 | value: "" 116 | - name: IP6 117 | value: "{{ IPv6env }}" 118 | - name: IP_AUTODETECTION_METHOD 119 | value: "first-found" 120 | - name: IP6_AUTODETECTION_METHOD 121 | value: "{{ ipv6preInterface }}{{ ipv6Interface }}" 122 | - name: CALICO_IPV6POOL_NAT_OUTGOING 123 | value: "{{ enableNATIPv6 }}" 124 | - name: FELIX_HEALTHENABLED 125 | value: "true" 126 | securityContext: 127 | privileged: true 128 | resources: 129 | requests: 130 | cpu: 250m 131 | livenessProbe: 132 | httpGet: 133 | path: /liveness 134 | port: 9099 135 | periodSeconds: 10 136 | initialDelaySeconds: 10 137 | failureThreshold: 6 138 | readinessProbe: 139 | httpGet: 140 | path: /readiness 141 | port: 9099 142 | periodSeconds: 10 143 | volumeMounts: 144 | - mountPath: /lib/modules 145 | name: lib-modules 146 | readOnly: true 147 | - mountPath: /var/run/calico 148 | name: var-run-calico 149 | readOnly: false 150 | - mountPath: /var/lib/kubernetes 151 | name: var-lib-k8s 152 | readOnly: true 153 | - mountPath: /var/lib/calico 154 | name: var-lib-calico 155 | - mountPath: /etc/cni/net.d 156 | name: cni-net-dir 157 | readOnly: true 158 | 159 | # This container installs the Calico CNI binaries 160 | # and CNI network config file on each node. 161 | volumes: 162 | # Used by calico/node. 163 | - name: lib-modules 164 | hostPath: 165 | path: /lib/modules 166 | - name: var-run-calico 167 | hostPath: 168 | path: /var/run/calico 169 | # Used to install CNI. 170 | - name: cni-net-dir 171 | hostPath: 172 | path: /etc/cni/net.d 173 | - name: var-lib-k8s 174 | hostPath: 175 | path: /var/lib/kubernetes 176 | - name: var-lib-calico 177 | hostPath: 178 | path: /var/lib/calico 179 | --- 180 | 181 | # This manifest deploys the Calico Kubernetes controllers. 182 | # See https://github.com/projectcalico/kube-controllers 183 | apiVersion: apps/v1 184 | kind: Deployment 185 | metadata: 186 | name: calico-kube-controllers 187 | namespace: kube-system 188 | labels: 189 | k8s-app: calico-kube-controllers 190 | annotations: 191 | scheduler.alpha.kubernetes.io/critical-pod: '' 192 | scheduler.alpha.kubernetes.io/tolerations: | 193 | [{"key": "dedicated", "value": "master", "effect": "NoSchedule" }, 194 | {"key":"CriticalAddonsOnly", "operator":"Exists"}] 195 | spec: 196 | selector: 197 | matchLabels: 198 | k8s-app: calico-kube-controllers 199 | # The controllers can only have a single active instance. 200 | replicas: 1 201 | strategy: 202 | type: Recreate 203 | template: 204 | metadata: 205 | name: calico-kube-controllers 206 | namespace: kube-system 207 | labels: 208 | k8s-app: calico-kube-controllers 209 | spec: 210 | # The controllers must run in the host network namespace so that 211 | # it isn't governed by policy that would prevent it from working. 212 | hostNetwork: true 213 | serviceAccountName: calico-kube-controllers 214 | containers: 215 | - name: calico-kube-controllers 216 | image: quay.io/calico/kube-controllers:release-v3.9 217 | env: 218 | - name: ETCD_ENDPOINTS 219 | value: "https://{{ etcdEndpoint }}:2379" 220 | # Location of the CA certificate for etcd. 221 | - name: ETCD_CA_CERT_FILE 222 | value: "/var/lib/kubernetes/ca.pem" 223 | # Location of the client key for etcd. 224 | - name: ETCD_KEY_FILE 225 | value: "/var/lib/kubernetes/kubernetes-key.pem" 226 | # Location of the client certificate for etcd. 227 | - name: ETCD_CERT_FILE 228 | value: "/var/lib/kubernetes/kubernetes.pem" 229 | # Auto-detect the BGP IP address. 230 | - name: ENABLED_CONTROLLERS 231 | value: policy,profile,workloadendpoint,node 232 | - name: KUBERNETES_SERVICE_HOST 233 | value: "{{ etcdEndpoint }}" 234 | - name: KUBERNETES_SERVICE_PORT_HTTPS 235 | value: "6443" 236 | - name: KUBERNETES_SERVICE_PORT 237 | value: "6443" 238 | volumeMounts: 239 | - mountPath: /var/lib/kubernetes 240 | name: var-lib-k8s 241 | readOnly: true 242 | - mountPath: /etc/cni/net.d 243 | name: cni-net-dir 244 | readOnly: true 245 | 246 | volumes: 247 | - name: var-lib-k8s 248 | hostPath: 249 | path: /var/lib/kubernetes 250 | - name: cni-net-dir 251 | hostPath: 252 | path: /etc/cni/net.d 253 | --- 254 | 255 | apiVersion: v1 256 | kind: ServiceAccount 257 | metadata: 258 | name: calico-kube-controllers 259 | namespace: kube-system 260 | 261 | --- 262 | 263 | apiVersion: v1 264 | kind: ServiceAccount 265 | metadata: 266 | name: calico-node 267 | namespace: kube-system 268 | 269 | --- 270 | 271 | # Calico Version master 272 | # https://docs.projectcalico.org/master/releases#master 273 | 274 | --- 275 | 276 | kind: ClusterRole 277 | apiVersion: rbac.authorization.k8s.io/v1beta1 278 | metadata: 279 | name: calico-kube-controllers 280 | rules: 281 | - apiGroups: 282 | - "*" 283 | - extensions 284 | resources: 285 | - pods 286 | - namespaces 287 | - networkpolicies 288 | - networkpolicies.networking.k8s.io 289 | - nodes 290 | verbs: 291 | - watch 292 | - list 293 | --- 294 | kind: ClusterRoleBinding 295 | apiVersion: rbac.authorization.k8s.io/v1beta1 296 | metadata: 297 | name: calico-kube-controllers 298 | roleRef: 299 | apiGroup: rbac.authorization.k8s.io 300 | kind: ClusterRole 301 | name: calico-kube-controllers 302 | subjects: 303 | - kind: ServiceAccount 304 | name: calico-kube-controllers 305 | namespace: kube-system 306 | - kind: User 307 | name: "system:serviceaccount:kube-system:calico-kube-controllers" 308 | --- 309 | kind: ClusterRole 310 | apiVersion: rbac.authorization.k8s.io/v1beta1 311 | metadata: 312 | name: calico-node 313 | rules: 314 | - apiGroups: [""] 315 | resources: 316 | - pods 317 | - nodes 318 | verbs: 319 | - get 320 | --- 321 | apiVersion: rbac.authorization.k8s.io/v1beta1 322 | kind: ClusterRoleBinding 323 | metadata: 324 | name: calico-node 325 | roleRef: 326 | apiGroup: rbac.authorization.k8s.io 327 | kind: ClusterRole 328 | name: calico-node 329 | subjects: 330 | - kind: ServiceAccount 331 | name: calico-node 332 | namespace: kube-system 333 | -------------------------------------------------------------------------------- /k8s-worker/cni/calico/calicoctl.cfg: -------------------------------------------------------------------------------- 1 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 2 | {% if masterCount == 1 %} 3 | {%- set k8sMaster = pillar['kubernetes']['master']['ipaddr'] -%} 4 | {% elif masterCount == 3 %} 5 | {%- set k8sMaster = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 6 | {% endif %} 7 | 8 | apiVersion: projectcalico.org/v3 9 | kind: CalicoAPIConfig 10 | metadata: 11 | spec: 12 | datastoreType: "etcdv3" 13 | etcdEndpoints: "https://{{ k8sMaster }}:2379" 14 | etcdKeyFile: /var/lib/kubernetes/kubernetes-key.pem 15 | etcdCertFile: /var/lib/kubernetes/kubernetes.pem 16 | etcdCACertFile: /var/lib/kubernetes/ca.pem 17 | -------------------------------------------------------------------------------- /k8s-worker/cni/calico/init.sls: -------------------------------------------------------------------------------- 1 | {%- set calicoCniVersion = pillar['kubernetes']['worker']['networking']['calico']['cni-version'] -%} 2 | {%- set calicoctlVersion = pillar['kubernetes']['worker']['networking']['calico']['calicoctl-version'] -%} 3 | 4 | # set k8s-worker.cni if k8s-worker is at the same level of top.sls 5 | # set .k8s-worker.cni if k8s-worker is in a sub folder 6 | {% set require_cni = "cni-latest-archive" %} 7 | 8 | /usr/bin/calicoctl: 9 | file.managed: 10 | - source: https://github.com/projectcalico/calicoctl/releases/download/{{ calicoctlVersion }}/calicoctl 11 | - skip_verify: true 12 | - group: root 13 | - mode: 755 14 | 15 | /etc/calico/: 16 | file.directory: 17 | - user: root 18 | - group: root 19 | - dir_mode: 750 20 | 21 | /etc/calico/kube/: 22 | file.directory: 23 | - user: root 24 | - group: root 25 | - dir_mode: 750 26 | 27 | /opt/cni/bin/calico: 28 | file.managed: 29 | - source: 30 | {%- if "v3.1" in calicoCniVersion or calicoCniVersion in ["v3.2.1","v3.2.2"] %} 31 | - https://github.com/projectcalico/cni-plugin/releases/download/{{ calicoCniVersion }}/calico 32 | {% else %} 33 | - https://github.com/projectcalico/cni-plugin/releases/download/{{ calicoCniVersion }}/calico-amd64 34 | {%- endif %} 35 | - skip_verify: true 36 | - group: root 37 | - mode: 755 38 | - require: 39 | - id: {{ require_cni }} 40 | 41 | /opt/cni/bin/calico-ipam: 42 | file.managed: 43 | - source: 44 | {%- if "v3.1" in calicoCniVersion or calicoCniVersion in ["v3.2.1","v3.2.2"] %} 45 | - https://github.com/projectcalico/cni-plugin/releases/download/{{ calicoCniVersion }}/calico-ipam 46 | {% else %} 47 | - https://github.com/projectcalico/cni-plugin/releases/download/{{ calicoCniVersion }}/calico-ipam-amd64 48 | {%- endif %} 49 | - skip_verify: true 50 | - group: root 51 | - mode: 755 52 | - require: 53 | - id: {{ require_cni }} 54 | 55 | /etc/calico/kube/kubeconfig: 56 | file.managed: 57 | - source: salt://{{ slspath }}/kubeconfig 58 | - user: root 59 | - template: jinja 60 | - group: root 61 | - mode: 640 62 | - require: 63 | - id: {{ require_cni }} 64 | 65 | /etc/calico/calicoctl.cfg: 66 | file.managed: 67 | - source: salt://{{ slspath }}/calicoctl.cfg 68 | - user: root 69 | - template: jinja 70 | - group: root 71 | - mode: 640 72 | - require: 73 | - id: {{ require_cni }} 74 | 75 | /etc/cni/net.d/10-calico.conf: 76 | file.managed: 77 | - source: salt://{{ slspath }}/10-calico.conf 78 | - user: root 79 | - template: jinja 80 | - group: root 81 | - mode: 644 82 | - require: 83 | - id: {{ require_cni }} 84 | -------------------------------------------------------------------------------- /k8s-worker/cni/calico/kubeconfig: -------------------------------------------------------------------------------- 1 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 2 | {% if masterCount == 1 %} 3 | {%- set k8sMaster = pillar['kubernetes']['master']['ipaddr'] -%} 4 | {% elif masterCount == 3 %} 5 | {%- set k8sMaster = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 6 | {% endif %} 7 | {%- set calicoToken = pillar['kubernetes']['worker']['networking']['calico']['token'] -%} 8 | # Kubeconfig file for Calico CNI plugin. 9 | apiVersion: v1 10 | kind: Config 11 | clusters: 12 | - cluster: 13 | server: https://{{ k8sMaster }}:6443 14 | insecure-skip-tls-verify: true 15 | name: kubernetes 16 | users: 17 | - name: calico 18 | user: 19 | token: {{ calicoToken }} 20 | contexts: 21 | - name: calico-context 22 | context: 23 | cluster: kubernetes 24 | user: calico 25 | current-context: calico-context 26 | -------------------------------------------------------------------------------- /k8s-worker/cni/flannel/init.sls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valentin2105/Kubernetes-Saltstack/668e9d1c9e7af61cc90a722d06e75c3d695052df/k8s-worker/cni/flannel/init.sls -------------------------------------------------------------------------------- /k8s-worker/cni/init.sls: -------------------------------------------------------------------------------- 1 | {%- set cniVersion = pillar['kubernetes']['worker']['networking']['cni-version'] -%} 2 | {%- set cniProvider = pillar['kubernetes']['worker']['networking']['provider'] -%} 3 | 4 | /etc/cni: 5 | file.directory: 6 | - user: root 7 | - group: root 8 | - dir_mode: 750 9 | 10 | /etc/cni/net.d: 11 | file.directory: 12 | - user: root 13 | - group: root 14 | - dir_mode: 750 15 | 16 | cni-latest-archive: 17 | archive.extracted: 18 | - name: /opt/cni/bin 19 | - source: 20 | {%- if "v0.7" in cniVersion %} 21 | - https://github.com/containernetworking/plugins/releases/download/{{ cniVersion }}/cni-plugins-amd64-{{ cniVersion }}.tgz 22 | {% else %} 23 | - https://github.com/containernetworking/plugins/releases/download/{{ cniVersion }}/cni-plugins-linux-amd64-{{ cniVersion }}.tgz 24 | {%- endif %} 25 | - skip_verify: true 26 | - archive_format: tar 27 | - if_missing: /opt/cni/bin/loopback 28 | 29 | include: 30 | - .{{ cniProvider }} 31 | -------------------------------------------------------------------------------- /k8s-worker/cri/containerd/init.sls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valentin2105/Kubernetes-Saltstack/668e9d1c9e7af61cc90a722d06e75c3d695052df/k8s-worker/cri/containerd/init.sls -------------------------------------------------------------------------------- /k8s-worker/cri/docker/docker.service: -------------------------------------------------------------------------------- 1 | {%- set datadir = salt['pillar.get']('kubernetes:worker:runtime:docker:data-dir') -%} 2 | ### THIS FILE IS MANAGED BY SALTSTACK 3 | [Unit] 4 | 5 | Description=Docker Application Container Engine 6 | Documentation=http://docs.docker.io 7 | 8 | [Service] 9 | LimitNOFILE=1048576 10 | LimitNPROC=1048576 11 | ExecStart=/usr/bin/dockerd \ 12 | --iptables=false \ 13 | --ip-masq=false \ 14 | --host=unix:///var/run/docker.sock \ 15 | --log-level=error \ 16 | --data-root={{ datadir }} \ 17 | --storage-driver=overlay2 18 | Restart=on-failure 19 | RestartSec=5 20 | 21 | [Install] 22 | WantedBy=multi-user.target 23 | -------------------------------------------------------------------------------- /k8s-worker/cri/docker/init.sls: -------------------------------------------------------------------------------- 1 | {%- set dockerVersion = pillar['kubernetes']['worker']['runtime']['docker']['version'] -%} 2 | {%- set dockerdata = pillar['kubernetes']['worker']['runtime']['docker']['data-dir'] -%} 3 | 4 | {{ dockerdata }}: 5 | file.directory: 6 | - user: root 7 | - group: root 8 | - mode: '711' 9 | 10 | docker-latest-archive: 11 | archive.extracted: 12 | - name: /opt/ 13 | - source: https://download.docker.com/linux/static/stable/x86_64/docker-{{ dockerVersion }}.tgz 14 | - skip_verify: true 15 | - archive_format: tar 16 | - if_missing: /opt/docker/ 17 | 18 | /usr/bin/docker-containerd: 19 | file.symlink: 20 | - target: /opt/docker/docker-containerd 21 | 22 | /usr/bin/containerd: 23 | file.symlink: 24 | - target: /opt/docker/containerd 25 | 26 | 27 | /usr/bin/runc: 28 | file.symlink: 29 | - target: /opt/docker/runc 30 | 31 | /usr/bin/docker-containerd-ctr: 32 | file.symlink: 33 | - target: /opt/docker/docker-containerd-ctr 34 | 35 | /usr/bin/docker-containerd-shim: 36 | file.symlink: 37 | - target: /opt/docker/docker-containerd-shim 38 | 39 | /usr/bin/containerd-shim: 40 | file.symlink: 41 | - target: /opt/docker/containerd-shim 42 | 43 | /usr/bin/dockerd: 44 | file.symlink: 45 | - target: /opt/docker/dockerd 46 | 47 | /usr/bin/docker: 48 | file.symlink: 49 | - target: /opt/docker/docker 50 | 51 | /usr/bin/docker-proxy: 52 | file.symlink: 53 | - target: /opt/docker/docker-proxy 54 | 55 | /usr/bin/docker-runc: 56 | file.symlink: 57 | - target: /opt/docker/docker-runc 58 | 59 | /etc/systemd/system/docker.service: 60 | file.managed: 61 | - source: salt://{{ slspath }}/docker.service 62 | - user: root 63 | - template: jinja 64 | - group: root 65 | - mode: 644 66 | 67 | docker: 68 | service.running: 69 | - enable: True 70 | - watch: 71 | - /etc/systemd/system/docker.service 72 | -------------------------------------------------------------------------------- /k8s-worker/init.sls: -------------------------------------------------------------------------------- 1 | {%- set k8sVersion = pillar['kubernetes']['version'] -%} 2 | {%- set os = salt['grains.get']('os') -%} 3 | {%- set enableIPv6 = pillar['kubernetes']['worker']['networking']['calico']['ipv6']['enable'] -%} 4 | {%- set criProvider = pillar['kubernetes']['worker']['runtime']['provider'] -%} 5 | 6 | include: 7 | - .cri/{{ criProvider }} 8 | - .cni 9 | {% if os == "Debian" or os == "Ubuntu" %} 10 | glusterfs-client: 11 | pkg.latest 12 | 13 | conntrack: 14 | pkg.latest 15 | 16 | nfs-common: 17 | pkg.latest 18 | {% endif %} 19 | 20 | socat: 21 | pkg.latest 22 | 23 | vm.max_map_count: 24 | sysctl.present: 25 | - value: 2097152 26 | 27 | /usr/bin/kubelet: 28 | file.managed: 29 | - source: https://storage.googleapis.com/kubernetes-release/release/{{ k8sVersion }}/bin/linux/amd64/kubelet 30 | - skip_verify: true 31 | - group: root 32 | - mode: 755 33 | 34 | /usr/bin/kube-proxy: 35 | file.managed: 36 | - source: https://storage.googleapis.com/kubernetes-release/release/{{ k8sVersion }}/bin/linux/amd64/kube-proxy 37 | - skip_verify: true 38 | - group: root 39 | - mode: 755 40 | 41 | /var/lib/kubelet: 42 | file.directory: 43 | - user: root 44 | - group: root 45 | - dir_mode: 700 46 | 47 | /var/lib/kubelet/kubeconfig: 48 | file.managed: 49 | - source: salt://{{ slspath }}/kubeconfig 50 | - user: root 51 | - template: jinja 52 | - group: root 53 | - mode: 644 54 | 55 | /etc/systemd/system/kubelet.service: 56 | file.managed: 57 | - source: salt://{{ slspath }}/kubelet.service 58 | - user: root 59 | - template: jinja 60 | - group: root 61 | - mode: 644 62 | 63 | /etc/systemd/system/kube-proxy.service: 64 | file.managed: 65 | - source: salt://{{ slspath }}/kube-proxy.service 66 | - user: root 67 | - template: jinja 68 | - group: root 69 | - mode: 644 70 | 71 | kubelet: 72 | service.running: 73 | - enable: True 74 | - watch: 75 | - /etc/systemd/system/kubelet.service 76 | - /var/lib/kubernetes/kubernetes.pem 77 | - /var/lib/kubernetes/ca.pem 78 | - /usr/bin/kubelet 79 | 80 | kube-proxy: 81 | service.running: 82 | - enable: True 83 | - watch: 84 | - /etc/systemd/system/kube-proxy.service 85 | - /var/lib/kubernetes/kubernetes.pem 86 | - /var/lib/kubernetes/ca.pem 87 | - /usr/bin/kube-proxy 88 | 89 | {% if enableIPv6 == true %} 90 | net.ipv6.conf.all.forwarding: 91 | sysctl.present: 92 | - value: 1 93 | {% endif %} 94 | -------------------------------------------------------------------------------- /k8s-worker/kube-proxy.service: -------------------------------------------------------------------------------- 1 | ### THIS FILE IS MANAGED BY SALTSTACK 2 | [Unit] 3 | Description=Kubernetes Kube Proxy 4 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 5 | 6 | [Service] 7 | ExecStart=/usr/bin/kube-proxy \ 8 | --kubeconfig=/var/lib/kubelet/kubeconfig \ 9 | --proxy-mode=iptables \ 10 | --iptables-min-sync-period=2s \ 11 | --iptables-sync-period=5s \ 12 | --v=2 13 | 14 | Restart=on-failure 15 | RestartSec=5 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /k8s-worker/kubeconfig: -------------------------------------------------------------------------------- 1 | {%- set masterCount = pillar['kubernetes']['master']['count'] -%} 2 | {% if masterCount == 1 %} 3 | {%- set Endpoint = pillar['kubernetes']['master']['ipaddr'] -%} 4 | {% elif masterCount == 3 %} 5 | {%- set Endpoint = pillar['kubernetes']['master']['cluster']['node01']['ipaddr'] -%} 6 | {% endif %} 7 | {%- set Token = pillar['kubernetes']['global']['kubelet-token'] -%} 8 | apiVersion: v1 9 | kind: Config 10 | clusters: 11 | - cluster: 12 | certificate-authority: /var/lib/kubernetes/ca.pem 13 | server: https://{{ Endpoint }}:6443 14 | name: kubernetes 15 | contexts: 16 | - context: 17 | cluster: kubernetes 18 | user: kubelet 19 | name: kubelet 20 | current-context: kubelet 21 | users: 22 | - name: kubelet 23 | user: 24 | token: {{ Token }} 25 | -------------------------------------------------------------------------------- /k8s-worker/kubelet.service: -------------------------------------------------------------------------------- 1 | {%- set clusterDomain = pillar['kubernetes']['domain'] -%} 2 | {%- set hostname = salt['grains.get']('fqdn') -%} 3 | ### THIS FILE IS MANAGED BY SALTSTACK 4 | [Unit] 5 | Description=Kubernetes Kubelet 6 | Documentation=https://github.com/GoogleCloudPlatform/kubernetes 7 | After=docker.service 8 | Requires=docker.service 9 | 10 | [Service] 11 | ExecStart=/usr/bin/kubelet \ 12 | --cluster-dns=10.32.0.10 \ 13 | --cluster-domain={{ clusterDomain }} \ 14 | --hostname-override={{ hostname }} \ 15 | --container-runtime=docker \ 16 | --docker=unix:///var/run/docker.sock \ 17 | --network-plugin=cni \ 18 | --kubeconfig=/var/lib/kubelet/kubeconfig \ 19 | --runtime-cgroups=/systemd/system.slice \ 20 | --kubelet-cgroups=/systemd/system.slice \ 21 | --serialize-image-pulls=false \ 22 | --register-node=true \ 23 | --tls-cert-file=/var/lib/kubernetes/kubernetes.pem \ 24 | --tls-private-key-file=/var/lib/kubernetes/kubernetes-key.pem \ 25 | --eviction-pressure-transition-period 30s \ 26 | --cert-dir=/var/lib/kubelet \ 27 | --v=2 28 | 29 | Restart=on-failure 30 | RestartSec=5 31 | 32 | [Install] 33 | WantedBy=multi-user.target 34 | -------------------------------------------------------------------------------- /k8s-worker/wireguard/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/valentin2105/Kubernetes-Saltstack/668e9d1c9e7af61cc90a722d06e75c3d695052df/k8s-worker/wireguard/.placeholder -------------------------------------------------------------------------------- /pillar/cluster_config.sls: -------------------------------------------------------------------------------- 1 | kubernetes: 2 | version: v1.16.1 3 | domain: cluster.local 4 | 5 | master: 6 | count: 1 7 | hostname: master.domain.tld 8 | ipaddr: 10.240.0.10 9 | 10 | # count: 3 11 | # cluster: 12 | # node01: 13 | # hostname: master01.domain.tld 14 | # ipaddr: 10.240.0.10 15 | # node02: 16 | # hostname: master02.domain.tld 17 | # ipaddr: 10.240.0.20 18 | # node03: 19 | # hostname: master03.domain.tld 20 | # ipaddr: 10.240.0.30 21 | 22 | etcd: 23 | version: v3.3.12 24 | encryption-key: '0Wh+uekJUj3SzaKt+BcHUEJX/9Vo2PLGiCoIsND9GyY=' 25 | 26 | pki: 27 | enable: false 28 | host: master01.domain.tld 29 | wildcard: '*.domain.tld' 30 | 31 | worker: 32 | runtime: 33 | provider: docker 34 | docker: 35 | version: 18.09.9 36 | data-dir: /dockerFS 37 | networking: 38 | cni-version: v0.7.1 39 | provider: calico 40 | calico: 41 | version: v3.9.0 42 | cni-version: v3.9.0 43 | calicoctl-version: v3.9.0 44 | controller-version: 3.9-release 45 | as-number: 64512 46 | token: hu0daeHais3a--CHANGEME--hu0daeHais3a 47 | ipv4: 48 | range: 192.168.0.0/16 49 | nat: true 50 | ip-in-ip: true 51 | ipv6: 52 | enable: false 53 | nat: true 54 | interface: eth0 55 | range: fd80:24e2:f998:72d6::/64 56 | 57 | global: 58 | clusterIP-range: 10.32.0.0/16 59 | helm-version: v2.14.3 60 | dashboard-version: v2.0.0-beta4 61 | coredns-version: 1.6.4 62 | admin-token: Haim8kay1rar--CHANGEME--Haim8kay11ra 63 | kubelet-token: ahT1eipae1wi--CHANGEME--ahT1eipa1e1w 64 | metallb: 65 | enable: false 66 | version: v0.8.1 67 | protocol: layer2 68 | addresses: 10.100.0.0/24 69 | nginx-ingress: 70 | enable: false 71 | version: 0.26.1 72 | service-type: LoadBalancer 73 | cert-manager: 74 | enable: false 75 | version: v0.11.0 -------------------------------------------------------------------------------- /pillar/top.sls: -------------------------------------------------------------------------------- 1 | base: 2 | '*': 3 | {% if "k8s-master" in grains.get('role', []) or "k8s-worker" in grains.get('role', []) %} 4 | - cluster_config 5 | {% endif %} 6 | -------------------------------------------------------------------------------- /post_install/coredns.yaml: -------------------------------------------------------------------------------- 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 | health 52 | kubernetes {{ salt['pillar.get']('kubernetes:domain') }} {{ salt['pillar.get']('kubernetes:domain') }} { 53 | pods insecure 54 | upstream 55 | fallthrough in-addr.arpa ip6.arpa 56 | } 57 | forward . /etc/resolv.conf 58 | prometheus :9153 59 | cache 30 60 | reload 61 | loadbalance 62 | } 63 | --- 64 | apiVersion: apps/v1 65 | kind: Deployment 66 | metadata: 67 | name: coredns 68 | namespace: kube-system 69 | labels: 70 | k8s-app: kube-dns 71 | kubernetes.io/name: "CoreDNS" 72 | spec: 73 | replicas: 2 74 | strategy: 75 | type: RollingUpdate 76 | rollingUpdate: 77 | maxUnavailable: 1 78 | selector: 79 | matchLabels: 80 | k8s-app: kube-dns 81 | template: 82 | metadata: 83 | labels: 84 | k8s-app: kube-dns 85 | spec: 86 | serviceAccountName: coredns 87 | tolerations: 88 | - key: "CriticalAddonsOnly" 89 | operator: "Exists" 90 | #priorityClassName: high-priority 91 | containers: 92 | - name: coredns 93 | image: coredns/coredns:{{ salt['pillar.get']('kubernetes:global:coredns-version') }} 94 | env: 95 | imagePullPolicy: IfNotPresent 96 | args: [ "-conf", "/etc/coredns/Corefile" ] 97 | volumeMounts: 98 | - name: config-volume 99 | mountPath: /etc/coredns 100 | readOnly: true 101 | ports: 102 | - containerPort: 53 103 | name: dns 104 | protocol: UDP 105 | - containerPort: 53 106 | name: dns-tcp 107 | protocol: TCP 108 | - containerPort: 9153 109 | name: metrics 110 | protocol: TCP 111 | securityContext: 112 | allowPrivilegeEscalation: false 113 | capabilities: 114 | add: 115 | - NET_BIND_SERVICE 116 | drop: 117 | - all 118 | readOnlyRootFilesystem: true 119 | livenessProbe: 120 | httpGet: 121 | path: /health 122 | port: 8080 123 | scheme: HTTP 124 | initialDelaySeconds: 60 125 | timeoutSeconds: 5 126 | successThreshold: 1 127 | failureThreshold: 5 128 | dnsPolicy: Default 129 | volumes: 130 | - name: config-volume 131 | configMap: 132 | name: coredns 133 | items: 134 | - key: Corefile 135 | path: Corefile 136 | --- 137 | apiVersion: v1 138 | kind: Service 139 | metadata: 140 | name: kube-dns 141 | namespace: kube-system 142 | annotations: 143 | prometheus.io/port: "9153" 144 | prometheus.io/scrape: "true" 145 | labels: 146 | k8s-app: kube-dns 147 | kubernetes.io/cluster-service: "true" 148 | kubernetes.io/name: "CoreDNS" 149 | spec: 150 | selector: 151 | k8s-app: kube-dns 152 | clusterIP: 10.32.0.10 153 | ports: 154 | - name: dns 155 | port: 53 156 | protocol: UDP 157 | - name: dns-tcp 158 | port: 53 159 | protocol: TCP 160 | -------------------------------------------------------------------------------- /post_install/grafana.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 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: gcr.io/google_containers/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 | # The following env variables are required to make Grafana accessible via 32 | # the kubernetes api-server proxy. On production clusters, we recommend 33 | # removing these env variables, setup auth for grafana, and expose the grafana 34 | # service using a LoadBalancer or a public IP. 35 | - name: GF_AUTH_BASIC_ENABLED 36 | value: "false" 37 | - name: GF_AUTH_ANONYMOUS_ENABLED 38 | value: "true" 39 | - name: GF_AUTH_ANONYMOUS_ORG_ROLE 40 | value: Admin 41 | - name: GF_SERVER_ROOT_URL 42 | # If you're only using the API Server proxy, set this value instead: 43 | # value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy 44 | value: / 45 | volumes: 46 | - name: ca-certificates 47 | hostPath: 48 | path: /etc/ssl/certs 49 | - name: grafana-storage 50 | emptyDir: {} 51 | --- 52 | apiVersion: v1 53 | kind: Service 54 | metadata: 55 | labels: 56 | # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) 57 | # If you are NOT using this as an addon, you should comment out this line. 58 | kubernetes.io/cluster-service: 'true' 59 | kubernetes.io/name: monitoring-grafana 60 | name: monitoring-grafana 61 | namespace: kube-system 62 | spec: 63 | # In a production setup, we recommend accessing Grafana through an external Loadbalancer 64 | # or through a public IP. 65 | # type: LoadBalancer 66 | # You could also use NodePort to expose the service at a randomly-generated port 67 | # type: NodePort 68 | ports: 69 | - port: 80 70 | targetPort: 3000 71 | selector: 72 | k8s-app: grafana 73 | -------------------------------------------------------------------------------- /post_install/heapster-rbac.yaml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /post_install/heapster.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: heapster 5 | namespace: kube-system 6 | --- 7 | apiVersion: apps/v1 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.4 24 | imagePullPolicy: IfNotPresent 25 | command: 26 | - /heapster 27 | - --source=kubernetes:https://kubernetes.default 28 | - --sink=influxdb:http://monitoring-influxdb:8086 29 | --- 30 | apiVersion: v1 31 | kind: Service 32 | metadata: 33 | labels: 34 | task: monitoring 35 | # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) 36 | # If you are NOT using this as an addon, you should comment out this line. 37 | kubernetes.io/cluster-service: 'true' 38 | kubernetes.io/name: Heapster 39 | name: heapster 40 | namespace: kube-system 41 | spec: 42 | ports: 43 | - port: 80 44 | targetPort: 8082 45 | selector: 46 | k8s-app: heapster 47 | -------------------------------------------------------------------------------- /post_install/influxdb.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 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: gcr.io/google_containers/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 | # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) 30 | # If you are NOT using this as an addon, you should comment out this line. 31 | kubernetes.io/cluster-service: 'true' 32 | kubernetes.io/name: monitoring-influxdb 33 | name: monitoring-influxdb 34 | namespace: kube-system 35 | spec: 36 | ports: 37 | - port: 8086 38 | targetPort: 8086 39 | selector: 40 | k8s-app: influxdb 41 | -------------------------------------------------------------------------------- /post_install/metallb-configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | namespace: metallb-system 5 | name: config 6 | data: 7 | config: | 8 | address-pools: 9 | - name: default 10 | protocol: layer2 11 | addresses: 12 | - {{ salt['pillar.get']('kubernetes:global:metallb:addresses') }} 13 | -------------------------------------------------------------------------------- /post_install/policy-controller.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Deployment 3 | apiVersion: apps/v1 4 | metadata: 5 | name: calico-policy 6 | namespace: kube-system 7 | labels: 8 | k8s-app: calico-policy 9 | spec: 10 | replicas: 1 11 | selector: 12 | matchLabels: 13 | k8s-app: calico-policy 14 | template: 15 | metadata: 16 | labels: 17 | k8s-app: calico-policy 18 | name: calico-policy 19 | version: latest 20 | spec: 21 | imagePullSecrets: 22 | - name: dntlpw 23 | hostNetwork: true 24 | restartPolicy: Always 25 | containers: 26 | - image: calico/kube-controllers:v2.0.0 27 | name: calico-policy 28 | env: 29 | - name: ETCD_ENDPOINTS 30 | value: "http://MASTER_HOSTNAME:2379" 31 | - name: K8S_API 32 | value: "https://kubernetes.default.svc.CLUSTER_DOMAIN:443" 33 | - name: CONFIGURE_ETC_HOSTS 34 | value: "false" 35 | -------------------------------------------------------------------------------- /post_install/rbac-calico.yaml: -------------------------------------------------------------------------------- 1 | kind: ClusterRole 2 | apiVersion: rbac.authorization.k8s.io/v1beta1 3 | metadata: 4 | name: calico-policy-controller 5 | namespace: kube-system 6 | rules: 7 | - apiGroups: 8 | - "" 9 | - extensions 10 | resources: 11 | - pods 12 | - namespaces 13 | - networkpolicies 14 | verbs: 15 | - watch 16 | - list 17 | --- 18 | apiVersion: rbac.authorization.k8s.io/v1beta1 19 | kind: ClusterRoleBinding 20 | metadata: 21 | name: calico-policy-controller 22 | roleRef: 23 | apiGroup: rbac.authorization.k8s.io 24 | kind: ClusterRole 25 | name: calico-policy-controller 26 | subjects: 27 | - kind: User 28 | name: "system:serviceaccount:kube-system:default" 29 | -------------------------------------------------------------------------------- /post_install/rbac-tiller.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: tiller 5 | namespace: kube-system 6 | --- 7 | apiVersion: rbac.authorization.k8s.io/v1beta1 8 | kind: ClusterRoleBinding 9 | metadata: 10 | name: tiller 11 | roleRef: 12 | apiGroup: rbac.authorization.k8s.io 13 | kind: ClusterRole 14 | name: cluster-admin 15 | subjects: 16 | - kind: ServiceAccount 17 | name: tiller 18 | namespace: kube-system 19 | -------------------------------------------------------------------------------- /post_install/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /opt/kubernetes/post_install 4 | 5 | {% set HELM_VERSION = salt['pillar.get']('kubernetes:global:helm-version') -%} 6 | {% set DASHBOARD_VERSION = salt['pillar.get']('kubernetes:global:dashboard-version') -%} 7 | 8 | {% set PROVIDER = salt['pillar.get']('kubernetes:worker:networking:provider') -%} 9 | {% if PROVIDER == "calico" -%} 10 | kubectl create -f rbac-calico.yaml 11 | kubectl create -f /opt/calico.yaml 12 | sleep 15 13 | {% endif %} 14 | 15 | # CoreDNS 16 | kubectl create -f coredns.yaml 17 | sleep 5 18 | 19 | # Kubernetes Dashboard 20 | kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/{{ DASHBOARD_VERSION }}/aio/deploy/recommended.yaml 21 | 22 | # Helm 23 | wget https://kubernetes-helm.storage.googleapis.com/helm-{{ HELM_VERSION }}-linux-amd64.tar.gz 24 | tar -zxvf helm-{{ HELM_VERSION }}-linux-amd64.tar.gz 25 | mv linux-amd64/helm /usr/local/bin/helm 26 | rm -r linux-amd64/ && rm -r helm-{{ HELM_VERSION }}-linux-amd64.tar.gz 27 | 28 | kubectl create -f rbac-tiller.yaml 29 | helm init --service-account tiller --output yaml | sed 's@apiVersion: extensions/v1beta1@apiVersion: apps/v1@' | sed 's@ replicas: 1@ replicas: 1\n selector: {"matchLabels": {"app": "helm", "name": "tiller"}}@' | kubectl apply -f - 30 | helm init --client-only 31 | sleep 20 32 | 33 | # MetalLB 34 | {% set METALLB_ENABLE = salt['pillar.get']('kubernetes:global:metallb:enable') -%} 35 | {% set METALLB_VERSION = salt['pillar.get']('kubernetes:global:metallb:version') -%} 36 | 37 | {% if METALLB_ENABLE == true -%} 38 | kubectl apply -f https://raw.githubusercontent.com/google/metallb/{{ METALLB_VERSION }}/manifests/metallb.yaml 39 | kubectl apply -f metallb-configmap.yaml 40 | {% endif %} 41 | 42 | # Nginx-Ingress 43 | {% set NGINX_ENABLE = salt['pillar.get']('kubernetes:global:nginx-ingress:enable') -%} 44 | {% set NGINX_VERSION = salt['pillar.get']('kubernetes:global:nginx-ingress:version') -%} 45 | {% set NGINX_SVC = salt['pillar.get']('kubernetes:global:nginx-ingress:service-type') -%} 46 | 47 | {% if NGINX_ENABLE == true -%} 48 | helm install \ 49 | --namespace nginx-ingress \ 50 | --name nginx-ingress \ 51 | --set controller.image.tag={{NGINX_VERSION}} \ 52 | --set controller.service.type={{NGINX_SVC}} stable/nginx-ingress 53 | {% endif %} 54 | 55 | #Cert-Manager (Helm) 56 | {% set CERT_MANAGER_ENABLE = salt['pillar.get']('kubernetes:global:cert-manager:enable') -%} 57 | {% set CERT_MANAGER_VERSION = salt['pillar.get']('kubernetes:global:cert-manager:version') -%} 58 | {% if CERT_MANAGER_ENABLE == true -%} 59 | kubectl apply --validate=false -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.11/deploy/manifests/00-crds.yaml 60 | kubectl create namespace cert-manager 61 | helm repo add jetstack https://charts.jetstack.io 62 | helm repo update 63 | helm install \ 64 | --name cert-manager \ 65 | --namespace cert-manager \ 66 | --version {{ CERT_MANAGER_VERSION }} \ 67 | jetstack/cert-manager 68 | {% endif %} 69 | 70 | 71 | sleep 2 72 | echo "" 73 | kubectl get pod,deploy,svc --all-namespaces 74 | echo "" 75 | kubectl get nodes 76 | echo "" 77 | echo "Kubernetes is now configured with Policy-Controller, Dashboard, Helm and CoreDNS..." 78 | echo "" 79 | -------------------------------------------------------------------------------- /top.sls: -------------------------------------------------------------------------------- 1 | base: 2 | '*': 3 | {% if "k8s-master" in grains.get('role', []) %} 4 | - k8s-certs 5 | - k8s-master 6 | {% endif %} 7 | {% if "k8s-worker" in grains.get('role', []) %} 8 | - k8s-certs 9 | - k8s-worker 10 | {% endif %} 11 | --------------------------------------------------------------------------------