├── .gitignore ├── LICENSE ├── README.md ├── attachments ├── 317345a8.jpg ├── 3946b715.jpg ├── 4e1384ce.jpg ├── 88d4150c.jpg ├── SCR20241127pdvk.png ├── SCR20241127pglz.png ├── SCR20241127phat.png ├── SCR20241127pnxl.png └── k8s_architecture.svg ├── scripts ├── CNI_Calico.sh ├── setup_k8s_control.sh └── setup_k8s_worker.sh └── tf_libvirt ├── Cloudinit.tf ├── Domain.tf ├── Output.tf ├── Provider.tf ├── README.md ├── Variables.tf ├── Volume.tf ├── destroy.sh ├── start.sh └── templates ├── netplan.yml └── user-data.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .terraform** 2 | terraform.** 3 | -------------------------------------------------------------------------------- /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 | # Creating a kubernetes cluster with kubeadm on Ubuntu 24.04 LTS 2 | 3 | > [Kubernetes](https://kubernetes.io/), also known as **k8s**, is an open-source system for automating deployment, scaling, and management of containerized applications. 4 | 5 | ***Notice*** The initial (old) blog post with ubuntu 22.04 is (still) here: [blog post](https://balaskas.gr/blog/2022/08/31/creating-a-kubernetes-cluster-with-kubeadm-on-ubuntu-2204-lts/) 6 | 7 | 8 | 9 | - [Prerequisites](#Prerequisites) 10 | * [Streamline the lab environment](#Streamline-the-lab-environment) 11 | - [Git Terraform Code for the kubernetes cluster](#Git-Terraform-Code-for-the-kubernetes-cluster) 12 | * [Initilaze the working directory](#Initilaze-the-working-directory) 13 | * [Ubuntu 24.04 Image](#Ubuntu-2404-Image) 14 | * [Spawn the VMs](#Spawn-the-VMs) 15 | - [Control-Plane Node](#Control-Plane-Node) 16 | * [Ports on the control-plane node](#Ports-on-the-control-plane-node) 17 | * [Firewall on the control-plane node](#Firewall-on-the-control-plane-node) 18 | * [Hosts file in the control-plane node](#Hosts-file-in-the-control-plane-node) 19 | + [Updating your hosts file](#Updating-your-hosts-file) 20 | * [No Swap on the control-plane node](#No-Swap-on-the-control-plane-node) 21 | * [Kernel modules on the control-plane node](#Kernel-modules-on-the-control-plane-node) 22 | * [NeedRestart on the control-plane node](#NeedRestart-on-the-control-plane-node) 23 | + [temporarily](#temporarily) 24 | + [permanently](#permanently) 25 | * [Installing a Container Runtime on the control-plane node](#Installing-a-Container-Runtime-on-the-control-plane-node) 26 | * [Installing kubeadm, kubelet and kubectl on the control-plane node](#Installing-kubeadm-kubelet-and-kubectl-on-the-control-plane-node) 27 | * [Get kubernetes admin configuration images](#Get-kubernetes-admin-configuration-images) 28 | * [Initializing the control-plane node](#Initializing-the-control-plane-node) 29 | * [Create user access config to the k8s control-plane node](#Create-user-access-config-to-the-k8s-control-plane-node) 30 | * [Verify the control-plane node](#Verify-the-control-plane-node) 31 | * [Install an overlay network provider on the control-plane node](#Install-an-overlay-network-provider-on-the-control-plane-node) 32 | * [Verify CoreDNS is running on the control-plane node](#Verify-CoreDNS-is-running-on-the-control-plane-node) 33 | - [Worker Nodes](#Worker-Nodes) 34 | * [Ports on the worker nodes](#Ports-on-the-worker-nodes) 35 | * [Firewall on the worker nodes](#Firewall-on-the-worker-nodes) 36 | * [Hosts file in the worker node](#Hosts-file-in-the-worker-node) 37 | * [No Swap on the worker node](#No-Swap-on-the-worker-node) 38 | * [Kernel modules on the worker node](#Kernel-modules-on-the-worker-node) 39 | * [NeedRestart on the worker node](#NeedRestart-on-the-worker-node) 40 | * [Installing a Container Runtime on the worker node](#Installing-a-Container-Runtime-on-the-worker-node) 41 | * [Installing kubeadm, kubelet and kubectl on the worker node](#Installing-kubeadm-kubelet-and-kubectl-on-the-worker-node) 42 | - [Get Token from the control-plane node](#Get-Token-from-the-control-plane-node) 43 | * [Get Certificate Hash from the control-plane node](#Get-Certificate-Hash-from-the-control-plane-node) 44 | * [Join Workers to the kubernetes cluster](#Join-Workers-to-the-kubernetes-cluster) 45 | - [Is the kubernetes cluster running ?](#Is-the-kubernetes-cluster-running-) 46 | * [All nodes have successfully joined the Kubernetes cluster](#All-nodes-have-successfully-joined-the-Kubernetes-cluster) 47 | * [All pods](#All-pods) 48 | - [Kubernetes Dashboard](#Kubernetes-Dashboard) 49 | * [Helm](#Helm) 50 | * [Install kubernetes dashboard](#Install-kubernetes-dashboard) 51 | * [Accessing Dashboard via a NodePort](#Accessing-Dashboard-via-a-NodePort) 52 | + [Patch kubernetes-dashboard](#Patch-kubernetes-dashboard) 53 | + [Edit kubernetes-dashboard Service](#Edit-kubernetes-dashboard-Service) 54 | * [Accessing Kubernetes Dashboard](#Accessing-Kubernetes-Dashboard) 55 | * [Create An Authentication Token (RBAC)](#Create-An-Authentication-Token-RBAC) 56 | + [Creating a Service Account](#Creating-a-Service-Account) 57 | + [Creating a ClusterRoleBinding](#Creating-a-ClusterRoleBinding) 58 | + [Getting a Bearer Token](#Getting-a-Bearer-Token) 59 | * [Browsing Kubernetes Dashboard](#Browsing-Kubernetes-Dashboard) 60 | - [Nginx App](#Nginx-App) 61 | * [Install nginx-app](#Install-nginx-app) 62 | * [Get Deployment](#Get-Deployment) 63 | * [Expose Nginx-App](#Expose-Nginx-App) 64 | * [Verify Service nginx-app](#Verify-Service-nginx-app) 65 | * [Describe Service nginx-app](#Describe-Service-nginx-app) 66 | * [Curl Nginx-App](#Curl-Nginx-App) 67 | * [Nginx-App from Browser](#Nginx-App-from-Browser) 68 | * [Change the default page](#Change-the-default-page) 69 | - [That's it](#Thats-it) 70 | * [destroy our lab](#destroy-our-lab) 71 | 72 | 73 | 74 | In this blog post, I’ll share my personal notes on setting up a kubernetes cluster using **kubeadm** on Ubuntu 24.04 LTS Virtual Machines. 75 | 76 | For this setup, I will use three (3) Virtual Machines in my local lab. My home lab is built on libvirt with QEMU/KVM (Kernel-based Virtual Machine), and I use Terraform as the infrastructure provisioning tool. 77 | 78 | ## Architecture Diagram 79 | 80 | ![k8s_architecture](attachments/k8s_architecture.svg) 81 | 82 | ## Prerequisites 83 | 84 | - at least 3 Virtual Machines of Ubuntu 24.04 (one for control-plane, two for worker nodes) 85 | - 2GB (or more) of RAM on each Virtual Machine 86 | - 2 CPUs (or more) on each Virtual Machine 87 | - 20Gb of hard disk on each Virtual Machine 88 | - No SWAP partition/image/file on each Virtual Machine 89 | 90 | ### Streamline the lab environment 91 | 92 | To simplify the Terraform code for the libvirt/QEMU Kubernetes lab, I’ve made a few adjustments so that all of the VMs use the below default values: 93 | 94 | - ssh port: 22/TCP 95 | - volume size: 40G 96 | - memory: 4096 97 | - cpu: 4 98 | 99 | Review the values and adjust them according to your requirements and limitations. 100 | 101 | ## Git Terraform Code for the kubernetes cluster 102 | 103 | I prefer maintaining a reproducible infrastructure so that I can quickly create and destroy my test lab. My approach involves testing each step, so I often destroy everything, copy and paste commands, and move forward. I use Terraform to provision the infrastructure. You can find the full Terraform code for the Kubernetes cluster here: [k8s cluster - Terraform code](https://github.com/ebal/k8s_cluster/tree/main/tf_libvirt). 104 | 105 | > If you do not use terraform, skip this step! 106 | 107 | You can `git clone` the repo to review and edit it according to your needs. 108 | 109 | ```bash 110 | git clone https://github.com/ebal/k8s_cluster.git 111 | cd tf_libvirt 112 | 113 | ``` 114 | 115 | You will **need** to make appropriate changes. Open **Variables.tf** for that. The most important option to change, is the **User** option. Change it to your github username and it will download and setup the VMs with your public key, instead of mine! 116 | 117 | But pretty much, everything else should work out of the box. Change the **vmem** and **vcpu** settings to your needs. 118 | 119 | ### Initilaze the working directory 120 | 121 | **Init** terraform before running the below shell script. 122 | This action will download in your local directory all the required teffarorm providers or modules. 123 | 124 | ```bash 125 | terraform init 126 | 127 | ``` 128 | 129 | ### Ubuntu 24.04 Image 130 | 131 | Before proceeding with creating the VMs, we need to ensure that the Ubuntu 24.04 image is available on our system, or modify the code to download it from the internet. 132 | 133 | In **Variables.tf** terraform file, you will notice the below entries 134 | 135 | ```yaml 136 | # The image source of the VM 137 | # cloud_image = "https://cloud-images.ubuntu.com/oracular/current/focal-server-cloudimg-amd64.img" 138 | cloud_image = "../oracular-server-cloudimg-amd64.img" 139 | 140 | ``` 141 | 142 | If you do not want to download the Ubuntu 24.04 cloud server image then make the below change 143 | 144 | ```yaml 145 | # The image source of the VM 146 | cloud_image = "https://cloud-images.ubuntu.com/oracular/current/focal-server-cloudimg-amd64.img" 147 | # cloud_image = "../oracular-server-cloudimg-amd64.img" 148 | 149 | ``` 150 | 151 | otherwise you need to download it, in the upper directory, to speed things up 152 | 153 | ```bash 154 | cd ../ 155 | IMAGE="oracular" # 24.04 156 | curl -sLO https://cloud-images.ubuntu.com/${IMAGE}/current/${IMAGE}-server-cloudimg-amd64.img 157 | cd - 158 | 159 | ls -l ../oracular-server-cloudimg-amd64.img 160 | 161 | ``` 162 | 163 | ### Spawn the VMs 164 | 165 | We are ready to spawn our 3 VMs by running `terraform plan` & `terraform apply` 166 | 167 | ```bash 168 | ./start.sh 169 | 170 | ``` 171 | 172 | output should be something like: 173 | 174 | ``` 175 | ... 176 | Apply complete! Resources: 16 added, 0 changed, 0 destroyed. 177 | 178 | Outputs: 179 | 180 | VMs = [ 181 | "192.168.122.223 k8scpnode1", 182 | "192.168.122.50 k8swrknode1", 183 | "192.168.122.10 k8swrknode2", 184 | ] 185 | 186 | ``` 187 | 188 | Verify that you have ssh access to the VMs 189 | 190 | eg. 191 | 192 | ```bash 193 | ssh ubuntu@192.168.122.223 194 | 195 | ``` 196 | 197 | Replace the IP with the one provided in the output. 198 | 199 | ***DISCLAIMER*** if something failed, destroy everything with `./destroy.sh` to remove any garbages before run `./start.sh` again!! 200 | 201 | ## Control-Plane Node 202 | 203 | Let’s now begin configuring the Kubernetes control-plane node. 204 | 205 | ### Ports on the control-plane node 206 | 207 | Kubernetes runs a few services that needs to be accessable from the worker nodes. 208 | 209 | | Protocol | Direction | Port Range | Purpose | Used By | 210 | |----------|-----------|------------|-------------------------|----------------------| 211 | | TCP | Inbound | 6443 | Kubernetes API server | All | 212 | | TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd | 213 | | TCP | Inbound | 10250 | Kubelet API | Self, Control plane | 214 | | TCP | Inbound | 10259 | kube-scheduler | Self | 215 | | TCP | Inbound | 10257 | kube-controller-manager | Self | 216 | 217 | Although etcd ports are included in control plane section, you can also host your 218 | own **etcd** cluster externally or on custom ports. 219 | 220 | ### Firewall on the control-plane node 221 | 222 | We need to open the necessary ports on the CP's (control-plane node) firewall. 223 | 224 | ```bash 225 | sudo ufw allow 6443/tcp 226 | sudo ufw allow 2379:2380/tcp 227 | sudo ufw allow 10250/tcp 228 | sudo ufw allow 10259/tcp 229 | sudo ufw allow 10257/tcp 230 | 231 | # sudo ufw disable 232 | sudo ufw status 233 | 234 | ``` 235 | 236 | the output should be 237 | 238 | ``` 239 | To Action From 240 | -- ------ ---- 241 | 22/tcp ALLOW Anywhere 242 | 6443/tcp ALLOW Anywhere 243 | 2379:2380/tcp ALLOW Anywhere 244 | 10250/tcp ALLOW Anywhere 245 | 10259/tcp ALLOW Anywhere 246 | 10257/tcp ALLOW Anywhere 247 | 22/tcp (v6) ALLOW Anywhere (v6) 248 | 6443/tcp (v6) ALLOW Anywhere (v6) 249 | 2379:2380/tcp (v6) ALLOW Anywhere (v6) 250 | 10250/tcp (v6) ALLOW Anywhere (v6) 251 | 10259/tcp (v6) ALLOW Anywhere (v6) 252 | 10257/tcp (v6) ALLOW Anywhere (v6) 253 | ``` 254 | 255 | ### Hosts file in the control-plane node 256 | 257 | We need to update the `/etc/hosts` with the internal IP and hostname. 258 | This will help when it is time to join the worker nodes. 259 | 260 | ```bash 261 | echo $(hostname -I) $(hostname) | sudo tee -a /etc/hosts 262 | 263 | ``` 264 | 265 | Just a reminder: we need to update the hosts file to all the VMs. 266 | To include all the VMs' IPs and hostnames. 267 | 268 | If you already know them, then your `/etc/hosts` file should look like this: 269 | 270 | ``` 271 | 192.168.122.223 k8scpnode1 272 | 192.168.122.50 k8swrknode1 273 | 192.168.122.10 k8swrknode2 274 | ``` 275 | 276 | replace the IPs to yours. 277 | 278 | #### Updating your hosts file 279 | 280 | if you already the IPs of your VMs, run the below script to ALL 3 VMs 281 | 282 | ```bash 283 | sudo tee -a /etc/hosts < It is best to use cgroup v2, use the systemd cgroup driver instead of cgroupfs. 395 | 396 | Starting with v1.22 and later, when creating a cluster with kubeadm, if the user does not set the cgroupDriver field under KubeletConfiguration, kubeadm defaults it to systemd. 397 | 398 | ### Installing kubeadm, kubelet and kubectl on the control-plane node 399 | 400 | Install the kubernetes packages (kubedam, kubelet and kubectl) by first adding the k8s repository on our virtual machine. To speed up the next step, we will also download the configuration container images. 401 | 402 | This guide is using kubeadm, so we need to check the latest version. 403 | 404 | Kubernetes v1.31 is the latest version when this guide was written. 405 | 406 | ```bash 407 | VERSION="1.31" 408 | 409 | curl -fsSL https://pkgs.k8s.io/core:/stable:/v${VERSION}/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg 410 | 411 | # allow unprivileged APT programs to read this keyring 412 | sudo chmod 0644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg 413 | 414 | # This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list 415 | echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v${VERSION}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list 416 | 417 | # helps tools such as command-not-found to work correctly 418 | sudo chmod 0644 /etc/apt/sources.list.d/kubernetes.list 419 | 420 | sleep 2 421 | 422 | sudo apt-get update 423 | sudo apt-get install -y kubelet kubeadm kubectl 424 | 425 | ``` 426 | 427 | ### Get kubernetes admin configuration images 428 | 429 | Retrieve the Kubernetes admin configuration images. 430 | 431 | ```bash 432 | sudo kubeadm config images pull 433 | 434 | ``` 435 | 436 | ### Initializing the control-plane node 437 | 438 | We can now proceed with initializing the control-plane node for our Kubernetes cluster. 439 | 440 | There are a few things we need to be careful about: 441 | 442 | - We can specify the control-plane-endpoint if we are planning to have a high available k8s cluster. (we will skip this for now), 443 | - Choose a Pod network add-on (next section) but be aware that CoreDNS (DNS and Service Discovery) will not run till then (later), 444 | - define where is our container runtime socket (we will skip it) 445 | - advertise the API server (we will skip it) 446 | 447 | But we will define our Pod Network CIDR to the default value of the Pod network add-on so everything will go smoothly later on. 448 | 449 | ```bash 450 | sudo kubeadm init --pod-network-cidr=10.244.0.0/16 451 | 452 | ``` 453 | 454 | Keep the output in a notepad. 455 | 456 | ### Create user access config to the k8s control-plane node 457 | 458 | Our k8s control-plane node is running, so we need to have credentials to access it. 459 | 460 | The **kubectl** reads a configuration file (that has the token), so we copying this from k8s admin. 461 | 462 | ```bash 463 | rm -rf $HOME/.kube 464 | mkdir -p $HOME/.kube 465 | 466 | sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config 467 | 468 | sudo chown $(id -u):$(id -g) $HOME/.kube/config 469 | 470 | ls -la $HOME/.kube/config 471 | 472 | echo 'alias k="kubectl"' | sudo tee -a /etc/bash.bashrc 473 | source /etc/bash.bashrc 474 | 475 | ``` 476 | 477 | ### Verify the control-plane node 478 | 479 | Verify that the kubernets is running. 480 | 481 | That means we have a k8s cluster - but only the control-plane node is running. 482 | 483 | ```bash 484 | kubectl cluster-info 485 | # kubectl cluster-info dump 486 | 487 | kubectl get nodes -o wide 488 | kubectl get pods -A -o wide 489 | 490 | ``` 491 | 492 | ### Install an overlay network provider on the control-plane node 493 | 494 | As I mentioned above, in order to use the DNS and Service Discovery services in the kubernetes (CoreDNS) we need to install a Container Network Interface (CNI) based Pod network add-on so that your Pods can communicate with each other. 495 | 496 | Kubernetes **[Flannel](https://github.com/flannel-io/flannel)** is a popular network overlay solution for Kubernetes clusters, primarily used to enable networking between pods across different nodes. It's a simple and easy-to-implement network fabric that uses the VXLAN protocol to create a flat virtual network, allowing Kubernetes pods to communicate with each other across different hosts. 497 | 498 | Make sure to open the below udp ports for flannel’s VXLAN traffic (if you are going to use it): 499 | 500 | ```bash 501 | sudo ufw allow 8472/udp 502 | 503 | ``` 504 | 505 | To install Flannel as the networking solution for your Kubernetes (K8s) cluster, run the following command to deploy Flannel: 506 | 507 | ```bash 508 | k apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml 509 | 510 | ``` 511 | 512 | ### Verify CoreDNS is running on the control-plane node 513 | 514 | Verify that the control-plane node is Up & Running and the control-plane pods (as coredns pods) are also running 515 | 516 | ```bash 517 | k get nodes -o wide 518 | 519 | ``` 520 | 521 | ```bash 522 | NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME 523 | k8scpnode1 Ready control-plane 12m v1.31.3 192.168.122.223 Ubuntu 24.10 6.11.0-9-generic containerd://1.7.23 524 | 525 | ``` 526 | 527 | ```bash 528 | k get pods -A -o wide 529 | 530 | ``` 531 | 532 | ```bash 533 | NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 534 | kube-flannel kube-flannel-ds-9v8fq 1/1 Running 0 2m17s 192.168.122.223 k8scpnode1 535 | kube-system coredns-7c65d6cfc9-dg6nq 1/1 Running 0 12m 10.244.0.2 k8scpnode1 536 | kube-system coredns-7c65d6cfc9-r4ksc 1/1 Running 0 12m 10.244.0.3 k8scpnode1 537 | kube-system etcd-k8scpnode1 1/1 Running 0 13m 192.168.122.223 k8scpnode1 538 | kube-system kube-apiserver-k8scpnode1 1/1 Running 0 12m 192.168.122.223 k8scpnode1 539 | kube-system kube-controller-manager-k8scpnode1 1/1 Running 0 12m 192.168.122.223 k8scpnode1 540 | kube-system kube-proxy-sxtk9 1/1 Running 0 12m 192.168.122.223 k8scpnode1 541 | kube-system kube-scheduler-k8scpnode1 1/1 Running 0 13m 192.168.122.223 k8scpnode1 542 | 543 | ``` 544 | 545 |

 

