├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── SECURITY.md ├── images ├── Screenshot-csi-driver-nfs.png ├── Screenshot-csi-driver-smb.png ├── Screenshot-end-output-of-playbook-run.png ├── Screenshot-host-control-plane-file.png ├── Screenshot-host-workers-file.png ├── Screenshot-metallb-ip-pool.png ├── Screenshot-metallb.png ├── Screenshot-pod-network-cidr-file.png └── Screenshot-setup-script-run.png ├── inst-k8s-ansible.tar.gz ├── inst-k8s-ansible ├── ansible.cfg ├── host-control-plane ├── host-workers ├── inst-k8s-ansible.yaml ├── inventory │ ├── ansible_control_host │ │ └── hosts │ ├── host_vars │ │ └── local-ansible-control-host.yaml │ ├── k8s_cluster_ctrl_plane_node │ │ └── hosts │ └── k8s_cluster_worker_nodes │ │ └── hosts ├── optional-install-metallb.yaml ├── optional-k8s-csi-nfs-driver.yaml ├── optional-k8s-csi-smb-driver.yaml ├── pod-network-cidr ├── roles │ ├── apply_rules_for_firewalld │ │ └── tasks │ │ │ ├── apply_rules.yaml │ │ │ └── main.yaml │ ├── check_cluster_ready_status │ │ └── tasks │ │ │ └── main.yaml │ ├── fetch_latest_version_number │ │ └── tasks │ │ │ └── main.yaml │ ├── install_and_configure_metallb │ │ ├── tasks │ │ │ └── main.yaml │ │ └── templates │ │ │ └── metallb_config.j2 │ ├── install_and_configure_the_cluster │ │ ├── tasks │ │ │ ├── apply_calico_cni_manifest.yaml │ │ │ ├── create_kube_config.yaml │ │ │ ├── kubeadm_config_images_pull.yaml │ │ │ ├── kubeadm_init.yaml │ │ │ └── main.yaml │ │ └── vars │ │ │ └── main.yaml │ ├── install_k8s_csi_nfs_driver │ │ └── tasks │ │ │ └── main.yaml │ ├── install_k8s_csi_smb_driver │ │ └── tasks │ │ │ └── main.yaml │ ├── join_worker_nodes_to_the_cluster │ │ └── tasks │ │ │ └── main.yaml │ └── prepare_all_the_cluster_nodes │ │ ├── tasks │ │ ├── debian_tasks.yaml │ │ ├── disable_swap.yaml │ │ ├── install_containerd.yaml │ │ ├── install_runc.yaml │ │ ├── load_kernel_modules.yaml │ │ ├── load_kernel_parameters.yaml │ │ ├── main.yaml │ │ ├── redhat_tasks.yaml │ │ ├── suse_tasks.yaml │ │ └── upgrade_os.yaml │ │ └── vars │ │ └── main.yaml ├── setup.py └── testing │ ├── my-gcp-lab-k8s-setup.py │ ├── my-local-k8s-setup.py │ └── my-local-k8s-test-setup.py ├── playbook_version.json └── update-tarball.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Muthukumar-Subramaniam] 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Pull Request 2 | 3 | ## Description 4 | 5 | Please include a summary of the change and which issue is fixed. Also include relevant motivation and context. 6 | 7 | ## Does this fix a reported issue? 8 | 9 | - [ ] Yes, Issue Number: #[issue number] 10 | - [ ] No 11 | 12 | ## Type of Change 13 | 14 | - [ ] Bugfix 15 | - [ ] Feature 16 | - [ ] Documentation Update 17 | - [ ] Other (please specify): 18 | 19 | ## How Has This Been Tested? 20 | 21 | Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. 22 | 23 | - [ ] Test A 24 | - [ ] Test B 25 | 26 | ## Checklist 27 | 28 | - [ ] My code follows the style guidelines of this project 29 | - [ ] I have performed a self-review of my code 30 | - [ ] I have commented my code, particularly in hard-to-understand areas 31 | - [ ] I have made corresponding changes to the documentation 32 | - [ ] My changes generate no new warnings 33 | - [ ] Any dependent changes have been merged and published in downstream modules 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/logs-* 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | msmkumar.eee@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to [install-k8s-on-linux](https://github.com/Muthukumar-Subramaniam/install-k8s-on-linux) 2 | 3 | Thank you for considering contributing to this project! We welcome all forms of contributions and appreciate your efforts. Please take a moment to review this guide before you start contributing. 4 | 5 | ## How Can You Contribute? 6 | 7 | ### 1. Reporting Bugs 8 | If you find any bugs, please report them by opening an issue in the [Issues section](https://github.com/Muthukumar-Subramaniam/install-k8s-on-linux/issues). Include the following: 9 | - A clear and descriptive title. 10 | - A detailed description of the problem, including steps to reproduce the issue. 11 | - The version of the project you're using, operating system, and other relevant information. 12 | 13 | ### 2. Suggesting Features or Enhancements 14 | If you have ideas for improving the project, feel free to submit feature requests or suggestions by opening an issue. Please include: 15 | - A description of the feature and why it would be beneficial. 16 | - Any implementation details or relevant resources, if applicable. 17 | 18 | ### 3. Submitting Code 19 | We welcome code contributions. Here’s how to get started: 20 | - Fork the repository and create your branch from `main` (e.g., `git checkout -b feature-branch`). 21 | - Ensure your code is well-documented and follows the project's coding standards. 22 | - Add or update documentation as necessary. 23 | - Commit your changes (e.g., `git commit -m 'Add feature X'`). 24 | - Push your branch to GitHub (e.g., `git push origin feature-branch`). 25 | - Open a pull request (PR) with a clear description of the changes. 26 | 27 | ### 4. Improving Documentation 28 | Documentation improvements are always welcome. If you find areas in the documentation that need updates or missing sections, feel free to contribute. You can: 29 | - Submit issues with suggestions or open a pull request to update the `README.md`, `CONTRIBUTING.md`, or other documentation files. 30 | 31 | ## Code Style and Guidelines 32 | 33 | To keep the codebase clean and easy to maintain, please follow these guidelines: 34 | - Write clear and self-explanatory comments in your code. 35 | - Maintain consistent formatting and naming conventions throughout the codebase. 36 | 37 | ### Commit Messages 38 | - Use clear and concise commit messages. 39 | - Follow this format if possible: 40 | - `feat`: New feature 41 | - `fix`: Bug fix 42 | - `docs`: Documentation changes 43 | - `style`: Code style changes (white-space, formatting, etc.) 44 | - `refactor`: Code restructuring 45 | - `test`: Adding or modifying tests 46 | 47 | ## Code of Conduct 48 | 49 | By contributing to this project, you agree to follow our [Code of Conduct](CODE_OF_CONDUCT.md). 50 | 51 | --- 52 | 53 | ## Getting Help 54 | 55 | If you have any questions or need assistance, feel free to reach out via the [Issues](https://github.com/Muthukumar-Subramaniam/install-k8s-on-linux/issues) or start a discussion. 56 | 57 | We appreciate your contributions and your effort to make this project better! 😊 58 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | ## Preamble 12 | 13 | The GNU General Public License is a free, copyleft license for 14 | software and other kinds of works. 15 | 16 | The licenses for most software and other practical works are designed 17 | to take away your freedom to share and change the works. By contrast, 18 | the GNU General Public License is intended to guarantee your freedom 19 | to share and change all versions of a program--to make sure it remains 20 | free software for all its users. We, the Free Software Foundation, use 21 | the GNU General Public License for most of our software; it applies 22 | also to any other work released this way by its authors. You can apply 23 | it to your programs, too. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | them if you wish), that you receive source code or can get it if you 29 | want it, that you can change the software or use pieces of it in new 30 | free programs, and that you know you can do these things. 31 | 32 | To protect your rights, we need to prevent others from denying you 33 | these rights or asking you to surrender the rights. Therefore, you 34 | have certain responsibilities if you distribute copies of the 35 | software, or if you modify it: responsibilities to respect the freedom 36 | of others. 37 | 38 | For example, if you distribute copies of such a program, whether 39 | gratis or for a fee, you must pass on to the recipients the same 40 | freedoms that you received. You must make sure that they, too, receive 41 | or can get the source code. And you must show them these terms so they 42 | know their rights. 43 | 44 | Developers that use the GNU GPL protect your rights with two steps: 45 | (1) assert copyright on the software, and (2) offer you this License 46 | giving you legal permission to copy, distribute and/or modify it. 47 | 48 | For the developers' and authors' protection, the GPL clearly explains 49 | that there is no warranty for this free software. For both users' and 50 | authors' sake, the GPL requires that modified versions be marked as 51 | changed, so that their problems will not be attributed erroneously to 52 | authors of previous versions. 53 | 54 | Some devices are designed to deny users access to install or run 55 | modified versions of the software inside them, although the 56 | manufacturer can do so. This is fundamentally incompatible with the 57 | aim of protecting users' freedom to change the software. The 58 | systematic pattern of such abuse occurs in the area of products for 59 | individuals to use, which is precisely where it is most unacceptable. 60 | Therefore, we have designed this version of the GPL to prohibit the 61 | practice for those products. If such problems arise substantially in 62 | other domains, we stand ready to extend this provision to those 63 | domains in future versions of the GPL, as needed to protect the 64 | freedom of users. 65 | 66 | Finally, every program is threatened constantly by software patents. 67 | States should not allow patents to restrict development and use of 68 | software on general-purpose computers, but in those that do, we wish 69 | to avoid the special danger that patents applied to a free program 70 | could make it effectively proprietary. To prevent this, the GPL 71 | assures that patents cannot be used to render the program non-free. 72 | 73 | The precise terms and conditions for copying, distribution and 74 | modification follow. 75 | 76 | ## TERMS AND CONDITIONS 77 | 78 | ### 0. Definitions. 79 | 80 | "This License" refers to version 3 of the GNU General Public License. 81 | 82 | "Copyright" also means copyright-like laws that apply to other kinds 83 | of works, such as semiconductor masks. 84 | 85 | "The Program" refers to any copyrightable work licensed under this 86 | License. Each licensee is addressed as "you". "Licensees" and 87 | "recipients" may be individuals or organizations. 88 | 89 | To "modify" a work means to copy from or adapt all or part of the work 90 | in a fashion requiring copyright permission, other than the making of 91 | an exact copy. The resulting work is called a "modified version" of 92 | the earlier work or a work "based on" the earlier work. 93 | 94 | A "covered work" means either the unmodified Program or a work based 95 | on the Program. 96 | 97 | To "propagate" a work means to do anything with it that, without 98 | permission, would make you directly or secondarily liable for 99 | infringement under applicable copyright law, except executing it on a 100 | computer or modifying a private copy. Propagation includes copying, 101 | distribution (with or without modification), making available to the 102 | public, and in some countries other activities as well. 103 | 104 | To "convey" a work means any kind of propagation that enables other 105 | parties to make or receive copies. Mere interaction with a user 106 | through a computer network, with no transfer of a copy, is not 107 | conveying. 108 | 109 | An interactive user interface displays "Appropriate Legal Notices" to 110 | the extent that it includes a convenient and prominently visible 111 | feature that (1) displays an appropriate copyright notice, and (2) 112 | tells the user that there is no warranty for the work (except to the 113 | extent that warranties are provided), that licensees may convey the 114 | work under this License, and how to view a copy of this License. If 115 | the interface presents a list of user commands or options, such as a 116 | menu, a prominent item in the list meets this criterion. 117 | 118 | ### 1. Source Code. 119 | 120 | The "source code" for a work means the preferred form of the work for 121 | making modifications to it. "Object code" means any non-source form of 122 | a work. 123 | 124 | A "Standard Interface" means an interface that either is an official 125 | standard defined by a recognized standards body, or, in the case of 126 | interfaces specified for a particular programming language, one that 127 | is widely used among developers working in that language. 128 | 129 | The "System Libraries" of an executable work include anything, other 130 | than the work as a whole, that (a) is included in the normal form of 131 | packaging a Major Component, but which is not part of that Major 132 | Component, and (b) serves only to enable use of the work with that 133 | Major Component, or to implement a Standard Interface for which an 134 | implementation is available to the public in source code form. A 135 | "Major Component", in this context, means a major essential component 136 | (kernel, window system, and so on) of the specific operating system 137 | (if any) on which the executable work runs, or a compiler used to 138 | produce the work, or an object code interpreter used to run it. 139 | 140 | The "Corresponding Source" for a work in object code form means all 141 | the source code needed to generate, install, and (for an executable 142 | work) run the object code and to modify the work, including scripts to 143 | control those activities. However, it does not include the work's 144 | System Libraries, or general-purpose tools or generally available free 145 | programs which are used unmodified in performing those activities but 146 | which are not part of the work. For example, Corresponding Source 147 | includes interface definition files associated with source files for 148 | the work, and the source code for shared libraries and dynamically 149 | linked subprograms that the work is specifically designed to require, 150 | such as by intimate data communication or control flow between those 151 | subprograms and other parts of the work. 152 | 153 | The Corresponding Source need not include anything that users can 154 | regenerate automatically from other parts of the Corresponding Source. 155 | 156 | The Corresponding Source for a work in source code form is that same 157 | work. 158 | 159 | ### 2. Basic Permissions. 160 | 161 | All rights granted under this License are granted for the term of 162 | copyright on the Program, and are irrevocable provided the stated 163 | conditions are met. This License explicitly affirms your unlimited 164 | permission to run the unmodified Program. The output from running a 165 | covered work is covered by this License only if the output, given its 166 | content, constitutes a covered work. This License acknowledges your 167 | rights of fair use or other equivalent, as provided by copyright law. 168 | 169 | You may make, run and propagate covered works that you do not convey, 170 | without conditions so long as your license otherwise remains in force. 171 | You may convey covered works to others for the sole purpose of having 172 | them make modifications exclusively for you, or provide you with 173 | facilities for running those works, provided that you comply with the 174 | terms of this License in conveying all material for which you do not 175 | control copyright. Those thus making or running the covered works for 176 | you must do so exclusively on your behalf, under your direction and 177 | control, on terms that prohibit them from making any copies of your 178 | copyrighted material outside their relationship with you. 179 | 180 | Conveying under any other circumstances is permitted solely under the 181 | conditions stated below. Sublicensing is not allowed; section 10 makes 182 | it unnecessary. 183 | 184 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 185 | 186 | No covered work shall be deemed part of an effective technological 187 | measure under any applicable law fulfilling obligations under article 188 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 189 | similar laws prohibiting or restricting circumvention of such 190 | measures. 191 | 192 | When you convey a covered work, you waive any legal power to forbid 193 | circumvention of technological measures to the extent such 194 | circumvention is effected by exercising rights under this License with 195 | respect to the covered work, and you disclaim any intention to limit 196 | operation or modification of the work as a means of enforcing, against 197 | the work's users, your or third parties' legal rights to forbid 198 | circumvention of technological measures. 199 | 200 | ### 4. Conveying Verbatim Copies. 201 | 202 | You may convey verbatim copies of the Program's source code as you 203 | receive it, in any medium, provided that you conspicuously and 204 | appropriately publish on each copy an appropriate copyright notice; 205 | keep intact all notices stating that this License and any 206 | non-permissive terms added in accord with section 7 apply to the code; 207 | keep intact all notices of the absence of any warranty; and give all 208 | recipients a copy of this License along with the Program. 209 | 210 | You may charge any price or no price for each copy that you convey, 211 | and you may offer support or warranty protection for a fee. 212 | 213 | ### 5. Conveying Modified Source Versions. 214 | 215 | You may convey a work based on the Program, or the modifications to 216 | produce it from the Program, in the form of source code under the 217 | terms of section 4, provided that you also meet all of these 218 | conditions: 219 | 220 | - a) The work must carry prominent notices stating that you modified 221 | it, and giving a relevant date. 222 | - b) The work must carry prominent notices stating that it is 223 | released under this License and any conditions added under 224 | section 7. This requirement modifies the requirement in section 4 225 | to "keep intact all notices". 226 | - c) You must license the entire work, as a whole, under this 227 | License to anyone who comes into possession of a copy. This 228 | License will therefore apply, along with any applicable section 7 229 | additional terms, to the whole of the work, and all its parts, 230 | regardless of how they are packaged. This License gives no 231 | permission to license the work in any other way, but it does not 232 | invalidate such permission if you have separately received it. 233 | - d) If the work has interactive user interfaces, each must display 234 | Appropriate Legal Notices; however, if the Program has interactive 235 | interfaces that do not display Appropriate Legal Notices, your 236 | work need not make them do so. 237 | 238 | A compilation of a covered work with other separate and independent 239 | works, which are not by their nature extensions of the covered work, 240 | and which are not combined with it such as to form a larger program, 241 | in or on a volume of a storage or distribution medium, is called an 242 | "aggregate" if the compilation and its resulting copyright are not 243 | used to limit the access or legal rights of the compilation's users 244 | beyond what the individual works permit. Inclusion of a covered work 245 | in an aggregate does not cause this License to apply to the other 246 | parts of the aggregate. 247 | 248 | ### 6. Conveying Non-Source Forms. 249 | 250 | You may convey a covered work in object code form under the terms of 251 | sections 4 and 5, provided that you also convey the machine-readable 252 | Corresponding Source under the terms of this License, in one of these 253 | ways: 254 | 255 | - a) Convey the object code in, or embodied in, a physical product 256 | (including a physical distribution medium), accompanied by the 257 | Corresponding Source fixed on a durable physical medium 258 | customarily used for software interchange. 259 | - b) Convey the object code in, or embodied in, a physical product 260 | (including a physical distribution medium), accompanied by a 261 | written offer, valid for at least three years and valid for as 262 | long as you offer spare parts or customer support for that product 263 | model, to give anyone who possesses the object code either (1) a 264 | copy of the Corresponding Source for all the software in the 265 | product that is covered by this License, on a durable physical 266 | medium customarily used for software interchange, for a price no 267 | more than your reasonable cost of physically performing this 268 | conveying of source, or (2) access to copy the Corresponding 269 | Source from a network server at no charge. 270 | - c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 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 | - e) Convey the object code using peer-to-peer transmission, 288 | provided you inform other peers where the object code and 289 | Corresponding Source of the work are being offered to the general 290 | public at no charge under subsection 6d. 291 | 292 | A separable portion of the object code, whose source code is excluded 293 | from the Corresponding Source as a System Library, need not be 294 | included in conveying the object code work. 295 | 296 | A "User Product" is either (1) a "consumer product", which means any 297 | tangible personal property which is normally used for personal, 298 | family, or household purposes, or (2) anything designed or sold for 299 | incorporation into a dwelling. In determining whether a product is a 300 | consumer product, doubtful cases shall be resolved in favor of 301 | coverage. For a particular product received by a particular user, 302 | "normally used" refers to a typical or common use of that class of 303 | product, regardless of the status of the particular user or of the way 304 | in which the particular user actually uses, or expects or is expected 305 | to use, the product. A product is a consumer product regardless of 306 | whether the product has substantial commercial, industrial or 307 | non-consumer uses, unless such uses represent the only significant 308 | 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 312 | install and execute modified versions of a covered work in that User 313 | Product from a modified version of its Corresponding Source. The 314 | information must suffice to ensure that the continued functioning of 315 | the modified object code is in no case prevented or interfered with 316 | solely because 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 331 | updates for a work that has been modified or installed by the 332 | recipient, or for the User Product in which it has been modified or 333 | installed. Access to a network may be denied when the modification 334 | itself materially and adversely affects the operation of the network 335 | or violates the rules and protocols for communication across the 336 | network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | ### 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders 364 | of that material) supplement the terms of this License with terms: 365 | 366 | - a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 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 | - c) Prohibiting misrepresentation of the origin of that material, 372 | or requiring that modified versions of such material be marked in 373 | reasonable ways as different from the original version; or 374 | - d) Limiting the use for publicity purposes of names of licensors 375 | or authors of the material; or 376 | - e) Declining to grant rights under trademark law for use of some 377 | trade names, trademarks, or service marks; or 378 | - f) Requiring indemnification of licensors and authors of that 379 | material by anyone who conveys the material (or modified versions 380 | of it) with contractual assumptions of liability to the recipient, 381 | for any liability that these contractual assumptions directly 382 | impose on those licensors and authors. 383 | 384 | All other non-permissive additional terms are considered "further 385 | restrictions" within the meaning of section 10. If the Program as you 386 | received it, or any part of it, contains a notice stating that it is 387 | governed by this License along with a term that is a further 388 | restriction, you may remove that term. If a license document contains 389 | a further restriction but permits relicensing or conveying under this 390 | License, you may add to a covered work material governed by the terms 391 | of that license document, provided that the further restriction does 392 | not survive such relicensing or conveying. 393 | 394 | If you add terms to a covered work in accord with this section, you 395 | must place, in the relevant source files, a statement of the 396 | additional terms that apply to those files, or a notice indicating 397 | where to find the applicable terms. 398 | 399 | Additional terms, permissive or non-permissive, may be stated in the 400 | form of a separately written license, or stated as exceptions; the 401 | above requirements apply either way. 402 | 403 | ### 8. Termination. 404 | 405 | You may not propagate or modify a covered work except as expressly 406 | provided under this License. Any attempt otherwise to propagate or 407 | modify it is void, and will automatically terminate your rights under 408 | this License (including any patent licenses granted under the third 409 | paragraph of section 11). 410 | 411 | However, if you cease all violation of this License, then your license 412 | from a particular copyright holder is reinstated (a) provisionally, 413 | unless and until the copyright holder explicitly and finally 414 | terminates your license, and (b) permanently, if the copyright holder 415 | fails to notify you of the violation by some reasonable means prior to 416 | 60 days after the cessation. 417 | 418 | Moreover, your license from a particular copyright holder is 419 | reinstated permanently if the copyright holder notifies you of the 420 | violation by some reasonable means, this is the first time you have 421 | received notice of violation of this License (for any work) from that 422 | copyright holder, and you cure the violation prior to 30 days after 423 | your receipt of the notice. 424 | 425 | Termination of your rights under this section does not terminate the 426 | licenses of parties who have received copies or rights from you under 427 | this License. If your rights have been terminated and not permanently 428 | reinstated, you do not qualify to receive new licenses for the same 429 | material under section 10. 430 | 431 | ### 9. Acceptance Not Required for Having Copies. 432 | 433 | You are not required to accept this License in order to receive or run 434 | a copy of the Program. Ancillary propagation of a covered work 435 | occurring solely as a consequence of using peer-to-peer transmission 436 | to receive a copy likewise does not require acceptance. However, 437 | nothing other than this License grants you permission to propagate or 438 | modify any covered work. These actions infringe copyright if you do 439 | not accept this License. Therefore, by modifying or propagating a 440 | covered work, you indicate your acceptance of this License to do so. 441 | 442 | ### 10. Automatic Licensing of Downstream Recipients. 443 | 444 | Each time you convey a covered work, the recipient automatically 445 | receives a license from the original licensors, to run, modify and 446 | propagate that work, subject to this License. You are not responsible 447 | for enforcing compliance by third parties with this License. 448 | 449 | An "entity transaction" is a transaction transferring control of an 450 | organization, or substantially all assets of one, or subdividing an 451 | organization, or merging organizations. If propagation of a covered 452 | work results from an entity transaction, each party to that 453 | transaction who receives a copy of the work also receives whatever 454 | licenses to the work the party's predecessor in interest had or could 455 | give under the previous paragraph, plus a right to possession of the 456 | Corresponding Source of the work from the predecessor in interest, if 457 | the predecessor has it or can get it with reasonable efforts. 458 | 459 | You may not impose any further restrictions on the exercise of the 460 | rights granted or affirmed under this License. For example, you may 461 | not impose a license fee, royalty, or other charge for exercise of 462 | rights granted under this License, and you may not initiate litigation 463 | (including a cross-claim or counterclaim in a lawsuit) alleging that 464 | any patent claim is infringed by making, using, selling, offering for 465 | sale, or importing the Program or any portion of it. 466 | 467 | ### 11. Patents. 468 | 469 | A "contributor" is a copyright holder who authorizes use under this 470 | License of the Program or a work on which the Program is based. The 471 | work thus licensed is called the contributor's "contributor version". 472 | 473 | A contributor's "essential patent claims" are all patent claims owned 474 | or controlled by the contributor, whether already acquired or 475 | hereafter acquired, that would be infringed by some manner, permitted 476 | by this License, of making, using, or selling its contributor version, 477 | but do not include claims that would be infringed only as a 478 | consequence of further modification of the contributor version. For 479 | purposes of this definition, "control" includes the right to grant 480 | patent sublicenses in a manner consistent with the requirements of 481 | this License. 482 | 483 | Each contributor grants you a non-exclusive, worldwide, royalty-free 484 | patent license under the contributor's essential patent claims, to 485 | make, use, sell, offer for sale, import and otherwise run, modify and 486 | propagate the contents of its contributor version. 487 | 488 | In the following three paragraphs, a "patent license" is any express 489 | agreement or commitment, however denominated, not to enforce a patent 490 | (such as an express permission to practice a patent or covenant not to 491 | sue for patent infringement). To "grant" such a patent license to a 492 | party means to make such an agreement or commitment not to enforce a 493 | patent against the party. 494 | 495 | If you convey a covered work, knowingly relying on a patent license, 496 | and the Corresponding Source of the work is not available for anyone 497 | to copy, free of charge and under the terms of this License, through a 498 | publicly available network server or other readily accessible means, 499 | then you must either (1) cause the Corresponding Source to be so 500 | available, or (2) arrange to deprive yourself of the benefit of the 501 | patent license for this particular work, or (3) arrange, in a manner 502 | consistent with the requirements of this License, to extend the patent 503 | license to downstream recipients. "Knowingly relying" means you have 504 | actual knowledge that, but for the patent license, your conveying the 505 | covered work in a country, or your recipient's use of the covered work 506 | in a country, would infringe one or more identifiable patents in that 507 | country that you have reason to believe are valid. 508 | 509 | If, pursuant to or in connection with a single transaction or 510 | arrangement, you convey, or propagate by procuring conveyance of, a 511 | covered work, and grant a patent license to some of the parties 512 | receiving the covered work authorizing them to use, propagate, modify 513 | or convey a specific copy of the covered work, then the patent license 514 | you grant is automatically extended to all recipients of the covered 515 | work and works based on it. 516 | 517 | A patent license is "discriminatory" if it does not include within the 518 | scope of its coverage, prohibits the exercise of, or is conditioned on 519 | the non-exercise of one or more of the rights that are specifically 520 | granted under this License. You may not convey a covered work if you 521 | are a party to an arrangement with a third party that is in the 522 | business of distributing software, under which you make payment to the 523 | third party based on the extent of your activity of conveying the 524 | work, and under which the third party grants, to any of the parties 525 | who would receive the covered work from you, a discriminatory patent 526 | license (a) in connection with copies of the covered work conveyed by 527 | you (or copies made from those copies), or (b) primarily for and in 528 | connection with specific products or compilations that contain the 529 | covered work, unless you entered into that arrangement, or that patent 530 | license was granted, prior to 28 March 2007. 531 | 532 | Nothing in this License shall be construed as excluding or limiting 533 | any implied license or other defenses to infringement that may 534 | otherwise be available to you under applicable patent law. 535 | 536 | ### 12. No Surrender of Others' Freedom. 537 | 538 | If conditions are imposed on you (whether by court order, agreement or 539 | otherwise) that contradict the conditions of this License, they do not 540 | excuse you from the conditions of this License. If you cannot convey a 541 | covered work so as to satisfy simultaneously your obligations under 542 | this License and any other pertinent obligations, then as a 543 | consequence you may not convey it at all. For example, if you agree to 544 | terms that obligate you to collect a royalty for further conveying 545 | from those to whom you convey the Program, the only way you could 546 | satisfy both those terms and this License would be to refrain entirely 547 | from conveying the Program. 548 | 549 | ### 13. Use with the GNU Affero General Public License. 550 | 551 | Notwithstanding any other provision of this License, you have 552 | permission to link or combine any covered work with a work licensed 553 | under version 3 of the GNU Affero General Public License into a single 554 | combined work, and to convey the resulting work. The terms of this 555 | License will continue to apply to the part which is the covered work, 556 | but the special requirements of the GNU Affero General Public License, 557 | section 13, concerning interaction through a network will apply to the 558 | combination as such. 559 | 560 | ### 14. Revised Versions of this License. 561 | 562 | The Free Software Foundation may publish revised and/or new versions 563 | of the GNU General Public License from time to time. Such new versions 564 | will be similar in spirit to the present version, but may differ in 565 | detail to address new problems or concerns. 566 | 567 | Each version is given a distinguishing version number. If the Program 568 | specifies that a certain numbered version of the GNU General Public 569 | License "or any later version" applies to it, you have the option of 570 | following the terms and conditions either of that numbered version or 571 | of any later version published by the Free Software Foundation. If the 572 | Program does not specify a version number of the GNU General Public 573 | License, you may choose any version ever published by the Free 574 | Software Foundation. 575 | 576 | If the Program specifies that a proxy can decide which future versions 577 | of the GNU General Public License can be used, that proxy's public 578 | statement of acceptance of a version permanently authorizes you to 579 | choose that version for the Program. 580 | 581 | Later license versions may give you additional or different 582 | permissions. However, no additional obligations are imposed on any 583 | author or copyright holder as a result of your choosing to follow a 584 | later version. 585 | 586 | ### 15. Disclaimer of Warranty. 587 | 588 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 589 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 590 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT 591 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT 592 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 593 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 594 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 595 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 596 | CORRECTION. 597 | 598 | ### 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR 602 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 603 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES 604 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT 605 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 606 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM 607 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 608 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 609 | 610 | ### 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | ## How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these 626 | terms. 627 | 628 | To do so, attach the following notices to the program. It is safest to 629 | attach them to the start of each source file to most effectively state 630 | the exclusion of warranty; and each file should have at least the 631 | "copyright" line and a pointer to where the full notice is found. 632 | 633 | 634 | Copyright (C) 635 | 636 | This program is free software: you can redistribute it and/or modify 637 | it under the terms of the GNU General Public License as published by 638 | the Free Software Foundation, either version 3 of the License, or 639 | (at your option) any later version. 640 | 641 | This program is distributed in the hope that it will be useful, 642 | but WITHOUT ANY WARRANTY; without even the implied warranty of 643 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 644 | GNU General Public License for more details. 645 | 646 | You should have received a copy of the GNU General Public License 647 | along with this program. If not, see . 648 | 649 | Also add information on how to contact you by electronic and paper 650 | 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 661 | appropriate parts of the General Public License. Of course, your 662 | program's commands might be different; for a GUI interface, you would 663 | use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or 666 | school, if any, to sign a "copyright disclaimer" for the program, if 667 | necessary. For more information on this, and how to apply and follow 668 | the GNU GPL, see . 669 | 670 | The GNU General Public License does not permit incorporating your 671 | program into proprietary programs. If your program is a subroutine 672 | library, you may consider it more useful to permit linking proprietary 673 | applications with the library. If this is what you want to do, use the 674 | GNU Lesser General Public License instead of this License. But first, 675 | please read . 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Ansible](https://www.ansible.com/) playbook for kubeadm-based [Kubernetes](https://kubernetes.io/) cluster installation on Linux 2 | 3 | ---- 4 | 5 | This Ansible playbook automates the installation and configuration of a Kubernetes cluster on Linux, with a single control plane node and multiple worker nodes, using [the most recent stable Kubernetes release](https://github.com/kubernetes/kubernetes/releases/latest). 6 | We understand that there’s Kubespray, which is much more powerful and allows for a lot of customizations, but this playbook is lightweight and simple. It might be a good option for those looking to set up a quick and easy development and testing environment of Kubernetes on Linux. 7 | 8 | **Suitable Environment:** Development & Testing 9 | 10 | **System Requirements:** Minimum 2 GB RAM & 2 vCPU 11 | 12 | **Supported Platforms:** Baremetal, Virtual Machines, Cloud Instances 13 | 14 | #### Supported Linux distributions: 15 | * RedHat-based ( Fedora, RHEL, Rocky Linux, Almalinux, Oracle Linux ) 16 | * Debian-based ( Debian, Ubuntu ) 17 | * SUSE-based ( OpenSUSE, SLES ) 18 | 19 | #### Prerequisites: 20 | * Please [install Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on the machine where you plan to run the playbook if you haven’t done so already. 21 | * Prepare the cluster nodes by installing any of the above mentioned supported Linux distributions, even with a minimal installation. 22 | * Please ensure that you have DNS set up that resolves all the involved hosts, or update the host files on all hosts with the necessary entries for each involved host. 23 | * Create a common Linux user on all cluster nodes, which will be used for the cluster installation. 24 | * Enable passwordless SSH authentication from the Ansible host to all cluster nodes using the common user created earlier. 25 | * Ensure the common user has passwordless sudo privileges on all cluster nodes. 26 | 27 | #### The main playbook installs and configures the latest stable versions of the following required components. 28 | * Container orchestrator: [kubernetes](https://github.com/kubernetes/kubernetes) 29 | * Container runtime: [containerd](https://github.com/containerd/containerd) 30 | * Low-level container runtime: [runc](https://github.com/opencontainers/runc) ( dependency for containerd ) 31 | * CNI plugin: [calico](https://github.com/projectcalico/calico) 32 | 33 | #### Optional playbooks are available to install the following components once the cluster is ready. 34 | * [csi-driver-nfs](https://github.com/kubernetes-csi/csi-driver-nfs) 35 | * [csi-driver-smb](https://github.com/kubernetes-csi/csi-driver-smb) 36 | * [MetalLB](https://github.com/metallb/metallb) LoadBalancer 37 | 38 | ---- 39 | 40 | ### Step-by-Step Workflow: 41 | 42 | #### Step 1) Copy and execute the below command snippet to extract the tarball for the most recent stable release of this Ansible project. 43 | [![stable release](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/main/playbook_version.json)](https://github.com/Muthukumar-Subramaniam/install-k8s-on-linux/releases/latest) 44 | ``` 45 | curl -sSL https://github.com/Muthukumar-Subramaniam/install-k8s-on-linux/releases/latest/download/inst-k8s-ansible.tar.gz | tar -xzvf - && cd inst-k8s-ansible 46 | ``` 47 | #### Step 2) Update the host-control-plane file with the necessary hostname. 48 | 49 | Screenshot-host-control-plane-file 50 | 51 | #### Step 3) Update the host-workers file with the necessary hostnames. 52 | 53 | Screenshot-host-workers-file 54 | 55 | #### Step 4) Update the pod-network-cidr file with the desired pod network CIDR. 56 | 57 | Screenshot-pod-network-cidr-file 58 | 59 | * Only private IP addresses, as defined in [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) are allowed. 60 | * The deployment is configured to accept CIDR prefixes exclusively within the /16 to /28 range. 61 | * Ensure that the selected CIDR prefix does not conflict with any existing networks in your infrastructure. 62 | * Choose a CIDR prefix that provides sufficient address space for your cluster. 63 | 64 | #### Step 5) Run the setup.py script to prepare the environment for the Ansible playbook. 65 | ``` 66 | ./setup.py 67 | ``` 68 | Screenshot-setup-script-run 69 | 70 | #### Step 6) Run the playbook if the setup.py script completes successfully. 71 | ``` 72 | ./inst-k8s-ansible.yaml 73 | ``` 74 | Expected Outcome: 75 | 76 | Screenshot-end-output-of-playbook-run 77 | 78 | ### Great work! Your cluster is now ready to use. 79 | 80 | #### Optional Step 1) To install CSI NFS Driver for the kubernetes cluster if required. 81 | ``` 82 | ./optional-k8s-csi-nfs-driver.yaml 83 | ``` 84 | Expected Outcome: 85 | 86 | Screenshot-csi-driver-nfs 87 | 88 | #### Optional Step 2) To install CSI SMB Driver for the kubernetes cluster if required. 89 | ``` 90 | ./optional-k8s-csi-smb-driver.yaml 91 | ``` 92 | Expected Outcome: 93 | 94 | Screenshot-csi-driver-smb 95 | 96 | #### Optional Step 3) To install MetalLB loadbalancer for the kubernetes cluster if required. 97 | Note: Please make sure to change the address pool range in the playbook as per your environment and requirement. 98 | 99 | Screenshot-metallb-ip-pool 100 | 101 | ``` 102 | ./optional-install-metallb.yaml 103 | ``` 104 | Expected Outcome: 105 | 106 | Screenshot-metallb 107 | 108 | ### That's all for now! Your trust and engagement means a lot, and we hope you find the playbook useful. 109 | 110 | ### Kindly note: 111 | * This playbook is a useful resource for experimenting with Kubernetes and can be customized to meet your specific requirements. 112 | * The playbook utilizes the GitHub API to fetch the current stable versions of all required software components. 113 | * Compatible with a wide range of Linux distributions. 114 | * Your feedback and contributions are invaluable to the success of this project. 115 | * Please report any bugs, suggest new features, or contribute directly to the codebase. 116 | 117 | ### Have lots of fun! 118 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | We value your feedback regarding security requirements and are committed to incorporating necessary security updates in future releases. 3 | Please continue to share any concerns or issues you encounter, as they help us maintain a secure and reliable project. 4 | Thank you for your understanding and support. 5 | -------------------------------------------------------------------------------- /images/Screenshot-csi-driver-nfs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-csi-driver-nfs.png -------------------------------------------------------------------------------- /images/Screenshot-csi-driver-smb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-csi-driver-smb.png -------------------------------------------------------------------------------- /images/Screenshot-end-output-of-playbook-run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-end-output-of-playbook-run.png -------------------------------------------------------------------------------- /images/Screenshot-host-control-plane-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-host-control-plane-file.png -------------------------------------------------------------------------------- /images/Screenshot-host-workers-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-host-workers-file.png -------------------------------------------------------------------------------- /images/Screenshot-metallb-ip-pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-metallb-ip-pool.png -------------------------------------------------------------------------------- /images/Screenshot-metallb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-metallb.png -------------------------------------------------------------------------------- /images/Screenshot-pod-network-cidr-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-pod-network-cidr-file.png -------------------------------------------------------------------------------- /images/Screenshot-setup-script-run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/images/Screenshot-setup-script-run.png -------------------------------------------------------------------------------- /inst-k8s-ansible.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/inst-k8s-ansible.tar.gz -------------------------------------------------------------------------------- /inst-k8s-ansible/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | interpreter_python=/usr/bin/python3 3 | inventory=./inventory 4 | log_path=./logs-inst-k8s-ansible-play-output.txt 5 | remote_user=muthuks 6 | -------------------------------------------------------------------------------- /inst-k8s-ansible/host-control-plane: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/inst-k8s-ansible/host-control-plane -------------------------------------------------------------------------------- /inst-k8s-ansible/host-workers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/inst-k8s-ansible/host-workers -------------------------------------------------------------------------------- /inst-k8s-ansible/inst-k8s-ansible.yaml: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ansible-playbook 2 | - name: Install and configure the kubernetes cluster on linux nodes 3 | hosts: k8s_cluster_ctrl_plane_node, k8s_cluster_worker_nodes 4 | roles: 5 | - name: Fetch latest version of software components to be installed from GitHub API 6 | role: fetch_latest_version_number 7 | 8 | - name: Prepare all the nodes for k8s cluster installation 9 | role: prepare_all_the_cluster_nodes 10 | 11 | - name: Apply firewalld rules if it is running 12 | role: apply_rules_for_firewalld 13 | 14 | - name: Install and configure k8s cluster on control plane node using kubeadm 15 | role: install_and_configure_the_cluster 16 | when: ( 'k8s_cluster_ctrl_plane_node' in group_names) 17 | 18 | - name: Join worker nodes with the k8s cluster 19 | role: join_worker_nodes_to_the_cluster 20 | when: ( 'k8s_cluster_worker_nodes' in group_names) 21 | 22 | - name: Check k8s cluster Ready status 23 | role: check_cluster_ready_status 24 | when: ( 'k8s_cluster_ctrl_plane_node' in group_names) 25 | 26 | ########################### EOF ########################################## 27 | -------------------------------------------------------------------------------- /inst-k8s-ansible/inventory/ansible_control_host/hosts: -------------------------------------------------------------------------------- 1 | [ansible_control_host] 2 | local-ansible-control-host 3 | -------------------------------------------------------------------------------- /inst-k8s-ansible/inventory/host_vars/local-ansible-control-host.yaml: -------------------------------------------------------------------------------- 1 | ansible_host: "localhost" 2 | ansible_connection: "local" 3 | -------------------------------------------------------------------------------- /inst-k8s-ansible/inventory/k8s_cluster_ctrl_plane_node/hosts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/inst-k8s-ansible/inventory/k8s_cluster_ctrl_plane_node/hosts -------------------------------------------------------------------------------- /inst-k8s-ansible/inventory/k8s_cluster_worker_nodes/hosts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/inst-k8s-ansible/inventory/k8s_cluster_worker_nodes/hosts -------------------------------------------------------------------------------- /inst-k8s-ansible/optional-install-metallb.yaml: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ansible-playbook 2 | ### Optional metallb installation for k8s cluster 3 | ### Run it if required only after the k8s cluster is Ready 4 | 5 | - name: Install and configure MetalLB for k8s cluster 6 | hosts: k8s_cluster_ctrl_plane_node 7 | gather_facts: false 8 | vars: 9 | k8s_metallb_ip_pool_range: "10.160.0.101-10.160.0.150" # Change it as per your environment 10 | roles: 11 | - role: install_and_configure_metallb 12 | 13 | ######################### EOF ############################# 14 | -------------------------------------------------------------------------------- /inst-k8s-ansible/optional-k8s-csi-nfs-driver.yaml: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ansible-playbook 2 | ### Optional CSI NFS Driver for k8s cluster 3 | ### Run it if required only after the k8s cluster is Ready 4 | - name: Install CSI NFS Driver for k8s cluster 5 | hosts: k8s_cluster_ctrl_plane_node 6 | gather_facts: false 7 | roles: 8 | - role: install_k8s_csi_nfs_driver 9 | 10 | ######################### EOF ############################# 11 | -------------------------------------------------------------------------------- /inst-k8s-ansible/optional-k8s-csi-smb-driver.yaml: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ansible-playbook 2 | ### Optional CSI SMB Driver for k8s cluster 3 | ### Run it if required only after the k8s cluster is Ready 4 | - name: Install CSI SMB Driver for k8s cluster 5 | hosts: k8s_cluster_ctrl_plane_node 6 | gather_facts: false 7 | roles: 8 | - role: install_k8s_csi_smb_driver 9 | 10 | ######################### EOF ############################# 11 | -------------------------------------------------------------------------------- /inst-k8s-ansible/pod-network-cidr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muthukumar-Subramaniam/install-k8s-on-linux/c3c87575c116bc4846b13bef5658a5320503cca9/inst-k8s-ansible/pod-network-cidr -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/apply_rules_for_firewalld/tasks/apply_rules.yaml: -------------------------------------------------------------------------------- 1 | - name: Allow Kubernetes related ports for control plane node 2 | become: true 3 | ansible.posix.firewalld: 4 | port: "{{ item }}" 5 | zone: public 6 | permanent: true 7 | immediate: true 8 | state: enabled 9 | loop: 10 | - 6443/tcp # Kubernetes API server 11 | - 2379-2380/tcp # etcd 12 | - 10250/tcp # Kubelet API server 13 | - 10256/tcp # kube-proxy 14 | - 10257/tcp # kube-controller-manager 15 | - 10259/tcp # Kube-scheduler 16 | - 30000-32767/tcp # NodePort range 17 | when: ( 'k8s_cluster_ctrl_plane_node' in group_names) 18 | 19 | - name: Allow Kubernetes related ports for worker nodes 20 | become: true 21 | ansible.posix.firewalld: 22 | port: "{{ item }}" 23 | zone: public 24 | permanent: true 25 | immediate: true 26 | state: enabled 27 | loop: 28 | - 10250/tcp # Kubelet API server 29 | - 10256/tcp # Kube Proxy 30 | - 30000-32767/tcp # NodePort range 31 | when: ( 'k8s_cluster_worker_nodes' in group_names) 32 | 33 | - name: Allow calico related ports in all nodes 34 | become: true 35 | ansible.posix.firewalld: 36 | port: "{{ item }}" 37 | zone: public 38 | permanent: true 39 | immediate: true 40 | state: enabled 41 | loop: 42 | - 179/tcp # BGP port 43 | - 4789/udp # VXLAN port 44 | - 5473/tcp # Calico port for tigera operator agent 45 | - 51820/udp # WireGuard port for Calico 46 | - 51821/udp # Another WireGuard port for Calico 47 | 48 | - name: Allow IP-in-IP encapsulation for Calico (Protocol 4) in all nodes 49 | become: true 50 | ansible.posix.firewalld: 51 | protocol: 4 52 | zone: public 53 | permanent: true 54 | immediate: true 55 | state: enabled 56 | 57 | - name: Fetch k8s cluster's Management Network CIDR 58 | set_fact: 59 | k8s_cluster_management_cidr: "{{ ansible_default_ipv4.network }}/{{ ansible_default_ipv4.prefix }}" 60 | 61 | - name: Add k8s cluster's Cluster-IP CIDR 10.96.0.0/12 to trusted zone 62 | become: true 63 | ansible.posix.firewalld: 64 | source: "10.96.0.0/12" 65 | zone: trusted 66 | permanent: true 67 | immediate: true 68 | state: enabled 69 | 70 | - name: Add k8s cluster's Management Network CIDR ( {{ k8s_cluster_management_cidr }} ) to trusted zone 71 | become: true 72 | ansible.posix.firewalld: 73 | source: "{{ k8s_cluster_management_cidr }}" 74 | zone: trusted 75 | permanent: true 76 | immediate: true 77 | state: enabled 78 | 79 | - name: Add k8s cluster's Pod Network CIDR ( {{ k8s_pod_network_cidr }} ) to trusted zone 80 | become: true 81 | ansible.posix.firewalld: 82 | source: "{{ k8s_pod_network_cidr }}" 83 | zone: trusted 84 | permanent: true 85 | immediate: true 86 | state: enabled 87 | 88 | ############################ EOF ########################### 89 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/apply_rules_for_firewalld/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - name: Check if firewalld is active 2 | become: true 3 | command: systemctl is-active firewalld 4 | register: firewalld_status 5 | changed_when: false 6 | failed_when: false 7 | 8 | - name: Notify if firewalld is not running 9 | debug: 10 | msg: |- 11 | Firewalld is not running. Skipping firewall configuration. 12 | when: firewalld_status.stdout != "active" 13 | 14 | - name: Notify if firewalld is running 15 | debug: 16 | msg: |- 17 | Firewalld is running. Proceeding with the necessary configuration. 18 | when: firewalld_status.stdout == "active" 19 | 20 | - name: Include tasks to apply firewalld rules for Kubernetes and Calico CNI 21 | include_tasks: apply_rules.yaml 22 | when: firewalld_status.stdout == "active" 23 | 24 | ########################## EOF ############################## 25 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/check_cluster_ready_status/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ### Role to check the k8s cluster Ready status 2 | - name: Get the current status of all the cluster nodes 3 | command: kubectl get nodes 4 | register: nodes_status 5 | changed_when: false 6 | 7 | - name: Notify the current status of all the cluster nodes 8 | debug: 9 | msg: |- 10 | {{ nodes_status.stdout_lines }} 11 | 12 | - name: Waiting for all the worker nodes to get Ready (This might take some time) 13 | command: kubectl get nodes 14 | register: number_of_nodes_ready_status 15 | until: number_of_nodes_ready_status.stdout_lines | select('search', 'NotReady') | list | length == 0 16 | retries: 500 17 | delay: 5 18 | changed_when: false 19 | failed_when: false 20 | 21 | - name: Get the list of worker nodes with label details 22 | command: kubectl get nodes --no-headers --show-labels 23 | register: worker_nodes 24 | changed_when: false 25 | 26 | - name: Segregate worker nodes into those with and without the worker role label 27 | set_fact: 28 | labeled_worker_nodes: "{{ worker_nodes.stdout_lines | select('search', 'node-role.kubernetes.io/worker=true') | list }}" 29 | unlabeled_worker_nodes: "{{ worker_nodes.stdout_lines | reject('search', 'control-plane') | reject('search', 'node-role.kubernetes.io/worker=true') | list }}" 30 | 31 | - name: Notify the names of the worker nodes to which the worker role label has been assigned already 32 | debug: 33 | msg: |- 34 | {{ labeled_worker_nodes }} 35 | when: labeled_worker_nodes | length > 0 36 | 37 | - name: Notify the names of the worker nodes to which the worker role label hasn't been assigned yet 38 | debug: 39 | msg: |- 40 | {{ unlabeled_worker_nodes }} 41 | when: unlabeled_worker_nodes | length > 0 42 | 43 | - name: Add worker role label to unlabeled worker nodes 44 | command: kubectl label node "{{ item.split(' ')[0] }}" node-role.kubernetes.io/worker=true 45 | loop: "{{ unlabeled_worker_nodes }}" 46 | when: unlabeled_worker_nodes | length > 0 47 | 48 | - name: Get the status of cluster nodes 49 | command: kubectl get nodes 50 | register: nodes_status 51 | changed_when: false 52 | 53 | - name: All the cluster nodes are Ready! 54 | debug: 55 | msg: |- 56 | {{ nodes_status.stdout_lines }} 57 | 58 | - name: Wait for all the k8s system pods to come online (This might take some time) 59 | command: kubectl get pods -n kube-system --no-headers 60 | register: k8s_pods_status 61 | until: k8s_pods_status.stdout_lines | select('search', '^(\\S+)\\s+(\\d+)/(\\2)\\s+Running') | list | length == k8s_pods_status.stdout_lines | length 62 | retries: 500 63 | delay: 5 64 | changed_when: false 65 | failed_when: false 66 | 67 | - name: Your kubernetes cluster is Ready! 68 | command: kubectl get nodes 69 | register: nodes_status 70 | changed_when: false 71 | 72 | - name: Manage this cluster from {{ k8s_ctrl_plane_node }} with user {{ k8s_user }} 73 | debug: 74 | msg: |- 75 | {{ nodes_status.stdout_lines }} 76 | 77 | ########################### EOF ############################### 78 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/fetch_latest_version_number/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ### Role to Fetch latest version of software components to be installed from GitHub API 2 | - name: Get latest version information of runc 3 | delegate_to: local-ansible-control-host 4 | run_once: true 5 | uri: 6 | url: https://api.github.com/repos/opencontainers/runc/releases/latest 7 | method: GET 8 | status_code: 200 9 | return_content: true 10 | register: runc_release 11 | changed_when: false 12 | 13 | - name: Notify the runc version to be installed 14 | debug: 15 | msg: |- 16 | Latest stable version to be installed of runc is {{ runc_release.json.tag_name }} 17 | delegate_to: local-ansible-control-host 18 | run_once: true 19 | 20 | 21 | - name: Get latest version information of containerd 22 | delegate_to: local-ansible-control-host 23 | run_once: true 24 | uri: 25 | url: https://api.github.com/repos/containerd/containerd/releases/latest 26 | method: GET 27 | status_code: 200 28 | return_content: true 29 | register: containerd_release 30 | changed_when: false 31 | 32 | - name: Notify the containerd version to be installed 33 | debug: 34 | msg: |- 35 | Latest stable version to be installed of containerd is {{ containerd_release.json.tag_name }} 36 | delegate_to: local-ansible-control-host 37 | run_once: true 38 | 39 | 40 | - name: Get latest version information of kubernetes 41 | delegate_to: local-ansible-control-host 42 | run_once: true 43 | uri: 44 | url: https://api.github.com/repos/kubernetes/kubernetes/releases/latest 45 | method: GET 46 | status_code: 200 47 | return_content: true 48 | register: k8s_release 49 | changed_when: false 50 | 51 | - name: Notify the kubernetes version to be installed 52 | debug: 53 | msg: |- 54 | Latest stable version to be installed of kubernetes is {{ k8s_release.json.tag_name }} 55 | delegate_to: local-ansible-control-host 56 | run_once: true 57 | 58 | 59 | - name: Get latest version information of calico CNI 60 | delegate_to: local-ansible-control-host 61 | run_once: true 62 | uri: 63 | url: https://api.github.com/repos/projectcalico/calico/releases/latest 64 | method: GET 65 | status_code: 200 66 | return_content: true 67 | register: calico_release 68 | changed_when: false 69 | 70 | - name: Notify the calico CNI version to be installed 71 | debug: 72 | msg: |- 73 | Latest stable version to be installed of calico CNI is {{ calico_release.json.tag_name }} 74 | delegate_to: local-ansible-control-host 75 | run_once: true 76 | 77 | 78 | - name: Set captured version information as global variables for all nodes 79 | set_fact: 80 | runc_latest_version: "{{ runc_release.json.tag_name }}" 81 | containerd_latest_version: "{{ containerd_release.json.tag_name }}" 82 | k8s_latest_version: "{{ k8s_release.json.tag_name }}" 83 | k8s_version_major_minor: "{{ k8s_release.json.tag_name | regex_replace('.[0-9]+$', '') }}" 84 | calico_latest_version: "{{ calico_release.json.tag_name }}" 85 | 86 | ################################## EOF ############################### 87 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_metallb/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ###Tasks to install and configure metallb for k8s cluster 2 | - name: Check if metallb-system namespace already exist 3 | command: kubectl get namespaces 4 | register: metallb_namespace_status 5 | failed_when: false 6 | changed_when: false 7 | ignore_errors: true 8 | 9 | - set_fact: 10 | metallb_install_status: "{{ 'already_installed' if (metallb_namespace_status.stdout_lines | select('search', 'metallb') | list | length > 0) else 'not_yet_installed' }}" 11 | 12 | - name: Notify if MetalLB is already installed 13 | debug: 14 | msg: |- 15 | MetalLB is already installed. 16 | when: metallb_install_status == 'already_installed' 17 | 18 | - name: Get latest version information of MetalLB from GitHub API 19 | delegate_to: local-ansible-control-host 20 | run_once: true 21 | uri: 22 | url: https://api.github.com/repos/metallb/metallb/releases/latest 23 | return_content: true 24 | register: metallb_release 25 | changed_when: false 26 | when: metallb_install_status == 'not_yet_installed' 27 | 28 | - set_fact: 29 | metallb_latest_version: "{{ metallb_release.json.tag_name }}" 30 | when: metallb_install_status == 'not_yet_installed' 31 | 32 | - name: Notify the version to be installed of MetalLB 33 | debug: 34 | msg: |- 35 | Latest stable version to be installed of MetalLB is {{ metallb_latest_version }} 36 | delegate_to: local-ansible-control-host 37 | run_once: true 38 | when: metallb_install_status == 'not_yet_installed' 39 | 40 | - name: Install MetalLB using manifest from GitHub with kubectl 41 | command: kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/{{ metallb_latest_version }}/config/manifests/metallb-native.yaml 42 | register: metallb_install_logs 43 | when: metallb_install_status == 'not_yet_installed' 44 | 45 | - name: Notify the results from metallb installation 46 | debug: 47 | msg: |- 48 | {{ metallb_install_logs.stdout_lines }} 49 | when: metallb_install_status == 'not_yet_installed' 50 | 51 | - name: Get the status of metallb-system pods being deployed 52 | command: kubectl get pods -n metallb-system --no-headers 53 | register: metallb_pods_logs 54 | changed_when: false 55 | when: metallb_install_status == 'not_yet_installed' 56 | 57 | - name: Notify the status of metallb-system pods being deployed 58 | debug: 59 | msg: |- 60 | {{ metallb_pods_logs.stdout_lines }} 61 | when: metallb_install_status == 'not_yet_installed' 62 | 63 | - name: Waiting for all the metallb-system pods to be Running 64 | command: kubectl get pods -n metallb-system --no-headers 65 | register: metallb_pods_status 66 | until: metallb_pods_status.stdout_lines | select('search', '^(\\S+)\\s+(\\d+)/(\\2)\\s+Running') | list | length == metallb_pods_status.stdout_lines | length 67 | retries: 500 68 | delay: 5 69 | changed_when: false 70 | failed_when: false 71 | when: metallb_install_status == 'not_yet_installed' 72 | 73 | - name: Create MetalLB IPAddressPool and L2Advertisement 74 | template: 75 | src: metallb_config.j2 76 | dest: /tmp/metallb_config.yaml # Temporary file before applying 77 | when: metallb_install_status == 'not_yet_installed' 78 | 79 | - name: Apply MetalLB IPAddressPool and L2Advertisement manifests 80 | command: kubectl apply -f /tmp/metallb_config.yaml 81 | when: metallb_install_status == 'not_yet_installed' 82 | 83 | - name: Get the current status of metallb-system pods 84 | command: kubectl get pods -n metallb-system 85 | register: metallb_pods_logs 86 | changed_when: false 87 | failed_when: false 88 | 89 | - name: Get MetalLB IPAddressPool details 90 | command: kubectl get ipaddresspools.metallb.io -n metallb-system 91 | register: metallb_ip_pool_status 92 | changed_when: false 93 | 94 | - name: Notify MetalLB IPAddressPool details 95 | debug: 96 | msg: |- 97 | {{ metallb_ip_pool_status.stdout_lines }} 98 | 99 | - name: Status of MetalLB pods if already installed 100 | debug: 101 | msg: |- 102 | {{ metallb_pods_logs.stdout_lines }} 103 | when: metallb_install_status == 'already_installed' 104 | 105 | - name: Successfully deployed MetalLB LoadBalancer for the k8s cluster 106 | debug: 107 | msg: |- 108 | {{ metallb_pods_logs.stdout_lines }} 109 | when: metallb_install_status == 'not_yet_installed' 110 | 111 | ############################## EOF ################################ 112 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_metallb/templates/metallb_config.j2: -------------------------------------------------------------------------------- 1 | apiVersion: metallb.io/v1beta1 2 | kind: IPAddressPool 3 | metadata: 4 | name: k8s-metallb-ip-pool 5 | namespace: metallb-system 6 | spec: 7 | addresses: 8 | - {{ k8s_metallb_ip_pool_range }} # Reserve IP range for LoadBalancer services 9 | --- 10 | apiVersion: metallb.io/v1beta1 11 | kind: L2Advertisement 12 | metadata: 13 | name: l2-advertisement 14 | namespace: metallb-system 15 | spec: 16 | ipAddressPools: 17 | - k8s-metallb-ip-pool 18 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_the_cluster/tasks/apply_calico_cni_manifest.yaml: -------------------------------------------------------------------------------- 1 | - name: Gather the list of pods from all namespaces 2 | command: kubectl get pods -A --no-headers 3 | register: list_of_all_pods 4 | failed_when: false 5 | changed_when: false 6 | ignore_errors: true 7 | 8 | - name: Check if Calico CNI manifest has been applied already 9 | set_fact: 10 | calico_cni_manifest: "{{ 'applied_already' if (list_of_all_pods.stdout_lines | select('search', 'calico') | list | length > 0) else 'not_yet_applied' }}" 11 | 12 | - name: Notify if Calico CNI manifest has been applied already 13 | debug: 14 | msg: |- 15 | Calico CNI manifest has been applied already. 16 | when: calico_cni_manifest == 'applied_already' 17 | 18 | - name: Notify if Calico CNI manifest has not been applied yet 19 | debug: 20 | msg: |- 21 | Calico CNI manifest has not been applied yet. Proceeding to apply. 22 | when: calico_cni_manifest == 'not_yet_applied' 23 | 24 | - name: Applying latest calico CNI ( {{ calico_latest_version }} ) manifest from GitHub 25 | command: kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/{{ calico_latest_version }}/manifests/calico.yaml 26 | when: calico_cni_manifest == 'not_yet_applied' 27 | 28 | ############################### EOF ################################### 29 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_the_cluster/tasks/create_kube_config.yaml: -------------------------------------------------------------------------------- 1 | - name: Create directory /home/{{ k8s_user }}/.kube 2 | file: 3 | path: "/home/{{ k8s_user }}/.kube" 4 | state: directory 5 | 6 | - name: Copy /etc/kubernetes/admin.conf to /home/{{ k8s_user }}/.kube/config 7 | become: true 8 | copy: 9 | src: /etc/kubernetes/admin.conf 10 | remote_src: true 11 | dest: "/home/{{ k8s_user }}/.kube/config" 12 | owner: "{{ k8s_user }}" 13 | group: "{{ k8s_user }}" 14 | mode: "0600" 15 | 16 | - name: Add kubectl completion to .bashrc of user {{ k8s_user }} 17 | lineinfile: 18 | path: "/home/{{ k8s_user }}/.bashrc" 19 | regexp: '^source <\(kubectl completion bash\)$' 20 | line: 'source <(kubectl completion bash)' 21 | state: present 22 | 23 | ##################################### EOF ###################################### 24 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_the_cluster/tasks/kubeadm_config_images_pull.yaml: -------------------------------------------------------------------------------- 1 | - name: Get the list of Kubernetes config images 2 | become: true 3 | command: kubeadm config images list 4 | register: kubeadm_images_list 5 | changed_when: false 6 | 7 | - name: Get the list of pulled images by crictl 8 | become: true 9 | command: crictl -r unix:///run/containerd/containerd.sock images 10 | register: crictl_images_list 11 | changed_when: false 12 | 13 | - name: Extract Kubernetes config image names 14 | set_fact: 15 | kubeadm_image_names: "{{ kubeadm_images_list.stdout_lines | map('regex_replace', ':.+', '') | map('regex_replace', '.*\/', '') | list }}" 16 | 17 | - name: Extract names of Kubernetes images pulled by crictl 18 | set_fact: 19 | crictl_image_names: "{{ crictl_images_list.stdout_lines | select('search', 'registry.k8s.io') | map('regex_replace', '^(?:.*\/)?([^ ]+).*$', '\\1') | list }}" 20 | 21 | - name: Find Kubernetes images yet to be pulled 22 | set_fact: 23 | missing_images: "{{ kubeadm_image_names | difference(crictl_image_names) }}" 24 | 25 | - name: Notify if all Kubernetes config images have already been pulled 26 | debug: 27 | msg: |- 28 | All Kubernetes config images have already been pulled. 29 | when: missing_images | length == 0 30 | 31 | - name: Notify if Kubernetes config images have not been pulled yet 32 | debug: 33 | msg: 34 | - "Kubernetes config images have not been pulled yet." 35 | - "Following images are yet to be pulled:" 36 | - "{{ missing_images }}" 37 | when: missing_images | length > 0 38 | 39 | - name: Pulling Kubernetes config images (this might take some time) 40 | become: true 41 | command: kubeadm config images pull 42 | when: missing_images | length > 0 43 | 44 | ####################################### EOF ######################################### 45 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_the_cluster/tasks/kubeadm_init.yaml: -------------------------------------------------------------------------------- 1 | - name: Check if kubeadm init has been performed 2 | stat: 3 | path: /etc/kubernetes/admin.conf 4 | register: check_k8s_admin_conf_file 5 | changed_when: false 6 | 7 | - name: Notify if kubeadm init has been performed already 8 | debug: 9 | msg: |- 10 | kubeadm init has been performed already. 11 | when: check_k8s_admin_conf_file.stat.exists 12 | 13 | - name: Notify if kubeadm init has not been performed yet. 14 | debug: 15 | msg: |- 16 | kubeadm init has not been performed yet. Proceeding with kubeadm init. 17 | when: not check_k8s_admin_conf_file.stat.exists 18 | 19 | - name: Create k8s cluster using kubeadm init with pod network {{ k8s_pod_network_cidr }} 20 | become: true 21 | command: kubeadm init --pod-network-cidr={{ k8s_pod_network_cidr }} 22 | when: not check_k8s_admin_conf_file.stat.exists 23 | 24 | ############################ EOF ################################### 25 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_the_cluster/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | - set_fact: 2 | k8s_ctrl_plane_node: "{{ ansible_host }}" 3 | k8s_user: "{{ ansible_user }}" 4 | 5 | ###Tasks for kubeadm config images pull 6 | - name: Include tasks for kubeadm config images pull 7 | include_tasks: kubeadm_config_images_pull.yaml 8 | 9 | ###Tasks for kubeadm init 10 | - name: Include tasks for kubeadm init 11 | include_tasks: kubeadm_init.yaml 12 | 13 | ###Tasks to create Kubernetes config for the k8s user 14 | - name: Include tasks for creating Kubernetes config for user {{ k8s_user }} 15 | include_tasks: create_kube_config.yaml 16 | 17 | ###Task to check Kube API server's health 18 | - name: Checking Kube API server's health (this might take some time). 19 | command: curl -skL https://localhost:6443/healthz 20 | register: api_server_health_status 21 | until: api_server_health_status.stdout.find("ok") != -1 22 | retries: 500 23 | delay: 5 24 | changed_when: false 25 | 26 | ###Tasks to apply Calico CNI manifest 27 | - name: Include tasks to apply Calico CNI manifest 28 | include_tasks: apply_calico_cni_manifest.yaml 29 | 30 | ###Tasks to check Ready status of control-plane node 31 | - name: Wait for control-plane to get Ready 32 | command: kubectl get nodes --no-headers -l node-role.kubernetes.io/control-plane 33 | register: control_plane_ready_status 34 | retries: 500 35 | until: control_plane_ready_status.stdout_lines | select('search', ' Ready ') | list | length > 0 36 | delay: 5 37 | changed_when: false 38 | failed_when: false 39 | 40 | - name: Get the status of control-plane node 41 | command: kubectl get nodes --no-headers -l node-role.kubernetes.io/control-plane 42 | register: nodes_status 43 | changed_when: false 44 | 45 | - name: Notify the status of control-plane node 46 | debug: 47 | msg: |- 48 | {{ nodes_status.stdout_lines }} 49 | 50 | ###Tasks to create kubeadm token required for joining the worker nodes with the cluster 51 | - name: Create kubeadm token required for joining the worker nodes with the cluster 52 | command: kubeadm token create --print-join-command 53 | register: kubeadm_join_command_register 54 | changed_when: false 55 | 56 | - set_fact: 57 | kubeadm_join_command: "{{ kubeadm_join_command_register.stdout }}" 58 | 59 | ########################### EOF ########################################## 60 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_and_configure_the_cluster/vars/main.yaml: -------------------------------------------------------------------------------- 1 | k8s_pod_network_cidr: "10.8.0.0/16" 2 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_k8s_csi_nfs_driver/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ### Optional csi-nfs-driver for k8s cluster 2 | - name: Check if csi-nfs-driver pods already exist 3 | command: kubectl get pods -n kube-system --no-headers -l "app in (csi-nfs-node, csi-nfs-controller)" 4 | register: csi_nfs_driver_pods_status 5 | failed_when: false 6 | changed_when: false 7 | ignore_errors: true 8 | 9 | - set_fact: 10 | csi_nfs_install_status: "{{ 'already_installed' if (csi_nfs_driver_pods_status.stdout_lines | select('search', 'csi-nfs') | list | length > 0) else 'not_yet_installed' }}" 11 | 12 | - name: Notify if csi-nfs-driver is already installed 13 | debug: 14 | msg: |- 15 | csi-nfs-driver is already installed. 16 | when: csi_nfs_install_status == 'already_installed' 17 | 18 | - name: Get latest version information of csi-nfs-driver from GitHub API 19 | delegate_to: local-ansible-control-host 20 | run_once: true 21 | uri: 22 | url: "https://api.github.com/repos/kubernetes-csi/csi-driver-nfs/releases/latest" 23 | return_content: true 24 | register: csi_driver_nfs_release 25 | changed_when: false 26 | when: csi_nfs_install_status == 'not_yet_installed' 27 | 28 | - set_fact: 29 | csi_driver_nfs_latest_version: "{{ csi_driver_nfs_release.json.tag_name }}" 30 | when: csi_nfs_install_status == 'not_yet_installed' 31 | 32 | - name: Notify the version to be installed of k8s csi-driver-nfs 33 | debug: 34 | msg: |- 35 | Latest stable version to be installed of k8s csi-driver-nfs is {{ csi_driver_nfs_latest_version }} 36 | delegate_to: local-ansible-control-host 37 | run_once: true 38 | when: csi_nfs_install_status == 'not_yet_installed' 39 | 40 | - name: Download the install-driver.sh script for csi-driver-nfs from GitHub 41 | get_url: 42 | url: "https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/{{ csi_driver_nfs_latest_version }}/deploy/install-driver.sh" 43 | dest: "/tmp/install-csi-driver-nfs.sh" 44 | mode: '0755' 45 | when: csi_nfs_install_status == 'not_yet_installed' 46 | 47 | - name: Install csi-nfs-driver 48 | command: /tmp/install-csi-driver-nfs.sh {{ csi_driver_nfs_latest_version }} 49 | register: csi_driver_nfs_install_logs 50 | when: csi_nfs_install_status == 'not_yet_installed' 51 | 52 | - name: Notify the results from csi-nfs-driver installation 53 | debug: 54 | msg: |- 55 | {{ csi_driver_nfs_install_logs.stdout_lines }} 56 | when: csi_nfs_install_status == 'not_yet_installed' 57 | 58 | - name: Gather current status of pods from all namespaces 59 | command: kubectl get pods -A --no-headers 60 | register: list_of_all_pods 61 | failed_when: false 62 | changed_when: false 63 | ignore_errors: true 64 | when: csi_nfs_install_status == 'not_yet_installed' 65 | 66 | - name: Get the status csi-nfs-driver pods being deployed 67 | set_fact: 68 | csi_driver_nfs_pods_logs: "{{ list_of_all_pods.stdout_lines | select('search', 'csi-nfs') | list }}" 69 | when: csi_nfs_install_status == 'not_yet_installed' 70 | 71 | - name: Notify creation of csi-nfs-driver pods 72 | debug: 73 | msg: |- 74 | {{ csi_driver_nfs_pods_logs }} 75 | when: csi_nfs_install_status == 'not_yet_installed' 76 | 77 | - name: Waiting for all the csi-nfs-driver pods to be Ready 78 | command: kubectl get pods -n kube-system --no-headers -l "app in (csi-nfs-node, csi-nfs-controller)" 79 | register: csi_nfs_driver_pods_status 80 | until: csi_nfs_driver_pods_status.stdout_lines | select('search', '^(\\S+)\\s+(\\d+)/(\\2)\\s+Running') | list | length == csi_nfs_driver_pods_status.stdout_lines | length 81 | retries: 500 82 | delay: 5 83 | changed_when: false 84 | failed_when: false 85 | when: csi_nfs_install_status == 'not_yet_installed' 86 | 87 | - name: Get the current status of csi-nfs-driver pods 88 | command: kubectl get pods -n kube-system --no-headers -l "app in (csi-nfs-node, csi-nfs-controller)" 89 | register: csi_nfs_driver_pods_status 90 | changed_when: false 91 | failed_when: false 92 | 93 | - name: Status of csi-nfs-driver pods if already installed 94 | debug: 95 | msg: |- 96 | {{ csi_nfs_driver_pods_status.stdout_lines }} 97 | when: csi_nfs_install_status == 'already_installed' 98 | 99 | - name: Successfully deployed csi-nfs-driver pods for k8s cluster 100 | debug: 101 | msg: |- 102 | {{ csi_nfs_driver_pods_status.stdout_lines }} 103 | when: csi_nfs_install_status == 'not_yet_installed' 104 | 105 | ######################################## EOF ######################################### 106 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/install_k8s_csi_smb_driver/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ### Optional csi-smb-driver for k8s cluster 2 | - name: Check if csi-smb-driver pods already exist 3 | command: kubectl get pods -n kube-system --no-headers -l "app in (csi-smb-node, csi-smb-controller)" 4 | register: csi_smb_driver_pods_status 5 | failed_when: false 6 | changed_when: false 7 | ignore_errors: true 8 | 9 | - set_fact: 10 | csi_smb_install_status: "{{ 'already_installed' if (csi_smb_driver_pods_status.stdout_lines | select('search', 'csi-smb') | list | length > 0) else 'not_yet_installed' }}" 11 | 12 | - name: Notify if csi-smb-driver is already installed 13 | debug: 14 | msg: |- 15 | csi-smb-driver is already installed. 16 | when: csi_smb_install_status == 'already_installed' 17 | 18 | - name: Get latest version information of csi-smb-driver from GitHub API 19 | delegate_to: local-ansible-control-host 20 | run_once: true 21 | uri: 22 | url: "https://api.github.com/repos/kubernetes-csi/csi-driver-smb/releases/latest" 23 | return_content: true 24 | register: csi_driver_smb_release 25 | changed_when: false 26 | when: csi_smb_install_status == 'not_yet_installed' 27 | 28 | - set_fact: 29 | csi_driver_smb_latest_version: "{{ csi_driver_smb_release.json.tag_name }}" 30 | when: csi_smb_install_status == 'not_yet_installed' 31 | 32 | - name: Notify the version to be installed of k8s csi-driver-smb 33 | debug: 34 | msg: |- 35 | Latest stable version to be installed of k8s csi-driver-smb is {{ csi_driver_smb_latest_version }} 36 | delegate_to: local-ansible-control-host 37 | run_once: true 38 | when: csi_smb_install_status == 'not_yet_installed' 39 | 40 | - name: Download the install-driver.sh script for csi-driver-smb from GitHub 41 | get_url: 42 | url: "https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/{{ csi_driver_smb_latest_version }}/deploy/install-driver.sh" 43 | dest: "/tmp/install-csi-driver-smb.sh" 44 | mode: '0755' 45 | when: csi_smb_install_status == 'not_yet_installed' 46 | 47 | - name: Install csi-smb-driver 48 | command: /tmp/install-csi-driver-smb.sh {{ csi_driver_smb_latest_version }} 49 | register: csi_driver_smb_install_logs 50 | when: csi_smb_install_status == 'not_yet_installed' 51 | 52 | - name: Notify the results from csi-smb-driver installation 53 | debug: 54 | msg: |- 55 | {{ csi_driver_smb_install_logs.stdout_lines }} 56 | when: csi_smb_install_status == 'not_yet_installed' 57 | 58 | - name: Gather current status of pods from all namespaces 59 | command: kubectl get pods -A --no-headers 60 | register: list_of_all_pods 61 | failed_when: false 62 | changed_when: false 63 | ignore_errors: true 64 | when: csi_smb_install_status == 'not_yet_installed' 65 | 66 | - name: Get the status csi-smb-driver pods being deployed 67 | set_fact: 68 | csi_driver_smb_pods_logs: "{{ list_of_all_pods.stdout_lines | select('search', 'csi-smb') | list }}" 69 | when: csi_smb_install_status == 'not_yet_installed' 70 | 71 | - name: Notify creation of csi-smb-driver pods 72 | debug: 73 | msg: |- 74 | {{ csi_driver_smb_pods_logs }} 75 | when: csi_smb_install_status == 'not_yet_installed' 76 | 77 | - name: Waiting for all the csi-smb-driver pods to be Ready 78 | command: kubectl get pods -n kube-system --no-headers -l "app in (csi-smb-node, csi-smb-controller)" 79 | register: csi_smb_driver_pods_status 80 | until: csi_smb_driver_pods_status.stdout_lines | select('search', '^(\\S+)\\s+(\\d+)/(\\2)\\s+Running') | list | length == csi_smb_driver_pods_status.stdout_lines | length 81 | retries: 500 82 | delay: 5 83 | changed_when: false 84 | failed_when: false 85 | when: csi_smb_install_status == 'not_yet_installed' 86 | 87 | - name: Get the current status of csi-smb-driver pods 88 | command: kubectl get pods -n kube-system --no-headers -l "app in (csi-smb-node, csi-smb-controller)" 89 | register: csi_smb_driver_pods_status 90 | changed_when: false 91 | failed_when: false 92 | 93 | - name: Status of csi-smb-driver pods if already installed 94 | debug: 95 | msg: |- 96 | {{ csi_smb_driver_pods_status.stdout_lines }} 97 | when: csi_smb_install_status == 'already_installed' 98 | 99 | - name: Successfully deployed csi-smb-driver pods for k8s cluster 100 | debug: 101 | msg: |- 102 | {{ csi_smb_driver_pods_status.stdout_lines }} 103 | when: csi_smb_install_status == 'not_yet_installed' 104 | 105 | ######################################## EOF ######################################### 106 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/join_worker_nodes_to_the_cluster/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ###Role to Register worker nodes with the k8s cluster with kubeadm join command 2 | - name: Check whether the worker node has joined the cluster already 3 | stat: 4 | path: /etc/kubernetes/kubelet.conf 5 | register: check_k8s_kubelet_conf_file 6 | changed_when: false 7 | 8 | - name: Notify about the worker nodes that has joined the cluster already 9 | debug: 10 | msg: |- 11 | The worker node {{ ansible_host }} has joined the cluster already 12 | when: check_k8s_kubelet_conf_file.stat.exists 13 | 14 | - name: Notify about the worker nodes that has not joined the cluster yet 15 | debug: 16 | msg: |- 17 | The worker node {{ ansible_host }} has not joined the cluster yet, Proceeding to join 18 | when: not check_k8s_kubelet_conf_file.stat.exists 19 | 20 | - name: Join the available worker nodes with the cluster 21 | command: "{{ hostvars[groups['k8s_cluster_ctrl_plane_node'][0]]['kubeadm_join_command'] }}" 22 | become: true 23 | register: worker_joined_output 24 | when: not check_k8s_kubelet_conf_file.stat.exists 25 | 26 | - name: Notify join command results from worker nodes that has joined the cluster 27 | debug: 28 | msg: | 29 | {{ worker_joined_output.stdout_lines }} 30 | when: not check_k8s_kubelet_conf_file.stat.exists 31 | 32 | ################################# EOF ###################################### 33 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/debian_tasks.yaml: -------------------------------------------------------------------------------- 1 | - name: Add k8s gpg apt-key ( Debian based systems ) 2 | become: true 3 | apt_key: 4 | keyring: /etc/apt/keyrings/k8s-apt-keyring-{{ k8s_version_major_minor }}.gpg 5 | url: https://pkgs.k8s.io/core:/stable:/{{ k8s_version_major_minor }}/deb/Release.key 6 | state: present 7 | 8 | - name: Add k8s deb repository ( Debian based systems ) 9 | become: true 10 | apt_repository: 11 | filename: k8s-{{ k8s_version_major_minor }} 12 | repo: deb [signed-by=/etc/apt/keyrings/k8s-apt-keyring-{{ k8s_version_major_minor }}.gpg] https://pkgs.k8s.io/core:/stable:/{{ k8s_version_major_minor }}/deb/ / 13 | state: present 14 | update-cache: true 15 | 16 | - name: Install kubelet, kubeadm and kubectl packages ( Debian based systems ) 17 | become: true 18 | apt: 19 | name: 20 | - kubelet 21 | - kubeadm 22 | - kubectl 23 | - bash-completion 24 | state: present 25 | 26 | - name: Lock kubelet, kubeadm and kubectl packages from upgrades ( Debian based systems ) 27 | become: true 28 | dpkg_selections: 29 | name: "{{ item }}" 30 | selection: "hold" 31 | loop: 32 | - kubelet 33 | - kubeadm 34 | - kubectl 35 | 36 | ######################################### EOF ############################################# 37 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/disable_swap.yaml: -------------------------------------------------------------------------------- 1 | - name: Check if swap is enabled 2 | become: true 3 | command: swapon --show 4 | register: swap_status 5 | ignore_errors: yes 6 | changed_when: false 7 | 8 | - name: Disable swap if it is enabled 9 | become: true 10 | command: swapoff -a 11 | when: swap_status.stdout | length > 0 12 | 13 | - name: Remove swap entry from /etc/fstab 14 | become: true 15 | lineinfile: 16 | path: /etc/fstab 17 | state: absent 18 | regexp: '^.*swap.*$' 19 | 20 | - name: Notify that swap has been disabled and removed from fstab 21 | debug: 22 | msg: |- 23 | Swap has been disabled and removed from /etc/fstab. 24 | when: swap_status.stdout | length > 0 25 | 26 | - name: Notify if swap is already disabled 27 | debug: 28 | msg: |- 29 | Swap is already disabled. 30 | when: swap_status.stdout | length == 0 31 | 32 | ######################### EOF ############################## 33 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/install_containerd.yaml: -------------------------------------------------------------------------------- 1 | - name: Download official binary tarball of latest containerd ( {{ containerd_latest_version }} ) to local-ansible-control-host 2 | delegate_to: local-ansible-control-host 3 | run_once: true 4 | get_url: 5 | url: https://github.com/containerd/containerd/releases/download/{{ containerd_latest_version }}/containerd-{{ containerd_latest_version | regex_replace('v', '') }}-linux-amd64.tar.gz 6 | dest: "{{ containerd_temp_binary_tarball }}" 7 | 8 | - name: Copy downloaded containerd binary tarball from local-ansible-control-host to cluster nodes 9 | copy: 10 | src: "{{ containerd_temp_binary_tarball }}" 11 | dest: "{{ containerd_temp_binary_tarball }}" 12 | mode: 755 13 | 14 | - name: Extract containerd bin under /usr/local 15 | become: true 16 | unarchive: 17 | remote_src: true 18 | src: "{{ containerd_temp_binary_tarball }}" 19 | dest: /usr/local 20 | owner: root 21 | group: root 22 | mode: 755 23 | 24 | - name: Create containerd configuration directory /etc/containerd 25 | become: true 26 | file: 27 | path: /etc/containerd 28 | state: directory 29 | mode: 0755 30 | 31 | - name: Create /etc/containerd/config.toml 32 | become: true 33 | file: 34 | path: /etc/containerd/config.toml 35 | state: touch 36 | 37 | - name: Generate containerd config 38 | command: containerd config default 39 | register: containerd_config 40 | changed_when: false 41 | 42 | - name: Write containerd config to /etc/containerd/config.toml 43 | become: true 44 | copy: 45 | content: "{{ containerd_config.stdout }}" 46 | dest: /etc/containerd/config.toml 47 | 48 | - name: Update SystemdCgroup as true in /etc/containerd/config.toml for runc 49 | become: true 50 | lineinfile: 51 | path: /etc/containerd/config.toml 52 | insertafter: '^.*containerd\.runtimes\.runc\.options.*$' 53 | line: ' SystemdCgroup = true' 54 | 55 | - name: Download containerd.service file from GitHub 56 | become: true 57 | get_url: 58 | url: "https://raw.githubusercontent.com/containerd/containerd/main/containerd.service" 59 | dest: /etc/systemd/system/containerd.service 60 | 61 | - name: Reload systemd daemon 62 | become: true 63 | systemd: 64 | name: daemon-reload 65 | 66 | - name: Enable and start containerd.service 67 | become: true 68 | systemd: 69 | name: containerd.service 70 | enabled: yes 71 | state: started 72 | 73 | - name: Verify status of containerd service 74 | command: systemctl is-active containerd 75 | register: containerd_service_status 76 | changed_when: false 77 | 78 | - name: Notify status of containerd service 79 | debug: 80 | msg: |- 81 | status of containerd service is {{ containerd_service_status.stdout_lines }} 82 | 83 | - name: Clean up {{ containerd_temp_binary_tarball }} from local-ansible-control-host 84 | delegate_to: local-ansible-control-host 85 | run_once: true 86 | file: 87 | path: "{{ containerd_temp_binary_tarball }}" 88 | state: absent 89 | 90 | - name: Clean up {{ containerd_temp_binary_tarball }} from all nodes 91 | file: 92 | path: "{{ containerd_temp_binary_tarball }}" 93 | state: absent 94 | 95 | ################################# EOF ####################################### 96 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/install_runc.yaml: -------------------------------------------------------------------------------- 1 | - name: Download latest official runc ( {{ runc_latest_version }} ) binary to local-ansible-control-host 2 | delegate_to: local-ansible-control-host 3 | run_once: true 4 | get_url: 5 | url: "https://github.com/opencontainers/runc/releases/download/{{ runc_latest_version }}/runc.amd64" 6 | dest: "{{ runc_temp_binary }}" 7 | mode: 0755 8 | 9 | - name: Copy downloaded runc binary from local-ansible-control-host to /usr/local/bin/runc of cluster node 10 | become: true 11 | copy: 12 | src: "{{ runc_temp_binary }}" 13 | dest: /usr/local/bin/runc 14 | owner: root 15 | group: root 16 | mode: 755 17 | 18 | - name: Clean up {{ runc_temp_binary }} from local-ansible-control-host 19 | delegate_to: local-ansible-control-host 20 | run_once: true 21 | file: 22 | path: "{{ runc_temp_binary }}" 23 | state: absent 24 | 25 | ########################################### EOF ############################################ 26 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/load_kernel_modules.yaml: -------------------------------------------------------------------------------- 1 | - name: Load the required kernel modules 2 | become: true 3 | modprobe: 4 | name: "{{ item }}" 5 | state: present 6 | loop: 7 | - overlay 8 | - br_netfilter 9 | 10 | - name: Create /etc/modules-load.d/k8s.conf for the above loaded modules to be persistent 11 | become: true 12 | blockinfile: 13 | create: true 14 | path: /etc/modules-load.d/k8s.conf 15 | block: | 16 | overlay 17 | br_netfilter 18 | state: present 19 | 20 | ############################## EOF ################################# 21 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/load_kernel_parameters.yaml: -------------------------------------------------------------------------------- 1 | - name: Load the required kernel parameters 2 | become: true 3 | ansible.posix.sysctl: 4 | name: "{{ item.key }}" 5 | value: "{{ item.value }}" 6 | state: present 7 | reload: yes 8 | loop: 9 | - { key: 'net.ipv4.ip_forward', value: '1' } 10 | - { key: 'net.bridge.bridge-nf-call-iptables', value: '1' } 11 | - { key: 'net.bridge.bridge-nf-call-ip6tables', value: '1' } 12 | 13 | - name: Create /etc/sysctl.d/k8s.conf for above loaded kernel parameters to be persistent 14 | become: true 15 | blockinfile: 16 | create: true 17 | path: /etc/sysctl.d/k8s.conf 18 | block: | 19 | net.ipv4.ip_forward = 1 20 | net.bridge.bridge-nf-call-iptables = 1 21 | net.bridge.bridge-nf-call-ip6tables = 1 22 | state: present 23 | 24 | ##################################### EOF ####################################### 25 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/main.yaml: -------------------------------------------------------------------------------- 1 | ###Tasks to upgrade the system packages 2 | - name: Include tasks to upgrade the system packages 3 | include_tasks: upgrade_os.yaml 4 | 5 | 6 | ###Tasks to disable swap memory 7 | - name: Include tasks to disable swap 8 | include_tasks: disable_swap.yaml 9 | 10 | 11 | ###Tasks to load required kernel modules 12 | - name: Include tasks to load required kernel modules 13 | include_tasks: load_kernel_modules.yaml 14 | 15 | 16 | ###Tasks to load required kernel parameters 17 | - name: Include tasks to load required kernel parameters 18 | include_tasks: load_kernel_parameters.yaml 19 | 20 | 21 | ###Tasks to install runc 22 | - name: Check if runc is already installed 23 | command: runc --version 24 | register: runc_check 25 | ignore_errors: true 26 | failed_when: false 27 | changed_when: false 28 | 29 | - name: Notify about runc installation status 30 | debug: 31 | msg: |- 32 | runc is {{ 'already installed.' if runc_check.rc == 0 else 'not installed. Proceeding with installation.' }} 33 | 34 | - name: Include tasks to download and install runc 35 | include_tasks: install_runc.yaml 36 | when: runc_check.rc != 0 37 | 38 | - name: Check runc version 39 | command: runc --version 40 | register: check_runc_version 41 | changed_when: false 42 | 43 | - name: Notify runc version 44 | debug: 45 | msg: |- 46 | {{ check_runc_version.stdout_lines }} 47 | 48 | 49 | ###Task to install containered 50 | - name: Check if containerd is already installed 51 | command: containerd --version 52 | register: containerd_check 53 | ignore_errors: true 54 | failed_when: false 55 | changed_when: false 56 | 57 | - name: Notify about containerd installation status 58 | debug: 59 | msg: |- 60 | Containerd is {{ 'already installed.' if containerd_check.rc == 0 else 'not installed. Proceeding with installation.' }} 61 | 62 | - name: Include tasks to download and install containerd 63 | include_tasks: install_containerd.yaml 64 | when: containerd_check.rc != 0 65 | 66 | - name: Check containerd version 67 | command: containerd --version 68 | register: check_containerd_version 69 | changed_when: false 70 | 71 | - name: Notify containerd version 72 | debug: 73 | msg: |- 74 | containerd version is {{ check_containerd_version.stdout_lines }} 75 | 76 | ###Task to install kubelet, kubeadm and kubectl packages 77 | - name: Tasks for RedHat based Distributions to install kubelet, kubeadm and kubectl packages 78 | when: ansible_os_family == "RedHat" 79 | include_tasks: redhat_tasks.yaml 80 | 81 | - name: Tasks for Debian based Distributions to install kubelet, kubeadm and kubectl packages 82 | when: ansible_os_family == "Debian" 83 | include_tasks: debian_tasks.yaml 84 | 85 | - name: Tasks for Suse based Distributions to install kubelet, kubeadm and kubectl packages 86 | when: ansible_os_family == "Suse" 87 | include_tasks: suse_tasks.yaml 88 | 89 | 90 | ###Tasks to Enable and start kubelet service 91 | - name: Enable and start kubelet.service 92 | become: true 93 | systemd: 94 | name: kubelet.service 95 | enabled: yes 96 | state: started 97 | 98 | - name: Check kubelet service status 99 | command: systemctl is-enabled kubelet 100 | register: kubelet_service_status 101 | changed_when: false 102 | 103 | - name: Notify if the kubelet service is enabled 104 | debug: 105 | msg: |- 106 | kubelet service is enabled. 107 | when: kubelet_service_status.stdout == 'enabled' 108 | 109 | ################################# EOF ######################################## 110 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/redhat_tasks.yaml: -------------------------------------------------------------------------------- 1 | - name: Add k8s rpm repository ( RedHat based systems ) 2 | become: true 3 | yum_repository: 4 | description: k8s-{{ k8s_version_major_minor }} 5 | name: k8s-{{ k8s_version_major_minor }} 6 | baseurl: https://pkgs.k8s.io/core:/stable:/{{ k8s_version_major_minor }}/rpm/ 7 | gpgcheck: 1 8 | gpgkey: https://pkgs.k8s.io/core:/stable:/{{ k8s_version_major_minor }}/rpm/repodata/repomd.xml.key 9 | enabled: true 10 | exclude: 11 | - kubelet 12 | - kubeadm 13 | - kubectl 14 | state: present 15 | 16 | - name: Install kubelet, kubeadm and kubectl packages ( RedHat based systems ) 17 | become: true 18 | dnf: 19 | update_cache: true 20 | name: 21 | - kubelet 22 | - kubeadm 23 | - kubectl 24 | - bash-completion 25 | disable_excludes: k8s-{{ k8s_version_major_minor }} 26 | state: present 27 | 28 | ################################## EOF #################################### 29 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/suse_tasks.yaml: -------------------------------------------------------------------------------- 1 | - name: Add k8s rpm repository ( Suse based systems ) 2 | become: true 3 | zypper_repository: 4 | description: k8s-{{ k8s_version_major_minor }} 5 | name: k8s-{{ k8s_version_major_minor }} 6 | repo: https://pkgs.k8s.io/core:/stable:/{{ k8s_version_major_minor }}/rpm/ 7 | auto_import_keys: true 8 | enabled: true 9 | state: present 10 | 11 | - name: Install kubelet, kubeadm and kubectl packages ( Suse based systems ) 12 | become: true 13 | zypper: 14 | update_cache: true 15 | name: 16 | - kubelet 17 | - kubeadm 18 | - kubectl 19 | - bash-completion 20 | state: present 21 | 22 | - name: Check package lock status of kubelet, kubeadm and kubectl (SUSE-based systems) 23 | become: true 24 | command: zypper locks 25 | register: k8s_packages_suse_lock_status 26 | failed_when: false 27 | changed_when: false 28 | ignore_errors: true 29 | 30 | - name: Check if kubelet, kubeadm and kubectl packages are locked already (SUSE-based systems) 31 | set_fact: 32 | k8s_packages_locked: "{{ k8s_packages_suse_lock_status.stdout | regex_search('kubeadm|kubectl|kubelet') is not none }}" 33 | 34 | - name: Lock kubelet, kubeadm and kubectl packages from upgrades (SUSE-based systems) 35 | become: true 36 | command: zypper addlock {{ item }} 37 | loop: 38 | - kubelet 39 | - kubeadm 40 | - kubectl 41 | when: not k8s_packages_locked 42 | 43 | ################################## EOF #################################### 44 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/tasks/upgrade_os.yaml: -------------------------------------------------------------------------------- 1 | - name: Upgrade the system packages (RedHat based systems) 2 | become: true 3 | when: ansible_os_family == "RedHat" 4 | dnf: 5 | update_cache: true 6 | name: "*" 7 | state: latest 8 | register: upgrade_result_redhat 9 | 10 | - name: Upgrade the system packages (Debian based systems) 11 | become: true 12 | when: ansible_os_family == "Debian" 13 | apt: 14 | update_cache: true 15 | upgrade: full 16 | register: upgrade_result_debian 17 | 18 | - name: Upgrade the system packages (Suse based systems) 19 | become: true 20 | when: ansible_os_family == "Suse" 21 | zypper: 22 | update_cache: true 23 | name: "*" 24 | state: latest 25 | register: upgrade_result_suse 26 | 27 | - name: Set the upgrade status for RedHat systems 28 | set_fact: 29 | upgrade_status: "{{ upgrade_status | default({}) | combine({inventory_hostname: upgrade_result_redhat.changed | default(false)}) }}" 30 | when: ansible_os_family == "RedHat" 31 | 32 | - name: Set the upgrade status for Debian systems 33 | set_fact: 34 | upgrade_status: "{{ upgrade_status | default({}) | combine({inventory_hostname: upgrade_result_debian.changed | default(false)}) }}" 35 | when: ansible_os_family == "Debian" 36 | 37 | - name: Set the upgrade status for Suse systems 38 | set_fact: 39 | upgrade_status: "{{ upgrade_status | default({}) | combine({inventory_hostname: upgrade_result_suse.changed | default(false)}) }}" 40 | when: ansible_os_family == "Suse" 41 | 42 | # Reboot the systems that are upgraded and wait for them to come back online 43 | - name: Reboot the systems that are upgraded and wait for them to come back online 44 | become: true 45 | reboot: 46 | msg: Reboot initiated by Ansible Control Host 47 | connect_timeout: 10 48 | post_reboot_delay: 60 49 | reboot_command: reboot 50 | reboot_timeout: 600 51 | test_command: whoami && systemctl is-active multi-user.target 52 | when: upgrade_status[inventory_hostname] | default(false) 53 | 54 | ############################# EOF ##################################### 55 | -------------------------------------------------------------------------------- /inst-k8s-ansible/roles/prepare_all_the_cluster_nodes/vars/main.yaml: -------------------------------------------------------------------------------- 1 | containerd_temp_binary_tarball: "/tmp/temp-containerd.tar.gz" 2 | runc_temp_binary: "/tmp/temp-runc" 3 | -------------------------------------------------------------------------------- /inst-k8s-ansible/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import re 5 | import ipaddress 6 | import subprocess 7 | 8 | host_file_cp = "./host-control-plane" 9 | host_file_w = "./host-workers" 10 | pod_network_file = "./pod-network-cidr" 11 | 12 | def fn_print_msg(message): 13 | print(f"\033[34m{message}\033[0m", end='') 14 | 15 | def fn_print_note(message): 16 | print(f"\033[33m{message}\033[0m", end='') 17 | 18 | def fn_print_success(message): 19 | print(f"\033[32m{message}\033[0m", end='') 20 | 21 | def fn_print_fail(message): 22 | print(f"\033[31m{message}\033[0m", end='') 23 | 24 | def fn_msg_setup(): 25 | fn_print_note("Run the ./setup.py script again once the issue is fixed!\n") 26 | 27 | def fn_check_files(file_name): 28 | if not os.path.isfile(file_name): 29 | fn_print_fail(f"\nFile {file_name} is not found.\n") 30 | fn_msg_setup() 31 | exit(1) 32 | elif os.path.getsize(file_name) == 0: 33 | fn_print_fail(f"\nFile {file_name} is empty.\n") 34 | fn_msg_setup() 35 | exit(1) 36 | 37 | # Remove spaces and empty lines 38 | with open(file_name, 'r+') as f: 39 | lines = [line.strip() for line in f if line.strip()] 40 | f.seek(0) 41 | f.writelines(f"{line}\n" for line in lines) 42 | f.truncate() 43 | 44 | fn_print_msg("Check the required files . . . ") 45 | fn_check_files(host_file_cp) 46 | fn_check_files(host_file_w) 47 | fn_check_files(pod_network_file) 48 | fn_print_success("[done]\n") 49 | 50 | fn_print_msg("Check if a single control plane host is provided . . .") 51 | with open(host_file_cp, 'r') as f: 52 | if len(f.readlines()) != 1: 53 | fn_print_fail(f"\nFile {host_file_cp} should only contain exactly one host entry!\n") 54 | fn_msg_setup() 55 | exit(1) 56 | fn_print_success("[done]\n") 57 | 58 | with open(pod_network_file, 'r') as f: 59 | pod_network_cidr = f.read().strip() 60 | 61 | fn_print_msg("Validate the pod network CIDR . . .") 62 | # Check if the CIDR matches the basic pattern 63 | cidr_pattern = r'^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}$' 64 | if not re.match(cidr_pattern, pod_network_cidr): 65 | fn_print_fail(f"\nInvalid pod network CIDR {pod_network_cidr} is provided in the file {pod_network_file}!\n") 66 | fn_msg_setup() 67 | exit(1) 68 | 69 | try: 70 | # Create an IP network object 71 | network = ipaddress.ip_network(pod_network_cidr, strict=False) 72 | 73 | # Check if the network address matches the provided CIDR 74 | if str(network.network_address) != pod_network_cidr.split('/')[0]: 75 | fn_print_fail(f"\nThe network part {pod_network_cidr.split('/')[0]} does not match the prefix length /{network.prefixlen} in the file {pod_network_file}!") 76 | fn_print_fail(f"\nMaybe you are looking for {network.network_address}/{network.prefixlen}!\n") 77 | fn_msg_setup() 78 | exit(1) 79 | 80 | # Additional validations 81 | if not re.search(r'^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)', str(network)): 82 | fn_print_fail(f"\nThe pod network CIDR {pod_network_cidr} provided in the file {pod_network_file} doesn't fall under private address space (RFC 1918)!\n") 83 | fn_msg_setup() 84 | exit(1) 85 | 86 | if str(network.network_address).startswith("10.96."): 87 | fn_print_fail(f"\nThe pod network CIDR {pod_network_cidr} overlaps with Kubernetes default internal Cluster IP network 10.96.0.0/16!\n") 88 | fn_msg_setup() 89 | exit(1) 90 | 91 | cidr_prefix = network.prefixlen 92 | if cidr_prefix < 16 or cidr_prefix > 28: 93 | fn_print_fail(f"\nInvalid pod network CIDR prefix /{cidr_prefix} in the file {pod_network_file}, as a best practice only /16 to /28 is accepted!\n") 94 | fn_msg_setup() 95 | exit(1) 96 | 97 | except ValueError as e: 98 | fn_print_fail(f"\nError validating pod network CIDR: {e}") 99 | fn_msg_setup() 100 | exit(1) 101 | 102 | fn_print_success("[done]\n") 103 | 104 | fn_print_msg(f"Update the variable of pod network CIDR with {pod_network_cidr} . . . ") 105 | with open('./roles/install_and_configure_the_cluster/vars/main.yaml', 'r+') as f: 106 | lines = f.readlines() 107 | f.seek(0) 108 | f.writelines(line for line in lines if 'k8s_pod_network_cidr' not in line) 109 | f.write(f'k8s_pod_network_cidr: "{pod_network_cidr}"\n') 110 | f.truncate() 111 | 112 | fn_print_success("[done]\n") 113 | 114 | fn_print_msg("Update the hosts provided to the inventory . . . ") 115 | with open('./inventory/k8s_cluster_ctrl_plane_node/hosts', 'w') as f: 116 | f.write(f'[k8s_cluster_ctrl_plane_node]\n') 117 | f.write(open(host_file_cp).read()) 118 | 119 | with open('./inventory/k8s_cluster_worker_nodes/hosts', 'w') as f: 120 | f.write(f'[k8s_cluster_worker_nodes]\n') 121 | f.write(open(host_file_w).read()) 122 | 123 | fn_print_success("[done]\n") 124 | 125 | fn_print_note("\n[User to manage the k8s cluster to be created]\n") 126 | while True: 127 | ansible_user = input("Enter the remote username (ansible_user): ") 128 | if ansible_user: 129 | break 130 | 131 | fn_print_msg("\nRun the ansible ping test against the host provided in ./host-control-plane . . .\n") 132 | if subprocess.call(['ansible', '-u', ansible_user, '-m', 'ping', 'k8s_cluster_ctrl_plane_node']) != 0: 133 | fn_print_fail("\nThere are some issues while doing the ansible ping test with the control plane host, Please fix it.\n") 134 | fn_msg_setup() 135 | exit(1) 136 | 137 | fn_print_msg("\nRun the ansible ping test against the hosts provided in ./host-workers . . .\n") 138 | if subprocess.call(['ansible', '-u', ansible_user, '-m', 'ping', 'k8s_cluster_worker_nodes']) != 0: 139 | fn_print_fail("\nThere are some issues while doing the ansible ping test with the worker hosts, Please fix it.\n") 140 | fn_msg_setup() 141 | exit(1) 142 | 143 | fn_print_msg(f"Update remote username (ansible_user) to ansible.cfg . . . ") 144 | with open('./ansible.cfg', 'r+') as f: 145 | lines = f.readlines() 146 | f.seek(0) 147 | f.writelines(line for line in lines if 'remote_user' not in line) 148 | f.write(f'remote_user={ansible_user}\n') 149 | f.truncate() 150 | 151 | fn_print_success("[done]\n") 152 | 153 | fn_print_success("\nAll set, you are good to go!\n") 154 | fn_print_note("You can now run the playbook whenever you are ready!\n") 155 | fn_print_note(f"./inst-k8s-ansible.yaml\n\n") 156 | -------------------------------------------------------------------------------- /inst-k8s-ansible/testing/my-gcp-lab-k8s-setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import re 5 | 6 | # Define the file paths 7 | host_control_plane_path = '../host-control-plane' 8 | host_workers_path = '../host-workers' 9 | pod_network_cidr_path = '../pod-network-cidr' 10 | metallb_config_yaml='../optional-install-metallb.yaml' 11 | 12 | # Write to host-control-plane 13 | with open(host_control_plane_path, 'w') as file: 14 | file.write("k8s-cp1.gcp.local\n") 15 | 16 | # Write to host-workers 17 | with open(host_workers_path, 'w') as file: 18 | file.write("k8s-w1.gcp.local\n") 19 | file.write("k8s-w2.gcp.local\n") 20 | 21 | # Write to pod-network-cidr 22 | with open(pod_network_cidr_path, 'w') as file: 23 | file.write("10.8.0.0/16\n") 24 | 25 | # Update metallb IP range 26 | with open(metallb_config_yaml, "r") as f: 27 | content = f.read() 28 | new_line = ' k8s_metallb_ip_pool_range: "10.160.0.101-10.160.0.150" # Change it as per your environment' 29 | updated_content = re.sub(r'^.*k8s_metallb_ip_pool_range:.*$', new_line, content, flags=re.MULTILINE) 30 | with open(metallb_config_yaml, "w") as f: 31 | f.write(updated_content) 32 | 33 | print("Local setup for k8s cluster installation updated successfully.\nNow you can go back to inst-k8s-ansible directory and run setup.py!") 34 | 35 | os.chdir("..") 36 | 37 | exit 38 | -------------------------------------------------------------------------------- /inst-k8s-ansible/testing/my-local-k8s-setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import re 5 | 6 | # Define the file paths 7 | host_control_plane_path = '../host-control-plane' 8 | host_workers_path = '../host-workers' 9 | pod_network_cidr_path = '../pod-network-cidr' 10 | metallb_config_yaml='../optional-install-metallb.yaml' 11 | 12 | # Write to host-control-plane 13 | with open(host_control_plane_path, 'w') as file: 14 | file.write("k8s-cp1.ms.local\n") 15 | 16 | # Write to host-workers 17 | with open(host_workers_path, 'w') as file: 18 | file.write("k8s-w1.ms.local\n") 19 | file.write("k8s-w2.ms.local\n") 20 | 21 | # Write to pod-network-cidr 22 | with open(pod_network_cidr_path, 'w') as file: 23 | file.write("10.8.0.0/16\n") 24 | 25 | # Update metallb IP range 26 | with open(metallb_config_yaml, "r") as f: 27 | content = f.read() 28 | new_line = ' k8s_metallb_ip_pool_range: "192.168.168.201-192.168.168.255" # Change it as per your environment' 29 | updated_content = re.sub(r'^.*k8s_metallb_ip_pool_range:.*$', new_line, content, flags=re.MULTILINE) 30 | with open(metallb_config_yaml, "w") as f: 31 | f.write(updated_content) 32 | 33 | print("Local setup for k8s cluster installation updated successfully.\nNow you can go back to inst-k8s-ansible directory and run setup.py!") 34 | 35 | os.chdir("..") 36 | 37 | exit 38 | -------------------------------------------------------------------------------- /inst-k8s-ansible/testing/my-local-k8s-test-setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import re 5 | 6 | # Define the file paths 7 | host_control_plane_path = '../host-control-plane' 8 | host_workers_path = '../host-workers' 9 | pod_network_cidr_path = '../pod-network-cidr' 10 | metallb_config_yaml='../optional-install-metallb.yaml' 11 | 12 | # Write to host-control-plane 13 | with open(host_control_plane_path, 'w') as file: 14 | file.write("test-k8s-cp1.ms.local\n") 15 | 16 | # Write to host-workers 17 | with open(host_workers_path, 'w') as file: 18 | file.write("test-k8s-w1.ms.local\n") 19 | file.write("test-k8s-w2.ms.local\n") 20 | 21 | # Write to pod-network-cidr 22 | with open(pod_network_cidr_path, 'w') as file: 23 | file.write("10.8.0.0/16\n") 24 | 25 | # Update metallb IP range 26 | with open(metallb_config_yaml, "r") as f: 27 | content = f.read() 28 | new_line = ' k8s_metallb_ip_pool_range: "192.168.168.201-192.168.168.255" # Change it as per your environment' 29 | updated_content = re.sub(r'^.*k8s_metallb_ip_pool_range:.*$', new_line, content, flags=re.MULTILINE) 30 | with open(metallb_config_yaml, "w") as f: 31 | f.write(updated_content) 32 | 33 | print("Local setup for k8s cluster installation updated successfully.\nNow you can go back to inst-k8s-ansible directory and run setup.py!") 34 | 35 | os.chdir("..") 36 | 37 | exit 38 | -------------------------------------------------------------------------------- /playbook_version.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "label": "stable release", 4 | "message": "v2.2.12", 5 | "color": "brightgreen" 6 | } 7 | -------------------------------------------------------------------------------- /update-tarball.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import tarfile 5 | 6 | # List of files to empty 7 | files_to_empty = [ 8 | "./inst-k8s-ansible/host-control-plane", 9 | "./inst-k8s-ansible/host-workers", 10 | "./inst-k8s-ansible/pod-network-cidr", 11 | "./inst-k8s-ansible/inventory/k8s_cluster_ctrl_plane_node/hosts", 12 | "./inst-k8s-ansible/inventory/k8s_cluster_worker_nodes/hosts", 13 | "./inst-k8s-ansible/logs-inst-k8s-ansible-play-output.txt", 14 | ] 15 | 16 | # Empty the specified files 17 | for file_path in files_to_empty: 18 | if os.path.exists(file_path): 19 | open(file_path, 'w').close() # Clear the contents of the file 20 | print(f'Emptied file: {file_path}') 21 | else: 22 | print(f'File not found: {file_path}') 23 | 24 | # Create a tar.gz archive 25 | tar_file_path = './inst-k8s-ansible.tar.gz' 26 | with tarfile.open(tar_file_path, 'w:gz') as tar: 27 | # Add the directory to the archive 28 | tar.add('./inst-k8s-ansible', arcname=os.path.basename('./inst-k8s-ansible')) 29 | 30 | print(f'Tar file created: {tar_file_path}') 31 | 32 | exit 33 | --------------------------------------------------------------------------------