546 |

 

547 |

 

548 | 549 |

550 | That's it with the control-plane node ! 551 |

552 | 553 | --- 554 | 555 |

 

556 |

 

557 |

 

558 | 559 | ## Worker Nodes 560 | 561 | The following instructions apply similarly to both worker nodes. I will document the steps for the **k8swrknode1** node, but please follow the same process for the **k8swrknode2** node. 562 | 563 | ### Ports on the worker nodes 564 | 565 | As we learned above on the control-plane section, kubernetes runs a few services 566 | 567 | | Protocol | Direction | Port Range | Purpose | Used By | 568 | |----------|-----------|-------------|-------------------|----------------------| 569 | | TCP | Inbound | 10250 | Kubelet API | Self, Control plane | 570 | | TCP | Inbound | 10256 | kube-proxy | Self, Load balancers | 571 | | TCP | Inbound | 30000-32767 | NodePort Services | All | 572 | 573 | ### Firewall on the worker nodes 574 | 575 | so we need to open the necessary ports on the worker nodes too. 576 | 577 | ```bash 578 | sudo ufw allow 10250/tcp 579 | sudo ufw allow 10256/tcp 580 | sudo ufw allow 30000:32767/tcp 581 | 582 | sudo ufw status 583 | 584 | ``` 585 | 586 | The output should appear as follows: 587 | 588 | ``` 589 | To Action From 590 | -- ------ ---- 591 | 22/tcp ALLOW Anywhere 592 | 10250/tcp ALLOW Anywhere 593 | 30000:32767/tcp ALLOW Anywhere 594 | 22/tcp (v6) ALLOW Anywhere (v6) 595 | 10250/tcp (v6) ALLOW Anywhere (v6) 596 | 30000:32767/tcp (v6) ALLOW Anywhere (v6) 597 | ``` 598 | 599 | and do not forget, we also need to open UDP 8472 for flannel 600 | 601 | ```bash 602 | sudo ufw allow 8472/udp 603 | 604 | ``` 605 | 606 | The next few steps are pretty much exactly the same as in the control-plane node. 607 | In order to keep this documentation short, I'll just copy/paste the commands. 608 | 609 | ### Hosts file in the worker node 610 | 611 | Update the `/etc/hosts` file to include the IPs and hostname of all VMs. 612 | 613 | ```bash 614 | 192.168.122.223 k8scpnode1 615 | 192.168.122.50 k8swrknode1 616 | 192.168.122.10 k8swrknode2 617 | 618 | ``` 619 | 620 | ### No Swap on the worker node 621 | 622 | ```bash 623 | sudo swapoff -a 624 | 625 | ``` 626 | 627 | ### Kernel modules on the worker node 628 | 629 | ```bash 630 | sudo tee /etc/modules-load.d/kubernetes.conf </dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' 734 | 735 | ``` 736 | 737 | and in my k8s cluster is: 738 | 739 | 2f68e4b27cae2d2a6431f3da308a691d00d9ef3baa4677249e43b3100d783061 740 | 741 | ## Get (new) Token from the control-plane node 742 | 743 | (the easy way) 744 | 745 | ```bash 746 | sudo kubeadm token create --print-join-command 747 | ``` 748 | 749 | but what's the fun with that? 750 | 751 | ### Join Workers to the kubernetes cluster 752 | 753 | So now, we can Join our worker nodes to the kubernetes cluster. 754 | Run the below command on both worker nodes: 755 | 756 | ```bash 757 | sudo kubeadm join 192.168.122.223:6443 \ 758 | --token 7n4iwm.8xqwfcu4i1co8nof \ 759 | --discovery-token-ca-cert-hash sha256:2f68e4b27cae2d2a6431f3da308a691d00d9ef3baa4677249e43b3100d783061 760 | 761 | ``` 762 | 763 | we get this message 764 | 765 | > Run 'kubectl get nodes' on the control-plane to see this node join the cluster. 766 | 767 | ## Is the kubernetes cluster running ? 768 | 769 | We can verify that 770 | 771 | ```bash 772 | kubectl get nodes -o wide 773 | kubectl get pods -A -o wide 774 | 775 | ``` 776 | 777 | ### All nodes have successfully joined the Kubernetes cluster 778 | 779 | so make sure they are in **Ready** status. 780 | 781 | ``` 782 | k8scpnode1 Ready control-plane 58m v1.31.3 192.168.122.223 Ubuntu 24.10 6.11.0-9-generic containerd://1.7.23 783 | k8swrknode1 Ready 3m37s v1.31.3 192.168.122.50 Ubuntu 24.10 6.11.0-9-generic containerd://1.7.23 784 | k8swrknode2 Ready 3m37s v1.31.3 192.168.122.10 Ubuntu 24.10 6.11.0-9-generic containerd://1.7.23 785 | ``` 786 | 787 | ### All pods 788 | 789 | so make sure all pods are in **Running** status. 790 | 791 | ``` 792 | NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 793 | kube-flannel kube-flannel-ds-9v8fq 1/1 Running 0 46m 192.168.122.223 k8scpnode1 794 | kube-flannel kube-flannel-ds-hmtmv 1/1 Running 0 3m32s 192.168.122.50 k8swrknode1 795 | kube-flannel kube-flannel-ds-rwkrm 1/1 Running 0 3m33s 192.168.122.10 k8swrknode2 796 | kube-system coredns-7c65d6cfc9-dg6nq 1/1 Running 0 57m 10.244.0.2 k8scpnode1 797 | kube-system coredns-7c65d6cfc9-r4ksc 1/1 Running 0 57m 10.244.0.3 k8scpnode1 798 | kube-system etcd-k8scpnode1 1/1 Running 0 57m 192.168.122.223 k8scpnode1 799 | kube-system kube-apiserver-k8scpnode1 1/1 Running 0 57m 192.168.122.223 k8scpnode1 800 | kube-system kube-controller-manager-k8scpnode1 1/1 Running 0 57m 192.168.122.223 k8scpnode1 801 | kube-system kube-proxy-49f6q 1/1 Running 0 3m32s 192.168.122.50 k8swrknode1 802 | kube-system kube-proxy-6qpph 1/1 Running 0 3m33s 192.168.122.10 k8swrknode2 803 | kube-system kube-proxy-sxtk9 1/1 Running 0 57m 192.168.122.223 k8scpnode1 804 | kube-system kube-scheduler-k8scpnode1 1/1 Running 0 57m 192.168.122.223 k8scpnode1 805 | ``` 806 | 807 | That's it ! 808 | 809 | Our **k8s cluster** is running. 810 | 811 |

 

812 |

 

813 |

 

814 | 815 | --- 816 | 817 |

 

818 |

 

819 |

 

820 | 821 | ## Kubernetes Dashboard 822 | 823 | > is a general purpose, web-based UI for Kubernetes clusters. It allows users to manage applications running in the cluster and troubleshoot them, as well as manage the cluster itself. 824 | 825 | Next, we can move forward with installing the Kubernetes dashboard on our cluster. 826 | 827 | ### Helm 828 | 829 | Helm—a package manager for Kubernetes that simplifies the process of deploying applications to a Kubernetes cluster. As of version 7.0.0, kubernetes-dashboard has dropped support for Manifest-based installation. Only Helm-based installation is supported now. 830 | 831 | Live on the edge ! 832 | 833 | ```bash 834 | curl -sL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash 835 | 836 | ``` 837 | 838 | ### Install kubernetes dashboard 839 | 840 | We need to add the kubernetes-dashboard helm repository first and install the helm chart after: 841 | 842 | ```bash 843 | # Add kubernetes-dashboard repository 844 | helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ 845 | 846 | # Deploy a Helm Release named "kubernetes-dashboard" using the kubernetes-dashboard chart 847 | helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard 848 | 849 | ``` 850 | 851 | The output of the command above should resemble something like this: 852 | 853 | ```bash 854 | Release "kubernetes-dashboard" does not exist. Installing it now. 855 | 856 | NAME: kubernetes-dashboard 857 | LAST DEPLOYED: Mon Nov 25 15:36:51 2024 858 | NAMESPACE: kubernetes-dashboard 859 | STATUS: deployed 860 | REVISION: 1 861 | TEST SUITE: None 862 | 863 | NOTES: 864 | ************************************************************************************************* 865 | *** PLEASE BE PATIENT: Kubernetes Dashboard may need a few minutes to get up and become ready *** 866 | ************************************************************************************************* 867 | 868 | Congratulations! You have just installed Kubernetes Dashboard in your cluster. 869 | 870 | To access Dashboard run: 871 | kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443 872 | 873 | NOTE: In case port-forward command does not work, make sure that kong service name is correct. 874 | Check the services in Kubernetes Dashboard namespace using: 875 | kubectl -n kubernetes-dashboard get svc 876 | 877 | Dashboard will be available at: 878 | https://localhost:8443 879 | 880 | ``` 881 | 882 | Verify the installation 883 | 884 | `kubectl -n kubernetes-dashboard get svc` 885 | 886 | ``` 887 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 888 | kubernetes-dashboard-api ClusterIP 10.106.254.153 8000/TCP 3m48s 889 | kubernetes-dashboard-auth ClusterIP 10.103.156.167 8000/TCP 3m48s 890 | kubernetes-dashboard-kong-proxy ClusterIP 10.105.230.13 443/TCP 3m48s 891 | kubernetes-dashboard-metrics-scraper ClusterIP 10.109.7.234 8000/TCP 3m48s 892 | kubernetes-dashboard-web ClusterIP 10.106.125.65 8000/TCP 3m48s 893 | ``` 894 | 895 | `kubectl get all -n kubernetes-dashboard` 896 | 897 | ``` 898 | NAME READY STATUS RESTARTS AGE 899 | pod/kubernetes-dashboard-api-6dbb79747-rbtlc 1/1 Running 0 4m5s 900 | pod/kubernetes-dashboard-auth-55d7cc5fbd-xccft 1/1 Running 0 4m5s 901 | pod/kubernetes-dashboard-kong-57d45c4f69-t9lw2 1/1 Running 0 4m5s 902 | pod/kubernetes-dashboard-metrics-scraper-df869c886-lt624 1/1 Running 0 4m5s 903 | pod/kubernetes-dashboard-web-6ccf8d967-9rp8n 1/1 Running 0 4m5s 904 | 905 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 906 | service/kubernetes-dashboard-api ClusterIP 10.106.254.153 8000/TCP 4m10s 907 | service/kubernetes-dashboard-auth ClusterIP 10.103.156.167 8000/TCP 4m10s 908 | service/kubernetes-dashboard-kong-proxy ClusterIP 10.105.230.13 443/TCP 4m10s 909 | service/kubernetes-dashboard-metrics-scraper ClusterIP 10.109.7.234 8000/TCP 4m10s 910 | service/kubernetes-dashboard-web ClusterIP 10.106.125.65 8000/TCP 4m10s 911 | 912 | NAME READY UP-TO-DATE AVAILABLE AGE 913 | deployment.apps/kubernetes-dashboard-api 1/1 1 1 4m7s 914 | deployment.apps/kubernetes-dashboard-auth 1/1 1 1 4m7s 915 | deployment.apps/kubernetes-dashboard-kong 1/1 1 1 4m7s 916 | deployment.apps/kubernetes-dashboard-metrics-scraper 1/1 1 1 4m7s 917 | deployment.apps/kubernetes-dashboard-web 1/1 1 1 4m7s 918 | 919 | NAME DESIRED CURRENT READY AGE 920 | replicaset.apps/kubernetes-dashboard-api-6dbb79747 1 1 1 4m6s 921 | replicaset.apps/kubernetes-dashboard-auth-55d7cc5fbd 1 1 1 4m6s 922 | replicaset.apps/kubernetes-dashboard-kong-57d45c4f69 1 1 1 4m6s 923 | replicaset.apps/kubernetes-dashboard-metrics-scraper-df869c886 1 1 1 4m6s 924 | replicaset.apps/kubernetes-dashboard-web-6ccf8d967 1 1 1 4m6s 925 | 926 | ``` 927 | 928 | ### Accessing Dashboard via a NodePort 929 | 930 | A NodePort is a type of Service in Kubernetes that exposes a service on each node’s IP at a static port. This allows external traffic to reach the service by accessing the node’s IP and port. kubernetes-dashboard by default runs on a internal 10.x.x.x IP. To access the dashboard we need to have a NodePort in the kubernetes-dashboard service. 931 | 932 | We can either **Patch** the service or **edit** the yaml file. 933 | 934 | Choose one of the two options below; there’s no need to run both as it’s unnecessary (but not harmful). 935 | 936 | #### Patch kubernetes-dashboard 937 | 938 | This is one way to add a NodePort. 939 | 940 | ```bash 941 | kubectl --namespace kubernetes-dashboard patch svc kubernetes-dashboard-kong-proxy -p '{"spec": {"type": "NodePort"}}' 942 | ``` 943 | 944 | output 945 | 946 | ``` 947 | service/kubernetes-dashboard-kong-proxy patched 948 | ``` 949 | 950 | verify the service 951 | 952 | ```bash 953 | kubectl get svc -n kubernetes-dashboard 954 | ``` 955 | 956 | output 957 | 958 | ``` 959 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 960 | kubernetes-dashboard-api ClusterIP 10.106.254.153 8000/TCP 50m 961 | kubernetes-dashboard-auth ClusterIP 10.103.156.167 8000/TCP 50m 962 | kubernetes-dashboard-kong-proxy NodePort 10.105.230.13 443:32116/TCP 50m 963 | kubernetes-dashboard-metrics-scraper ClusterIP 10.109.7.234 8000/TCP 50m 964 | kubernetes-dashboard-web ClusterIP 10.106.125.65 8000/TCP 50m 965 | ``` 966 | 967 | we can see the **32116** in the kubernetes-dashboard. 968 | 969 | #### Edit kubernetes-dashboard Service 970 | 971 | This is an alternative way to add a NodePort. 972 | 973 | ```bash 974 | kubectl edit svc -n kubernetes-dashboard kubernetes-dashboard-kong-proxy 975 | 976 | ``` 977 | 978 | and chaning the service type from 979 | 980 | ``` 981 | type: ClusterIP 982 | ``` 983 | 984 | to 985 | 986 | ``` 987 | type: NodePort 988 | ``` 989 | 990 | ### Accessing Kubernetes Dashboard 991 | 992 | The kubernetes-dashboard has two (2) pods, one (1) for metrics, one (2) for the dashboard. 993 | 994 | To access the dashboard, first we need to identify in which Node is running. 995 | 996 | ```bash 997 | kubectl get pods -n kubernetes-dashboard -o wide 998 | 999 | ``` 1000 | 1001 | ``` 1002 | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 1003 | kubernetes-dashboard-api-56f6f4b478-p4xbj 1/1 Running 0 55m 10.244.2.12 k8swrknode1 1004 | kubernetes-dashboard-auth-565b88d5f9-fscj9 1/1 Running 0 55m 10.244.1.12 k8swrknode2 1005 | kubernetes-dashboard-kong-57d45c4f69-rts57 1/1 Running 0 55m 10.244.2.10 k8swrknode1 1006 | kubernetes-dashboard-metrics-scraper-df869c886-bljqr 1/1 Running 0 55m 10.244.2.11 k8swrknode1 1007 | kubernetes-dashboard-web-6ccf8d967-t6k28 1/1 Running 0 55m 10.244.1.11 k8swrknode2 1008 | ``` 1009 | 1010 | In my setup the dashboard pod is running on the **worker node 1** and from the `/etc/hosts` is on the **192.168.122.50** IP. 1011 | 1012 | The NodePort is **32116** 1013 | 1014 | ```bash 1015 | k get svc -n kubernetes-dashboard -o wide 1016 | 1017 | ``` 1018 | 1019 | So, we can open a new tab on our browser and type: 1020 | 1021 | https://192.168.122.50:32116 1022 | 1023 | and accept the self-signed certificate! 1024 | 1025 | ![k8s_dashboard.jpg](attachments/SCR20241127pdvk.png) 1026 | 1027 | ### Create An Authentication Token (RBAC) 1028 | 1029 | Last step for the kubernetes-dashboard is to create an authentication token. 1030 | 1031 | #### Creating a Service Account 1032 | 1033 | Create a new yaml file, with kind: **ServiceAccount** that has access to kubernetes-dashboard namespace and has name: admin-user. 1034 | 1035 | ```bash 1036 | cat > kubernetes-dashboard.ServiceAccount.yaml < kubernetes-dashboard.ClusterRoleBinding.yaml < Nodes 1117 | 1118 | ![k8s_dashboard.jpg](attachments/SCR20241127phat.png) 1119 | 1120 |

 

1121 |

 

1122 |

 

1123 | 1124 | --- 1125 | 1126 |

 

1127 |

 

1128 |

 

1129 | 1130 | ## Nginx App 1131 | 1132 | Before finishing this blog post, I would also like to share how to install a simple nginx-app as it is customary to do such thing in every new k8s cluster. 1133 | 1134 | But plz excuse me, I will not get into much details. 1135 | You should be able to understand the below k8s commands. 1136 | 1137 | ### Install nginx-app 1138 | 1139 | ```bash 1140 | kubectl create deployment nginx-app --image=nginx --replicas=2 1141 | 1142 | ``` 1143 | 1144 | ```bash 1145 | deployment.apps/nginx-app created 1146 | ``` 1147 | 1148 | ### Get Deployment 1149 | 1150 | ```bash 1151 | kubectl get deployment nginx-app -o wide 1152 | ``` 1153 | 1154 | ```bash 1155 | NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR 1156 | nginx-app 2/2 2 2 64s nginx nginx app=nginx-app 1157 | ``` 1158 | 1159 | ### Expose Nginx-App 1160 | 1161 | ```bash 1162 | kubectl expose deployment nginx-app --type=NodePort --port=80 1163 | 1164 | ``` 1165 | 1166 | ```bash 1167 | service/nginx-app exposed 1168 | ``` 1169 | 1170 | ### Verify Service nginx-app 1171 | 1172 | ```bash 1173 | kubectl get svc nginx-app -o wide 1174 | 1175 | ``` 1176 | 1177 | ```bash 1178 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR 1179 | nginx-app NodePort 10.98.170.185 80:31761/TCP 27s app=nginx-app 1180 | 1181 | ``` 1182 | 1183 | ### Describe Service nginx-app 1184 | 1185 | ```bash 1186 | kubectl describe svc nginx-app 1187 | 1188 | ``` 1189 | 1190 | ```bash 1191 | Name: nginx-app 1192 | Namespace: default 1193 | Labels: app=nginx-app 1194 | Annotations: 1195 | Selector: app=nginx-app 1196 | Type: NodePort 1197 | IP Family Policy: SingleStack 1198 | IP Families: IPv4 1199 | IP: 10.98.170.185 1200 | IPs: 10.98.170.185 1201 | Port: 80/TCP 1202 | TargetPort: 80/TCP 1203 | NodePort: 31761/TCP 1204 | Endpoints: 10.244.1.10:80,10.244.2.10:80 1205 | Session Affinity: None 1206 | External Traffic Policy: Cluster 1207 | Events: 1208 | 1209 | 1210 | ``` 1211 | 1212 | ### Curl Nginx-App 1213 | 1214 | ```bash 1215 | curl http://192.168.122.8:31761 1216 | 1217 | ``` 1218 | 1219 | ```bash 1220 | 1221 | 1222 | 1223 | Welcome to nginx! 1224 | 1229 | 1230 | 1231 |

Welcome to nginx!

1232 |

If you see this page, the nginx web server is successfully installed and 1233 | working. Further configuration is required.

1234 | 1235 |

For online documentation and support please refer to 1236 | nginx.org.
1237 | Commercial support is available at 1238 | nginx.com.

1239 | 1240 |

Thank you for using nginx.

1241 | 1242 | 1243 | 1244 | 1245 | ``` 1246 | 1247 | ### Nginx-App from Browser 1248 | 1249 | ![k8s_nginx-app.jpg](attachments/88d4150c.jpg) 1250 | 1251 | 1252 | ### Change the default page 1253 | 1254 | Last but not least, let's modify the default index page to something different for educational purposes with the help of a **ConfigMap** 1255 | 1256 | The idea is to create a ConfigMap with the html of our new index page then we would like to attach it to our nginx deployment as a volume mount ! 1257 | 1258 | ```bash 1259 | cat > nginx_config.map << EOF 1260 | apiVersion: v1 1261 | data: 1262 | index.html: | 1263 | 1264 | 1265 | 1266 | A simple HTML document 1267 | 1268 | 1269 |

Change the default nginx page

1270 | 1271 | 1272 | kind: ConfigMap 1273 | metadata: 1274 | name: nginx-config-page 1275 | namespace: default 1276 | EOF 1277 | ``` 1278 | 1279 | cat nginx_config.map 1280 | 1281 | ```yaml 1282 | apiVersion: v1 1283 | data: 1284 | index.html: | 1285 | 1286 | 1287 | 1288 | A simple HTML document 1289 | 1290 | 1291 |

Change the default nginx page

1292 | 1293 | 1294 | kind: ConfigMap 1295 | metadata: 1296 | name: nginx-config-page 1297 | namespace: default 1298 | ``` 1299 | 1300 | apply the config.map 1301 | 1302 | ```bash 1303 | kubectl apply -f nginx_config.map 1304 | 1305 | ``` 1306 | 1307 | verify 1308 | 1309 | ```bash 1310 | kubectl get configmap 1311 | ``` 1312 | 1313 | ``` 1314 | NAME DATA AGE 1315 | kube-root-ca.crt 1 2d3h 1316 | nginx-config-page 1 16m 1317 | ``` 1318 | 1319 | now the diffucult part, we need to mount our config map to the nginx deployment and to do that, we need to edit the nginx deployment. 1320 | 1321 | ```bash 1322 | kubectl edit deployments.apps nginx-app 1323 | ``` 1324 | 1325 | rewrite spec section to include: 1326 | 1327 | * the VolumeMount & 1328 | * the ConfigMap as Volume 1329 | 1330 | ```yaml 1331 | spec: 1332 | containers: 1333 | - image: nginx 1334 | ... 1335 | volumeMounts: 1336 | - mountPath: /usr/share/nginx/html 1337 | name: nginx-config 1338 | ... 1339 | volumes: 1340 | - configMap: 1341 | name: nginx-config-page 1342 | name: nginx-config 1343 | ``` 1344 | 1345 | After saving, the nginx deployment will be updated by it-self. 1346 | 1347 | finally we can see our updated first index page: 1348 | 1349 | ![k8s_nginx-index.jpg](attachments/SCR20241127pnxl.png) 1350 | 1351 |

 

1352 |

 

1353 |

 

1354 | 1355 | --- 1356 | 1357 |

 

1358 |

 

1359 |

 

1360 | 1361 | ## That's it 1362 | 1363 | I hope you enjoyed this post. 1364 | 1365 | -Evaggelos Balaskas 1366 | 1367 |

 

1368 |

 

1369 |

 

1370 | 1371 | --- 1372 | 1373 |

 

1374 |

 

1375 |

 

1376 | 1377 | ### destroy our lab 1378 | 1379 | ```bash 1380 | ./destroy.sh 1381 | ``` 1382 | 1383 | ```bash 1384 | ... 1385 | 1386 | libvirt_domain.domain-ubuntu["k8wrknode1"]: Destroying... [id=446cae2a-ce14-488f-b8e9-f44839091bce] 1387 | libvirt_domain.domain-ubuntu["k8scpnode"]: Destroying... [id=51e12abb-b14b-4ab8-b098-c1ce0b4073e3] 1388 | time_sleep.wait_for_cloud_init: Destroying... [id=2022-08-30T18:02:06Z] 1389 | libvirt_domain.domain-ubuntu["k8wrknode2"]: Destroying... [id=0767fb62-4600-4bc8-a94a-8e10c222b92e] 1390 | time_sleep.wait_for_cloud_init: Destruction complete after 0s 1391 | libvirt_domain.domain-ubuntu["k8wrknode1"]: Destruction complete after 1s 1392 | libvirt_domain.domain-ubuntu["k8scpnode"]: Destruction complete after 1s 1393 | libvirt_domain.domain-ubuntu["k8wrknode2"]: Destruction complete after 1s 1394 | libvirt_cloudinit_disk.cloud-init["k8wrknode1"]: Destroying... [id=/var/lib/libvirt/images/Jpw2Sg_cloud-init.iso;b8ddfa73-a770-46de-ad16-b0a5a08c8550] 1395 | libvirt_cloudinit_disk.cloud-init["k8wrknode2"]: Destroying... [id=/var/lib/libvirt/images/VdUklQ_cloud-init.iso;5511ed7f-a864-4d3f-985a-c4ac07eac233] 1396 | libvirt_volume.ubuntu-base["k8scpnode"]: Destroying... [id=/var/lib/libvirt/images/l5Rr1w_ubuntu-base] 1397 | libvirt_volume.ubuntu-base["k8wrknode2"]: Destroying... [id=/var/lib/libvirt/images/VdUklQ_ubuntu-base] 1398 | libvirt_cloudinit_disk.cloud-init["k8scpnode"]: Destroying... [id=/var/lib/libvirt/images/l5Rr1w_cloud-init.iso;11ef6bb7-a688-4c15-ae33-10690500705f] 1399 | libvirt_volume.ubuntu-base["k8wrknode1"]: Destroying... [id=/var/lib/libvirt/images/Jpw2Sg_ubuntu-base] 1400 | libvirt_cloudinit_disk.cloud-init["k8wrknode1"]: Destruction complete after 1s 1401 | libvirt_volume.ubuntu-base["k8wrknode2"]: Destruction complete after 1s 1402 | libvirt_cloudinit_disk.cloud-init["k8scpnode"]: Destruction complete after 1s 1403 | libvirt_cloudinit_disk.cloud-init["k8wrknode2"]: Destruction complete after 1s 1404 | libvirt_volume.ubuntu-base["k8wrknode1"]: Destruction complete after 1s 1405 | libvirt_volume.ubuntu-base["k8scpnode"]: Destruction complete after 2s 1406 | libvirt_volume.ubuntu-vol["k8wrknode1"]: Destroying... [id=/var/lib/libvirt/images/Jpw2Sg_ubuntu-vol] 1407 | libvirt_volume.ubuntu-vol["k8scpnode"]: Destroying... [id=/var/lib/libvirt/images/l5Rr1w_ubuntu-vol] 1408 | libvirt_volume.ubuntu-vol["k8wrknode2"]: Destroying... [id=/var/lib/libvirt/images/VdUklQ_ubuntu-vol] 1409 | libvirt_volume.ubuntu-vol["k8scpnode"]: Destruction complete after 0s 1410 | libvirt_volume.ubuntu-vol["k8wrknode2"]: Destruction complete after 0s 1411 | libvirt_volume.ubuntu-vol["k8wrknode1"]: Destruction complete after 0s 1412 | random_id.id["k8scpnode"]: Destroying... [id=l5Rr1w] 1413 | random_id.id["k8wrknode2"]: Destroying... [id=VdUklQ] 1414 | random_id.id["k8wrknode1"]: Destroying... [id=Jpw2Sg] 1415 | random_id.id["k8wrknode2"]: Destruction complete after 0s 1416 | random_id.id["k8scpnode"]: Destruction complete after 0s 1417 | random_id.id["k8wrknode1"]: Destruction complete after 0s 1418 | 1419 | Destroy complete! Resources: 16 destroyed. 1420 | 1421 | ``` 1422 | -------------------------------------------------------------------------------- /attachments/317345a8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/317345a8.jpg -------------------------------------------------------------------------------- /attachments/3946b715.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/3946b715.jpg -------------------------------------------------------------------------------- /attachments/4e1384ce.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/4e1384ce.jpg -------------------------------------------------------------------------------- /attachments/88d4150c.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/88d4150c.jpg -------------------------------------------------------------------------------- /attachments/SCR20241127pdvk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/SCR20241127pdvk.png -------------------------------------------------------------------------------- /attachments/SCR20241127pglz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/SCR20241127pglz.png -------------------------------------------------------------------------------- /attachments/SCR20241127phat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/SCR20241127phat.png -------------------------------------------------------------------------------- /attachments/SCR20241127pnxl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebal/k8s_cluster/11e8b0fb40d5e10a20d10dfb216062678ad27501/attachments/SCR20241127pnxl.png -------------------------------------------------------------------------------- /attachments/k8s_architecture.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Kubernetes Cluster Architecture 7 | 8 | 9 | 10 | Infrastructure Environment 11 | 12 | 13 | 14 | Control Plane 15 | 16 | 17 | 18 | API Server 19 | 20 | 21 | etcd 22 | 23 | 24 | Controller Manager 25 | 26 | 27 | Scheduler 28 | 29 | 30 | Cloud Controller Manager 31 | 32 | 33 | 34 | Worker Nodes 35 | 36 | 37 | 38 | Worker Node 1 39 | 40 | 41 | kubelet 42 | 43 | 44 | kube-proxy 45 | 46 | 47 | Container Runtime 48 | 49 | 50 | Pods 51 | 52 | 53 | 54 | Worker Node 2 55 | 56 | 57 | kubelet 58 | 59 | 60 | kube-proxy 61 | 62 | 63 | Container Runtime 64 | 65 | 66 | Pods 67 | 68 | 69 | 70 | Networking 71 | 72 | Network Plugin (CNI) 73 | 74 | Service Mesh (Optional) 75 | 76 | 77 | 78 | Storage 79 | 80 | Local Volumes 81 | 82 | PersistentVolumes 83 | 84 | StorageClasses 85 | 86 | CSI Plugins 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /scripts/CNI_Calico.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Calico over Flannel as the CNI (Container Network Interface) 4 | 5 | # remove flannel if installed! 6 | kubectl delete -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml 7 | 8 | # open firewall ports 9 | sudo ufw allow proto tcp from any to any port 443 10 | # BGP 11 | sudo ufw allow proto tcp from any to any port 179 12 | sudo ufw allow proto udp from any to any port 9099 13 | 14 | # install calico 15 | kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml 16 | 17 | echo "You need to open firewall ports to worker noders too !" 18 | 19 | -------------------------------------------------------------------------------- /scripts/setup_k8s_control.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | # Open the necessary ports on the CP's (control-plane node) firewall. 4 | sudo ufw allow 6443/tcp 5 | sudo ufw allow 2379:2380/tcp 6 | sudo ufw allow 10250/tcp 7 | sudo ufw allow 10259/tcp 8 | sudo ufw allow 10257/tcp 9 | 10 | # Get status 11 | sudo ufw status 12 | 13 | # Disable Swap 14 | sudo swapoff -a 15 | sudo sed -i 's/^swap/#swap/' /etc/fstab 16 | 17 | # Always load on boot the k8s modules needed. 18 | sudo tee /etc/modules-load.d/kubernetes.conf <:6443 --token --discovery-token-ca-cert-hash sha256:" 78 | echo "" 79 | -------------------------------------------------------------------------------- /tf_libvirt/Cloudinit.tf: -------------------------------------------------------------------------------- 1 | resource "random_id" "id" { 2 | for_each = local.VMs 3 | 4 | byte_length = 4 5 | } 6 | 7 | data "template_file" "user_data" { 8 | for_each = local.VMs 9 | 10 | template = file("templates/user-data.yml") 11 | vars = { 12 | hostname = each.value 13 | sshdport = local.ssh_port 14 | timezone = local.timezone 15 | gh_user = local.gh_user 16 | } 17 | } 18 | 19 | data "template_file" "network_config" { 20 | template = file("templates/netplan.yml") 21 | } 22 | 23 | resource "libvirt_cloudinit_disk" "cloud-init" { 24 | for_each = local.VMs 25 | 26 | name = "${random_id.id[each.key].id}_cloud-init.iso" 27 | user_data = data.template_file.user_data[each.key].rendered 28 | 29 | depends_on = [data.template_file.user_data] 30 | } 31 | 32 | resource "time_sleep" "wait_for_cloud_init" { 33 | create_duration = "20s" 34 | 35 | depends_on = [libvirt_cloudinit_disk.cloud-init] 36 | } 37 | -------------------------------------------------------------------------------- /tf_libvirt/Domain.tf: -------------------------------------------------------------------------------- 1 | resource "libvirt_domain" "domain-ubuntu" { 2 | for_each = local.VMs 3 | 4 | name = each.value 5 | 6 | memory = local.vmem 7 | vcpu = local.vcpu 8 | 9 | cloudinit = libvirt_cloudinit_disk.cloud-init[each.key].id 10 | 11 | network_interface { 12 | network_name = "default" 13 | wait_for_lease = true 14 | } 15 | 16 | console { 17 | target_type = "serial" 18 | type = "pty" 19 | target_port = "0" 20 | } 21 | console { 22 | target_type = "virtio" 23 | type = "pty" 24 | target_port = "1" 25 | } 26 | 27 | disk { 28 | volume_id = libvirt_volume.ubuntu-base[each.key].id 29 | } 30 | 31 | depends_on = [libvirt_cloudinit_disk.cloud-init] 32 | } 33 | 34 | -------------------------------------------------------------------------------- /tf_libvirt/Output.tf: -------------------------------------------------------------------------------- 1 | output "VMs" { 2 | value = [ for vms in libvirt_domain.domain-ubuntu : format("%s %s", vms.network_interface.0.addresses[0], vms.name) ] 3 | 4 | depends_on = [libvirt_domain.domain-ubuntu] 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tf_libvirt/Provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 1.9" 3 | 4 | required_providers { 5 | libvirt = { 6 | source = "dmacvicar/libvirt" 7 | version = "0.8.1" 8 | } 9 | 10 | template = { 11 | source = "hashicorp/template" 12 | } 13 | 14 | random = { 15 | source = "hashicorp/random" 16 | } 17 | 18 | time = { 19 | source = "hashicorp/time" 20 | } 21 | } 22 | } 23 | 24 | provider "libvirt" { 25 | uri = "qemu:///system" 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tf_libvirt/README.md: -------------------------------------------------------------------------------- 1 | # Deploy the Ubuntu 24.04 LTS virtual machines to libvirt/QEMU using Terraform 2 | 3 | Creating a Terraform repository to deploy a Kubernetes cluster for educational purposes. 4 | 5 | It creates three (3) QEMU/KVM virtual machines running Ubuntu 24.04 LTS, provisioned through Libvirt. 6 | 7 | ## Step 0: Configure Variables 8 | 9 | You need to edit **Variables.tf** 10 | 11 | - timezone 12 | - ssh port 13 | - hostname 14 | - vcpu 15 | - vmem 16 | - vol_size 17 | 18 | and especially the Variable 19 | 20 | - github user 21 | 22 | ... allowing you to access these VMs via SSH. 23 | 24 | ## Step 1: Initialize Terraform 25 | 26 | ```bash 27 | terraform init 28 | 29 | ``` 30 | 31 | ## Step 2: Preview the Infrastructure Changes 32 | 33 | ```bash 34 | terraform plan 35 | 36 | ``` 37 | 38 | ## Step 3: Apply the Terraform Configuration 39 | 40 | using a bash shell script to automate creation 41 | 42 | ```bash 43 | ./start.sh 44 | ``` 45 | 46 | ## Console Output 47 | 48 | 49 | ``` 50 | Apply complete! Resources: 16 added, 0 changed, 0 destroyed. 51 | 52 | Outputs: 53 | 54 | VMs = [ 55 | "192.168.122.223 k8scpnode1", 56 | "192.168.122.50 k8swrknode1", 57 | "192.168.122.10 k8swrknode2", 58 | ] 59 | ``` 60 | 61 | ### Verify 62 | 63 | ```bash 64 | $ ssh -l ubuntu 192.168.122.223 hostname 65 | k8scpnode1 66 | 67 | $ ssh 192.168.122.223 -l ubuntu 'grep ^VERSION= /etc/os-release' 68 | VERSION="24.10 (Oracular Oriole)" 69 | 70 | ``` 71 | 72 | ## Destroy Everything 73 | 74 | run destroy bash shell script 75 | 76 | ```bash 77 | ./destroy.sh 78 | 79 | ``` 80 | 81 | ## Root Password 82 | 83 | If you need to set a root password for the Ubuntu 24.04 LTS virtual machine during its creation via Terraform 84 | 85 | ```bash 86 | $ sudo virsh console k8scpnode1 87 | 88 | userame: root 89 | password: ping 90 | 91 | ```` 92 | -------------------------------------------------------------------------------- /tf_libvirt/Variables.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | # cloud_image = "https://cloud-images.ubuntu.com/oracular/current/oracular-server-cloudimg-amd64.img" 3 | cloud_image = "../../../images/ubuntu/oracular-server-cloudimg-amd64.img" 4 | 5 | # Virtual Machines 6 | VMs = toset(["k8scpnode1", "k8swrknode1", "k8swrknode2"]) 7 | 8 | # TimeZone of the VM: /usr/share/zoneinfo/ 9 | timezone = "Europe/Athens" 10 | 11 | # The sshd port of the VM" 12 | ssh_port = 22 13 | 14 | # The default ssh key for user ubuntu 15 | # https://github.com/.keys 16 | gh_user = "ebal" 17 | 18 | # The disk volume size of the VM 19 | # eg. 40G 20 | vol_size = 40 * 1024 * 1024 * 1024 21 | 22 | # How many virtual CPUs the VM 23 | vcpu = 4 24 | 25 | # How RAM will VM have will have 26 | vmem = 4096 27 | } 28 | -------------------------------------------------------------------------------- /tf_libvirt/Volume.tf: -------------------------------------------------------------------------------- 1 | resource "libvirt_volume" "ubuntu-vol" { 2 | for_each = local.VMs 3 | 4 | name = "${random_id.id[each.key].id}_ubuntu-vol" 5 | pool = "default" 6 | source = local.cloud_image 7 | format = "qcow2" 8 | } 9 | 10 | resource "libvirt_volume" "ubuntu-base" { 11 | for_each = local.VMs 12 | 13 | name = "${random_id.id[each.key].id}_ubuntu-base" 14 | pool = "default" 15 | base_volume_id = libvirt_volume.ubuntu-vol[each.key].id 16 | size = local.vol_size 17 | format = "qcow2" 18 | } 19 | -------------------------------------------------------------------------------- /tf_libvirt/destroy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | terraform destroy -auto-approve 3 | -------------------------------------------------------------------------------- /tf_libvirt/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | terraform plan -out terraform.out && terraform apply terraform.out 3 | -------------------------------------------------------------------------------- /tf_libvirt/templates/netplan.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | ethernets: 3 | ens3: 4 | dhcp4: true 5 | -------------------------------------------------------------------------------- /tf_libvirt/templates/user-data.yml: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | 3 | #disable_root: true 4 | disable_root: false 5 | chpasswd: 6 | list: | 7 | root:ping 8 | expire: False 9 | 10 | ssh_pwauth: no 11 | 12 | users: 13 | - name: ubuntu 14 | ssh_import_id: 15 | - gh:${gh_user} 16 | shell: /bin/bash 17 | sudo: ALL=(ALL) NOPASSWD:ALL 18 | 19 | write_files: 20 | - path: /etc/ssh/sshd_config 21 | content: | 22 | AcceptEnv LANG LC_* 23 | AllowUsers ubuntu 24 | ChallengeResponseAuthentication no 25 | Compression NO 26 | MaxSessions 3 27 | PasswordAuthentication no 28 | PermitRootLogin no 29 | Port ${sshdport} 30 | PrintMotd no 31 | Subsystem sftp /usr/lib/openssh/sftp-server 32 | UseDNS no 33 | UsePAM yes 34 | X11Forwarding no 35 | Ciphers chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com 36 | KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256 37 | MACs umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512 38 | HostKeyAlgorithms ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa 39 | 40 | # Set TimeZone 41 | timezone: ${timezone} 42 | 43 | hostname: "${hostname}" 44 | 45 | growpart: 46 | mode: auto 47 | devices: ["/"] 48 | ignore_growroot_disabled: false 49 | 50 | # Install packages 51 | packages: 52 | - bash-completion 53 | - figlet 54 | - mlocate 55 | - ncdu 56 | - python3-apt 57 | 58 | # Update/Upgrade & Reboot if necessary 59 | package_update: true 60 | package_upgrade: true 61 | package_reboot_if_required: true 62 | 63 | # PostInstall 64 | runcmd: 65 | - figlet ${hostname} > /etc/motd 66 | - updatedb 67 | # Firewall 68 | - ufw allow "${sshdport}"/tcp && ufw enable 69 | # Remove cloud-init 70 | - apt-get -y autoremove --purge cloud-init lxc lxd snapd 71 | - apt-get -y --purge autoremove 72 | - apt -y autoclean 73 | - apt -y clean all 74 | - date -R > /root/Finished.txt 75 | --------------------------------------------------------------------------------