├── day-4 ├── DescomplicandoKubernetes-Day4.md └── LICENSE ├── day-5 ├── DescomplicandoKubernetes-Day5.md └── LICENSE ├── day-6 ├── DescomplicandoKubernetes-Day6.md └── LICENSE ├── LICENSE ├── day-1 └── LICENSE ├── day-2 ├── LICENSE └── DescomplicandoKubernetes-Day2.md ├── day-3 ├── LICENSE └── DescomplicandoKubernetes-Day3.md └── manutencao-cluster-etcd ├── ETCD - Backup ETCD.md └── LICENSE /day-4/DescomplicandoKubernetes-Day4.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /day-5/DescomplicandoKubernetes-Day5.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /day-6/DescomplicandoKubernetes-Day6.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-1/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-2/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-3/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-4/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-5/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-6/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /manutencao-cluster-etcd/ETCD - Backup ETCD.md: -------------------------------------------------------------------------------- 1 | # O que preciso saber antes de começar? 2 | 3 | ETCD é um dos componentes fundamentais que fazem o kubernetes funcionar. 4 | 5 | # O que é o ETCD? 6 | 7 | Basicamente, o ETCD é um database de armazenamento de chave-valor de alta disponibilidade. 8 | 9 | Em um banco de dados relacional, nós temos colunas e dentro das colunas nós temos o tipo de informação que está sendo armazenada; 10 | 11 | | ![Banco de dados relacional](https://cdn.hswstatic.com/gif/relational-database-chart.jpg)| 12 | |:--:| 13 | | *Banco de dados relacional* | 14 | 15 | Em um banco de dados de chave-valor, quando consultamos e obtemos a chave, é retornado o valor atribuido à aquela chave. 16 | 17 | | ![Banco de dados chave valor](https://upload.wikimedia.org/wikipedia/commons/5/5b/KeyValue.PNG)| 18 | |:--:| 19 | | *Banco de dados chave-valor* | 20 | 21 | Quando consultamos a chave k1, o resultado retornado é o valor : AAA,BBB,CCC 22 | 23 | Quando consultamos a chave k5, o resultado retornado é o valor : 3,ZZZ,5623 24 | 25 | # ETCD no Kubernetes 26 | 27 | No kubernetes, o ETCD é responsável por registrar todo tipo de informação do cluster, como nodes, roles, pods, configs, accounts, secrets, etc. 28 | 29 | Quando o cluster é iniciado pelo ***kubeadm***, um pod do etcd é criado no master node. 30 | 31 | Toda informação que é apresentada ao usuário quando executado "kubect get" são informações armazenadas no ETCD. 32 | 33 | Vejamos se o *pod etcd* foi criado com sucesso com o comando ```kubectl get pods -n kube-system```: 34 | 35 | ``` 36 | NAME READY STATUS RESTARTS AGE 37 | coredns-66bff467f8-pfm2c 1/1 Running 0 8d 38 | coredns-66bff467f8-s8pk4 1/1 Running 0 8d 39 | etcd-docker-01 1/1 Running 0 8d 40 | kube-apiserver-docker-01 1/1 Running 0 8d 41 | kube-controller-manager-docker-01 1/1 Running 0 8d 42 | kube-proxy-mdcgf 1/1 Running 0 8d 43 | kube-proxy-q9cvf 1/1 Running 0 8d 44 | kube-proxy-vf8mq 1/1 Running 0 8d 45 | kube-scheduler-docker-01 1/1 Running 0 8d 46 | weave-net-7dhpf 2/2 Running 0 8d 47 | weave-net-fvttp 2/2 Running 0 8d 48 | weave-net-xl7km 2/2 Running 0 8d 49 | ``` 50 | 51 | # Certificados ETCD 52 | 53 | O ETCD como os demais serviços do Kuberentes utilizam certificados PKI para autenticação sobre TLS, essas chaves são declaradas no manifesto de configuração em: 54 | 55 | kubectl describe pod etcd-docker-01 -n kube-system 56 | 57 | ``` 58 | --cert-file 59 | --key-file 60 | --trusted-ca-file 61 | ``` 62 | 63 | Essas chaves vão ser utilizadas pelos demais componentes do cluster como por exemplo o API Server possam conectar e fazerem alterações. 64 | 65 | kubectl describe pod kube-apiserver -n kube-system 66 | 67 | ``` 68 | --etcd-cafile 69 | --etcd-certfile 70 | --etcd-keyfile 71 | ``` 72 | 73 | Então para toda e qualquer interação com o ETCD vamos precisar utililizar esses certificados para nos autenticar. 74 | 75 | # Interagindo com o ETCD 76 | 77 | Para interagir com o ETCD vamos precisar o etcdctl ou utilizar o próprio container do etcd com o ```kubectl exec``` 78 | 79 | https://github.com/etcd-io/etcd/tree/master/etcdctl 80 | 81 | Baixando a ultima versão do etc: 82 | 83 | Linux: 84 | ``` 85 | ETCD_VER=v3.4.7 86 | 87 | GOOGLE_URL=https://storage.googleapis.com/etcd 88 | GITHUB_URL=https://github.com/etcd-io/etcd/releases/download 89 | DOWNLOAD_URL=${GOOGLE_URL} 90 | 91 | rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz 92 | rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test 93 | 94 | curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz 95 | tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1 96 | rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz 97 | 98 | /tmp/etcd-download-test/etcd --version 99 | /tmp/etcd-download-test/etcdctl version 100 | ``` 101 | https://github.com/etcd-io/etcd/releases 102 | 103 | Como vimos anteriormente vamos precisar utilizar os certificados para nos autenticar, vamos fornecer os dados nos seguistes parâmetros no comando: 104 | ``` 105 | --cacert 106 | --key 107 | --cert 108 | ``` 109 | 110 | Além disso vamos precisar do endpoint, caso esteja no container do ETCD seu endpoint será 127.0.0.1:2379 111 | O sua URL para o endpoint vai estar na flag ```--advertise-client-urls``` nas configurações do ETCD. 112 | 113 | ETCDCTL: 114 | ``` 115 | ETCDCTL_API=3 etcdctl \ 116 | --cacert /var/lib/minikube/certs/etcd/ca.crt \ 117 | --key /var/lib/minikube/certs/etcd/server.key \ 118 | --cert /var/lib/minikube/certs/etcd/server.crt \ 119 | --endpoints $ADVERTISE_URL \ 120 | get / --prefix --keys-only 121 | ``` 122 | 123 | kubectl exec: 124 | ``` 125 | kubectl exec -it etcd-minikube -n kube-system -- etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/var/lib/minikube/certs/etcd/ca.crt --key=/var/lib/minikube/certs/etcd/server.key --cert=/var/lib/minikube/certs/etcd/server.crt get / --prefix --keys-only 126 | ``` 127 | 128 | Output: 129 | ``` 130 | /registry/apiregistration.k8s.io/apiservices/v1. 131 | 132 | /registry/apiregistration.k8s.io/apiservices/v1.admissionregistration.k8s.io 133 | 134 | /registry/apiregistration.k8s.io/apiservices/v1.apiextensions.k8s.io 135 | 136 | /registry/apiregistration.k8s.io/apiservices/v1.apps 137 | 138 | /registry/apiregistration.k8s.io/apiservices/v1.authentication.k8s.io 139 | 140 | /registry/apiregistration.k8s.io/apiservices/v1.authorization.k8s.io 141 | 142 | /registry/apiregistration.k8s.io/apiservices/v1.autoscaling 143 | 144 | /registry/apiregistration.k8s.io/apiservices/v1.batch 145 | 146 | /registry/apiregistration.k8s.io/apiservices/v1.coordination.k8s.io 147 | 148 | /registry/apiregistration.k8s.io/apiservices/v1.networking.k8s.io 149 | 150 | /registry/apiregistration.k8s.io/apiservices/v1.rbac.authorization.k8s.io 151 | 152 | /registry/apiregistration.k8s.io/apiservices/v1.scheduling.k8s.io 153 | 154 | /registry/apiregistration.k8s.io/apiservices/v1.storage.k8s.io 155 | 156 | /registry/apiregistration.k8s.io/apiservices/v1beta1.admissionregistration.k8s.io 157 | 158 | /registry/apiregistration.k8s.io/apiservices/v1beta1.apiextensions.k8s.io 159 | 160 | /registry/apiregistration.k8s.io/apiservices/v1beta1.authentication.k8s.io 161 | 162 | /registry/apiregistration.k8s.io/apiservices/v1beta1.authorization.k8s.io 163 | ``` 164 | 165 | Aqui temos uma parte do conteúdo da  resposta do get no "/" do ETCD, onde listamos todas as chaves do etcd. 166 | 167 | Em um exemplo um pouco mais pratico vamos listar apenas as chaves dos pods no namespace default, o parâmetro para que o output contenha apenas as chaves é ```--keys-only``` 168 | 169 | ``` 170 | kubectl exec -it etcd-minikube -n kube-system -- etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/var/lib/minikube/certs/etcd/ca.crt --key=/var/lib/minikube/certs/etcd/server.key --cert=/var/lib/minikube/certs/etcd/server.crt get /registry/pods/default --prefix=true -keys-only 171 | ``` 172 | 173 | Output: 174 | ``` 175 | /registry/pods/default/nginx 176 | ``` 177 | 178 | Agora vamos ver os valores contidos na chave /registry/pods/default/nginx onde estão as configurações do pod. Vamos remover o parâmetro ```--keys-only``` para que possamos ver os valores da chave. 179 | 180 | ``` 181 | kubectl exec -it etcd-minikube -n kube-system -- etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/var/lib/minikube/certs/etcd/ca.crt --key=/var/lib/minikube/certs/etcd/server.key --cert=/var/lib/minikube/certs/etcd/server.crt get /registry/pods/default/nginx --prefix=true 182 | ``` 183 | 184 | Output: 185 | 186 | ``` 187 | k8s 188 | 189 | v1Pod� 190 | � 191 | nginxdefault"*$a748750e-7582-4db5-ab63-0fab1d0c91542����Z 192 | 193 | runnginxz�� 194 | kubectlUpdatev����FieldsV1:� 195 | �{"f:metadata":{"f:labels":{".":{},"f:run":{}}},"f:spec":{"f:containers":{"k:{\"name\":\"nginx\"}":{".":{},"f:image":{},"f:imagePullPolicy":{},"f:name":{},"f:resources":{},"f:terminationMessagePath":{},"f:terminationMessagePolicy":{}}},"f:dnsPolicy":{},"f:enableServiceLinks":{},"f:restartPolicy":{},"f:schedulerName":{},"f:securityContext":{},"f:terminationGracePeriodSeconds":{}}}�� 196 | kubeletUpdatev����FieldsV1:� 197 | �{"f:status":{"f:conditions":{"k:{\"type\":\"ContainersReady\"}":{".":{},"f:lastProbeTime":{},"f:lastTransitionTime":{},"f:status":{},"f:type":{}},"k:{\"type\":\"Initialized\"}":{".":{},"f:lastProbeTime":{},"f:lastTransitionTime":{},"f:status":{},"f:type":{}},"k:{\"type\":\"Ready\"}":{".":{},"f:lastProbeTime":{},"f:lastTransitionTime":{},"f:status":{},"f:type":{}}},"f:containerStatuses":{},"f:hostIP":{},"f:phase":{},"f:podIP":{},"f:podIPs":{".":{},"k:{\"ip\":\"172.17.0.5\"}":{".":{},"f:ip":{}}},"f:startTime":{}}}� 198 | 1 199 | default-token-657qb2 200 | default-token-657qb�� 201 | nginxnginx*BJJ 202 | default-token-657qb-/var/run/secrets/kubernetes.io/serviceaccount"2j/dev/termination-logrAlways����FileAlways 2 203 | ClusterFirstBdefaultJdefaultminikubeX`hr���default-scheduler�6 204 | node.kubernetes.io/not-readyExists" NoExecute(��8 205 | node.kubernetes.io/unreachableExists" NoExecute(����� 206 | Running# 207 | 208 | InitializedTru����*2 209 | ReadyTru����*2' 210 | ContainersReadyTru����*2$ 211 | 212 | PodScheduledTru����*2"* 213 | 192.168.64.22 214 | 172.17.0.����B� 215 | nginx 216 | 217 | 218 | ���� (2 219 | nginx:latest:_docker-pullable://nginx@sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12BIdocker://4f42eaab397e862432c01d66d44b6e2d395ffae5e5dd16cfb83d906b3fc5022bHJ 220 | BestEffortZb 221 | 222 | 223 | 172.17.0.5" 224 | ``` 225 | 226 | Isso foi um pouco de como podemos interagir diretamente com o ETCD. 227 | 228 | # Backup do ETCD no Kubernetes 229 | 230 | Como sabemos, o ETCD é responsável por armazenar todo tipo de informação sobre o estado do nosso cluster. 231 | 232 | Para realizarmos o backup (snapshot) do ETCD, precisamos utilizar alguns comandos built-in que já vem com o próprio ETCD. 233 | 234 | Esse snapshot, contém todos os dados do estado do cluster. 235 | 236 | Para realizar o snapshot do ETCD sem a autenticação **TLS habilitado**, precisamos executar o seguinte comando. 237 | 238 | ``` 239 | ETCDCTL_API=3 etcdctl \ 240 | --endpoints $ENDPOINT \ 241 | snapshot save snapshotdb 242 | ``` 243 | 244 | ``` 245 | ETCDCTL_API=3 etcdctl \ 246 | --write-out=table \ 247 | snapshot status snapshotdb 248 | 249 | +----------+----------+------------+------------+ 250 | | HASH | REVISION | TOTAL KEYS | TOTAL SIZE | 251 | +----------+----------+------------+------------+ 252 | | fe01cf57 | 10 | 7 | 2.1 MB | 253 | +----------+----------+------------+------------+ 254 | ``` 255 | 256 | 257 | Existem algumas diferenças ao realizar o snapshot do ETCD com o **TLS habilitado** que são obrigatórias: 258 | 259 | Além do --endpoits, precisamos adicionar as chaves e certificados referentes ao TLS que são: 260 | 261 | --cacert - verifica os certificados dos servidores que estão com TLS habilitados; 262 | 263 | --cert - identifica o cliente usando o certificado TLS; 264 | 265 | --endpoints=[127.0.0.1:2379] - novamente, esse é o valor default de onde o ETCD está rodando no nó master com a porta padrão do ETCD, 2379; 266 | 267 | --key - identifica o cliente usando a chave TLS; 268 | 269 | Logo, o comando ficará: 270 | 271 | ``` 272 | ETCDCTL_API=3 etcdctl \ 273 | --cacert /var/lib/minikube/certs/etcd/ca.crt \ 274 | --key /var/lib/minikube/certs/etcd/server.key \ 275 | --cert /var/lib/minikube/certs/etcd/server.crt \ 276 | --endpoints [127.0.0.1:2379] \ 277 | snapshot save snapshotdb 278 | ``` 279 | -------------------------------------------------------------------------------- /manutencao-cluster-etcd/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /day-2/DescomplicandoKubernetes-Day2.md: -------------------------------------------------------------------------------- 1 | # Componentes do K8s 2 | 3 | **O k8s tem os seguintes componentes principais:** 4 | 5 | 6 | 7 | * Master node 8 | * Worker node 9 | * Services 10 | * Controllers 11 | * Pods 12 | * Namespaces e quotas 13 | * Network e policies 14 | * Storage 15 | 16 | **[kube-apiserver](https://kubernetes.io/docs/concepts/overview/components/#kube-apiserver)** é o central de operações do cluster k8s. Todas as chamadas, internas ou externas são tratadas por ele. Ele é o único que conecta no ETCD. 17 | 18 | **[kube-scheduller](https://kubernetes.io/docs/concepts/overview/components/#kube-apiserver)** usa um algoritmo para verificar em qual determinado pod deverá ser hospedado. Ele verifica os recursos disponíveis do node para verificar qual o melhor node para receber aquele pod. 19 | 20 | No **[ETCD](https://kubernetes.io/docs/concepts/overview/components/#etcd)** são armazenados o estado do cluster, rede e outras informações persistentes. 21 | 22 | **[kube-controller-manager](https://kubernetes.io/docs/concepts/overview/components/#cloud-controller-manager)** é o controle principal que interage com o kube-apiserver para determinar o seu estado. Se o estado não bate, o manager ira contactar o controller necessário para checar seu estado desejado. Tem diversos controller em uso como os endpoints, namespace e replication. 23 | 24 | O **[kubelet](https://kubernetes.io/docs/concepts/overview/components/#kubelet)** interage com o Docker instalado no node e garante que os containers que precisavam estar em execução realmente estão. 25 | 26 | O **[kube-proxy](https://kubernetes.io/docs/concepts/overview/components/#kube-proxy)** é o responsável por gerenciar a redes para os containers, é o responsável por expor portas dos containers 27 | 28 | **[Supervisord](http://supervisord.org/)** é o responsável por monitorar e restabelecer, se necessário, o kubelet e o docker. Por esse motivo, quando existe algum problema em relação ao kubelet, como por exemplo o uso do cgroup driver diferente do que está rodando no Docker, você perceberá que ele ficará tentando subir o Kubelet frequentemente. 29 | 30 | **[Pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/)** é a menor unidade que você irá tratar no k8s. Você poderá ter mais de um container por Pod, porém vale lembrar que eles dividirão os mesmos recursos, como por exemplo IP. Uma das boas razões para se ter mais de um container em um Pod é o fato de você ter os logs consolidados.. 31 | 32 | O Pod, por poder possuir diversos containers, muito das vezes se assemelha a uma VM, onde você poderia ter diversos serviços rodando compartilhando o mesmo IP e demais recursos. 33 | 34 | **[Services](https://kubernetes.io/docs/concepts/services-networking/service/)** é uma forma de você expor a comunicação através de um NodePort ou LoadBalancer para distribuir as requisições entre diversos Pods daquele Deployment. Funciona como um balanceador de carga. 35 | 36 | **Container Network Interface** 37 | 38 | Para prover a rede para os containers, o K8s utiliza a especificação do **CNI**, Container Network Interface. 39 | 40 | CNI é uma especificação que reúne alguma bibliotecas para o desenvolvimento de plugins para configuração e gerenciamento de redes para os containers. Ele provê uma comum interface entre as diversas soluções de rede para o k8s. Você encontra diversos plugins para AWS, GCP, Cloud Foundry entre outros. 41 | 42 | [https://github.com/containernetworking/cni](https://github.com/containernetworking/cni) 43 | 44 | Enquanto o CNI define a rede dos pods, ele não te ajuda na comunicação entre os pods de diferentes nodes. 45 | 46 | As características básicas da rede do k8s são: 47 | 48 | 49 | 50 | * Todos os pods conseguem se comunicar entre eles em diferentes nodes 51 | * Todos os nodes pode se comunicar com todos os pods 52 | * Não utilizar NAT 53 | 54 | Todos os IP dos pods e nodes são roteados sem a utilização de NAT. Isso é solucionado com a utilização de algum software que te ajudará na criação de uma rede Overlay. 55 | 56 | Segue alguns: 57 | 58 | 59 | 60 | * [Weave](https://www.weave.works/docs/net/latest/kube-addon/) 61 | * [Flannel](https://github.com/coreos/flannel/blob/master/Documentation/kubernetes.md) 62 | * [Canal](https://github.com/tigera/canal/tree/master/k8s-install) 63 | * [Calico](https://docs.projectcalico.org/latest/introduction/) 64 | * [Romana](http://romana.io/) 65 | * [Nuage](https://github.com/nuagenetworks/nuage-kubernetes/blob/v5.1.1-1/docs/kubernetes-1-installation.rst) 66 | * [Contiv](http://contiv.github.io/) 67 | 68 | [https://kubernetes.io/docs/concepts/cluster-administration/addons/](https://kubernetes.io/docs/concepts/cluster-administration/addons/) 69 | 70 | 71 | 72 | # Services 73 | 74 | 75 | ## Criando um service ClusterIP 76 | 77 | 78 | ``` 79 | # kubectl create -f meu_primeiro.yaml 80 | pod/nginx created 81 | ``` 82 | 83 | ``` 84 | # kubectl expose pod nginx 85 | service/nginx exposed 86 | ``` 87 | 88 | ``` 89 | # kubectl get svc 90 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 91 | kubernetes ClusterIP 10.96.0.1 443/TCP 25m 92 | nginx ClusterIP 10.104.209.243 80/TCP 7m15s 93 | ``` 94 | 95 | ``` 96 | # curl 10.104.209.243 97 | ... 98 | Welcome to nginx! 99 | ... 100 | ``` 101 | 102 | ``` 103 | # kubectl logs -f nginx 104 | 10.40.0.0 - - [10/May/2020:17:31:56 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.58.0" "-" 105 | ``` 106 | 107 | ``` 108 | # kubectl delete svc nginx 109 | service "nginx" deleted 110 | ``` 111 | 112 | 113 | Agora vamos criar nosso service ClusterIP, porém vamos criar um yaml com suas definições: 114 | 115 | 116 | ``` 117 | # vim primeiro-service-clusterip.yaml 118 | apiVersion: v1 119 | kind: Service 120 | metadata: 121 | labels: 122 | run: nginx 123 | name: nginx-clusterip 124 | namespace: default 125 | spec: 126 | ports: 127 | - port: 80 128 | protocol: TCP 129 | targetPort: 80 130 | selector: 131 | run: nginx 132 | type: ClusterIP 133 | ``` 134 | 135 | 136 | ``` 137 | # kubectl create -f primeiro-service-clusterip.yaml 138 | service/nginx-clusterip created 139 | ``` 140 | 141 | ``` 142 | # kubectl get services 143 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 144 | kubernetes ClusterIP 10.96.0.1 443/TCP 28m 145 | nginx-clusterip ClusterIP 10.109.70.243 80/TCP 71s 146 | ``` 147 | 148 | ``` 149 | # kubectl describe service nginx 150 | Name: nginx-clusterip 151 | Namespace: default 152 | Labels: run=nginx 153 | Annotations: 154 | Selector: run=nginx 155 | Type: ClusterIP 156 | IP: 10.109.70.243 157 | Port: 80/TCP 158 | TargetPort: 80/TCP 159 | Endpoints: 10.46.0.1:80 160 | Session Affinity: None 161 | Events: 162 | ``` 163 | 164 | ``` 165 | # kubectl delete -f primeiro-service-clusterip.yaml 166 | service "nginx-clusterip" deleted 167 | ``` 168 | 169 | 170 | Agora vamos mudar um detalhe em nosso manifesto, vamos brincar com o nosso sessionaffinity: 171 | 172 | 173 | ``` 174 | # vim primeiro-service-clusterip.yaml 175 | 176 | apiVersion: v1 177 | kind: Service 178 | metadata: 179 | labels: 180 | run: nginx 181 | name: nginx-clusterip 182 | namespace: default 183 | spec: 184 | ports: 185 | - port: 80 186 | protocol: TCP 187 | targetPort: 80 188 | selector: 189 | run: nginx 190 | sessionAffinity: ClientIP 191 | type: ClusterIP 192 | ``` 193 | 194 | ``` 195 | # kubectl create -f primeiro-service-clusterip.yaml 196 | service/nginx-clusterip created 197 | ``` 198 | 199 | ``` 200 | # kubectl get services 201 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 202 | kubernetes ClusterIP 10.96.0.1 443/TCP 29m 203 | nginx-clusterip ClusterIP 10.96.44.114 80/TCP 7s 204 | ``` 205 | 206 | ``` 207 | # kubectl describe service nginx 208 | Name: nginx-clusterip 209 | Namespace: default 210 | Labels: run=nginx 211 | Annotations: 212 | Selector: run=nginx 213 | Type: ClusterIP 214 | IP: 10.96.44.114 215 | Port: 80/TCP 216 | TargetPort: 80/TCP 217 | Endpoints: 10.46.0.1:80 218 | Session Affinity: ClientIP 219 | Events: 220 | ``` 221 | 222 | 223 | Com isso, agora temos como manter a sessão, ou seja, ele irá manter a conexão com o mesmo pod, respeitando o ip de origem, do cliente. 224 | 225 | Agora podemos remover o service: 226 | 227 | 228 | ``` 229 | # kubectl delete -f primeiro-service-clusterip.yaml 230 | service "nginx-clusterip" deleted 231 | ``` 232 | 233 | 234 | 235 | ## Criando um service NodePort 236 | 237 | 238 | ``` 239 | # kubectl expose pods nginx --type=NodePort 240 | service/nginx exposed 241 | ``` 242 | 243 | ``` 244 | # kubectl get svc 245 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 246 | kubernetes ClusterIP 10.96.0.1 443/TCP 29m 247 | nginx NodePort 10.101.42.230 80:31858/TCP 5s 248 | ``` 249 | 250 | ``` 251 | # kubectl delete svc nginx 252 | service "nginx" deleted 253 | ``` 254 | 255 | 256 | Agora vamos criar um service NodePort, porém vamos criar um manifesto yaml com suas definições: 257 | 258 | 259 | ``` 260 | # vim primeiro-service-nodeport.yaml 261 | apiVersion: v1 262 | kind: Service 263 | metadata: 264 | labels: 265 | run: nginx 266 | name: nginx-nodeport 267 | namespace: default 268 | spec: 269 | externalTrafficPolicy: Cluster 270 | ports: 271 | - nodePort: 31111 272 | port: 80 273 | protocol: TCP 274 | targetPort: 80 275 | selector: 276 | run: nginx 277 | sessionAffinity: None 278 | type: NodePort 279 | ``` 280 | 281 | ``` 282 | # kubectl create -f primeiro-service-nodeport.yaml 283 | service/nginx-nodeport created 284 | ``` 285 | 286 | ``` 287 | # kubectl get services 288 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 289 | kubernetes ClusterIP 10.96.0.1 443/TCP 30m 290 | nginx-nodeport NodePort 10.102.91.81 80:31111/TCP 7s 291 | ``` 292 | 293 | ``` 294 | # kubectl describe service nginx 295 | Name: nginx-nodeport 296 | Namespace: default 297 | Labels: run=nginx 298 | Annotations: 299 | Selector: run=nginx 300 | Type: NodePort 301 | IP: 10.102.91.81 302 | Port: 80/TCP 303 | TargetPort: 80/TCP 304 | NodePort: 31111/TCP 305 | Endpoints: 10.46.0.1:80 306 | Session Affinity: None 307 | External Traffic Policy: Cluster 308 | Events: 309 | ``` 310 | 311 | ``` 312 | # kubectl delete -f primeiro-service-nodeport.yaml 313 | service "nginx-nodeport" deleted 314 | ``` 315 | 316 | 317 | 318 | ## 319 | 320 | 321 | ## Criando um service LoadBalancer 322 | 323 | 324 | ``` 325 | # kubectl expose pod nginx --type=LoadBalancer 326 | service/nginx exposed 327 | ``` 328 | 329 | ``` 330 | # kubectl get svc 331 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 332 | kubernetes ClusterIP 10.96.0.1 443/TCP 32m 333 | nginx LoadBalancer 10.110.198.89 80:30728/TCP 4s 334 | ``` 335 | 336 | ``` 337 | # kubectl delete svc nginx 338 | service "nginx" deleted 339 | ``` 340 | 341 | 342 | Agora vamos criar service NodePort, porém vamos criar um yaml com suas definições, então: 343 | 344 | 345 | ``` 346 | # vim primeiro-service-loadbalancer.yaml 347 | ``` 348 | 349 | E colocar as definições desse cara: 350 | 351 | ``` 352 | apiVersion: v1 353 | kind: Service 354 | metadata: 355 | labels: 356 | run: nginx 357 | name: nginx-loadbalancer 358 | namespace: default 359 | spec: 360 | externalTrafficPolicy: Cluster 361 | ports: 362 | - nodePort: 31222 363 | port: 80 364 | protocol: TCP 365 | targetPort: 80 366 | selector: 367 | run: nginx 368 | sessionAffinity: None 369 | type: LoadBalancer 370 | ``` 371 | 372 | ``` 373 | # kubectl create -f primeiro-service-loadbalancer.yaml 374 | service/nginx-loadbalancer created 375 | ``` 376 | 377 | ``` 378 | # kubectl get services 379 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 380 | kubernetes ClusterIP 10.96.0.1 443/TCP 33m 381 | nginx-loadbalancer LoadBalancer 10.96.67.165 80:31222/TCP 4s 382 | ``` 383 | 384 | ``` 385 | # kubectl describe service nginx 386 | Name: nginx-loadbalancer 387 | Namespace: default 388 | Labels: run=nginx 389 | Annotations: 390 | Selector: run=nginx 391 | Type: LoadBalancer 392 | IP: 10.96.67.165 393 | Port: 80/TCP 394 | TargetPort: 80/TCP 395 | NodePort: 31222/TCP 396 | Endpoints: 10.46.0.1:80 397 | Session Affinity: None 398 | External Traffic Policy: Cluster 399 | Events: 400 | ``` 401 | 402 | ``` 403 | # kubectl delete -f primeiro-service-loadbalancer.yaml 404 | service "nginx-loadbalancer" deleted 405 | ``` 406 | 407 | 408 | 409 | ## 410 | 411 | 412 | ## EndPoint 413 | 414 | Sempre que criamos um service, automaticamente é criado um endpoint. O endpoint nada mais é do que o IP do pod que o service irá utilizar, por exemplo, quando criamos um service do tipo ClusterIP temos o seu IP, correto? 415 | 416 | Agora, quando batemos nesse IP ele redireciona a conexão para o Pod através desse IP, o EndPoint. 417 | 418 | Para listar os EndPoints criados, execute: 419 | 420 | 421 | ``` 422 | # kubectl get endpoints 423 | NAME ENDPOINTS AGE 424 | kubernetes 10.142.0.5:6443 4d 425 | ``` 426 | 427 | 428 | Vamos verificar esse endpoint com mais detalhes: 429 | 430 | 431 | ``` 432 | # kubectl describe endpoints kubernetes 433 | NAME ENDPOINTS AGE 434 | kubernetes 172.31.17.67:6443 33m 435 | root@elliot-01:~# kubectl describe endpoints kubernetes 436 | Name: kubernetes 437 | Namespace: default 438 | Labels: 439 | Annotations: 440 | Subsets: 441 | Addresses: 172.31.17.67 442 | NotReadyAddresses: 443 | Ports: 444 | Name Port Protocol 445 | ---- ---- -------- 446 | https 6443 TCP 447 | 448 | Events: 449 | ``` 450 | 451 | 452 | Vamos fazer um exemplo, para isso, vamos realizar a criação de um deployment, aumentar o número de replicas para 03 e na sequência um service para que possamos ver com mais detalhes os endpoints que serão criados. 453 | 454 | 455 | ``` 456 | # kubectl create deployment nginx --image=nginx 457 | deployment.apps/nginx created 458 | ``` 459 | 460 | ``` 461 | # kubectl get deployments.apps 462 | NAME READY UP-TO-DATE AVAILABLE AGE 463 | nginx 1/1 1 1 5s 464 | ``` 465 | 466 | ``` 467 | # kubectl scale deployment nginx --replicas=3 468 | deployment.apps/nginx scaled 469 | ``` 470 | 471 | ``` 472 | # kubectl get deployments.apps 473 | NAME READY UP-TO-DATE AVAILABLE AGE 474 | nginx 3/3 3 3 1m5s 475 | ``` 476 | 477 | ``` 478 | # kubectl expose deployment nginx --port=80 479 | service/nginx exposed 480 | ``` 481 | 482 | ``` 483 | # kubectl get svc 484 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 485 | kubernetes ClusterIP 10.96.0.1 443/TCP 40m 486 | nginx ClusterIP 10.98.153.22 80/TCP 6s 487 | ``` 488 | 489 | ``` 490 | # curl 10.98.153.22 491 | ... 492 |

Welcome to nginx!

493 | ... 494 | ``` 495 | 496 | ``` 497 | # kubectl get endpoints 498 | NAME ENDPOINTS AGE 499 | kubernetes 172.31.17.67:6443 44m 500 | nginx 10.32.0.2:80,10.32.0.3:80,10.46.0.2:80 3m31s 501 | ``` 502 | ``` 503 | # kubectl describe endpoints nginx 504 | Name: nginx 505 | Namespace: default 506 | Labels: app=nginx 507 | Annotations: endpoints.kubernetes.io/last-change-trigger-time: 2020-05-10T17:47:05Z 508 | Subsets: 509 | Addresses: 10.32.0.2,10.32.0.3,10.46.0.2 510 | NotReadyAddresses: 511 | Ports: 512 | Name Port Protocol 513 | ---- ---- -------- 514 | 80 TCP 515 | 516 | Events: 517 | ``` 518 | 519 | ``` 520 | # kubectl get endpoints -o yaml 521 | apiVersion: v1 522 | items: 523 | - apiVersion: v1 524 | kind: Endpoints 525 | metadata: 526 | creationTimestamp: "2020-05-10T17:06:12Z" 527 | managedFields: 528 | - apiVersion: v1 529 | fieldsType: FieldsV1 530 | fieldsV1: 531 | f:subsets: {} 532 | manager: kube-apiserver 533 | operation: Update 534 | time: "2020-05-10T17:06:12Z" 535 | name: kubernetes 536 | namespace: default 537 | resourceVersion: "163" 538 | selfLink: /api/v1/namespaces/default/endpoints/kubernetes 539 | uid: 39f1e237-f9cc-4553-a32d-95402ff52f6c 540 | ... 541 | - ip: 10.46.0.2 542 | nodeName: elliot-03 543 | targetRef: 544 | kind: Pod 545 | name: nginx-f89759699-dmt4t 546 | namespace: default 547 | resourceVersion: "6805" 548 | uid: 6a9c4639-78ee-44c6-8eb1-4fd90d308189 549 | ports: 550 | - port: 80 551 | protocol: TCP 552 | kind: List 553 | metadata: 554 | resourceVersion: "" 555 | selfLink: "" 556 | ``` 557 | 558 | ``` 559 | # curl 560 | ... 561 |

Welcome to nginx!

562 | ... 563 | ``` 564 | 565 | ``` 566 | # kubectl delete deployment nginx 567 | deployment.apps "nginx" deleted 568 | ``` 569 | 570 | ``` 571 | # kubectl delete service nginx 572 | service "nginx" deleted 573 | ``` 574 | 575 | 576 | # 577 | 578 | 579 | # Limitando Recursos 580 | 581 | Quando criamos um Pod podemos especificar a quantidade de CPU e Memória (RAM) que pode ser consumida em cada container. Quando algum container contém a configuração de limite de recursos o Scheduler fica responsável por alocar esse container no melhor nó possível de acordo com os recursos disponíveis. 582 | 583 | Podemos configurar dois tipos de recursos, CPU que é especificada em unidades de núcleos e Memória que é especificada em unidades de bytes. 584 | 585 | Vamos criar nosso primeiro Deployment com limite de recursos, para isso vamos subir a imagem de um nginx e copiar o yaml do deployment: 586 | 587 | 588 | ``` 589 | # kubectl create deployment nginx --image=nginx 590 | deployment.apps/nginx created 591 | ``` 592 | 593 | ``` 594 | # kubectl scale deployment nginx --replicas=3 595 | deployment.apps/nginx scaled 596 | ``` 597 | 598 | ``` 599 | # kubectl get deployments 600 | NAME READY UP-TO-DATE AVAILABLE AGE 601 | nginx 3/3 3 3 24s 602 | ``` 603 | 604 | ``` 605 | # kubectl get deployment nginx -o yaml > deployment-limitado.yaml 606 | ``` 607 | 608 | E adicionar as definições de limite: 609 | 610 | ``` 611 | # vim deployment-limitado.yaml 612 | apiVersion: apps/v1 613 | kind: Deployment 614 | metadata: 615 | labels: 616 | app: nginx 617 | name: nginx 618 | namespace: default 619 | spec: 620 | progressDeadlineSeconds: 600 621 | replicas: 3 622 | revisionHistoryLimit: 10 623 | selector: 624 | matchLabels: 625 | app: nginx 626 | strategy: 627 | rollingUpdate: 628 | maxSurge: 25% 629 | maxUnavailable: 25% 630 | type: RollingUpdate 631 | template: 632 | metadata: 633 | creationTimestamp: null 634 | labels: 635 | app: nginx 636 | spec: 637 | containers: 638 | - image: nginx 639 | imagePullPolicy: Always 640 | name: nginx 641 | # Adicione as linhas abaixo 642 | resources: 643 | limits: 644 | memory: "256Mi" 645 | cpu: "200m" 646 | requests: 647 | memory: "128Mi" 648 | cpu: "50m" 649 | terminationMessagePath: /dev/termination-log 650 | terminationMessagePolicy: File 651 | dnsPolicy: ClusterFirst 652 | restartPolicy: Always 653 | schedulerName: default-scheduler 654 | securityContext: {} 655 | terminationGracePeriodSeconds: 30 656 | ``` 657 | 658 | 659 | Agora vamos criar nosso deployment e verificar os recursos: 660 | 661 | 662 | ``` 663 | # kubectl delete deployments.apps nginx 664 | ``` 665 | ``` 666 | # kubectl create -f deployment-limitado.yaml 667 | deployment.apps/nginx created 668 | ``` 669 | 670 | 671 | Vamos acessar um container e testar a configuração. 672 | 673 | 674 | ``` 675 | # kubectl get pod 676 | NAME READY STATUS RESTARTS AGE 677 | nginx 1/1 Running 0 12m 678 | nginx-f89759699-77v8b 1/1 Running 0 117s 679 | nginx-f89759699-ffbgh 1/1 Running 0 117s 680 | nginx-f89759699-vzvlt 1/1 Running 0 2m2s 681 | ``` 682 | 683 | ``` 684 | # kubectl exec -ti nginx-f89759699-77v8b -- /bin/bash 685 | ``` 686 | 687 | 688 | Agora no container, instale e execute o stress para simular a carga em nossos recursos, no caso CPU e memória. 689 | 690 | 691 | ``` 692 | # apt-get update && apt-get install -y stress 693 | ``` 694 | 695 | ``` 696 | # stress --vm 1 --vm-bytes 128M --cpu 1 697 | stress: info: [221] dispatching hogs: 1 cpu, 0 io, 1 vm, 0 hdd 698 | ``` 699 | 700 | 701 | Aqui estamos _stressando_ o container, utilizando 124M de RAM e um core de CPU. Brinque de acordo com os limites que você estabeleceu. 702 | 703 | Quando ultrapassar o limite configurado, você receberá um erro como abaixo, pois ele não conseguirá alocar os recursos: 704 | 705 | 706 | ``` 707 | # stress --vm 1 --vm-bytes 512M --cpu 1 708 | stress: info: [230] dispatching hogs: 1 cpu, 0 io, 1 vm, 0 hdd 709 | stress: FAIL: [230] (415) <-- worker 232 got signal 9 710 | stress: WARN: [230] (417) now reaping child worker processes 711 | stress: FAIL: [230] (451) failed run completed in 0s 712 | ``` 713 | 714 | ``` 715 | # kubectl delete deployment nginx 716 | deployment.extensions "nginx" deleted 717 | ``` 718 | 719 | 720 | 721 | # Namespaces 722 | 723 | No kubernetes temos um cara chamado de Namespaces como já vimos anteriormente, mas o que é um Namespace , nada mais é do que um cluster virtual dentro do próprio cluster físico do Kubernetes. 724 | 725 | Namespaces são uma maneira de dividir recursos de um cluster entre vários ambientes , equipes ou projetos. 726 | 727 | Vamos criar nosso primeiro namespaces: 728 | 729 | 730 | ``` 731 | # kubectl create namespace primeiro-namespace 732 | namespace/primeiro-namespace created 733 | ``` 734 | 735 | 736 | Vamos listar todos os namespaces do kubernetes: 737 | 738 | 739 | ``` 740 | # kubectl get namespaces 741 | NAME STATUS AGE 742 | default Active 55m 743 | kube-node-lease Active 56m 744 | kube-public Active 56m 745 | kube-system Active 56m 746 | primeiro-namespace Active 5s 747 | ``` 748 | 749 | 750 | Pegar mais informações: 751 | 752 | 753 | ``` 754 | # kubectl describe namespace primeiro-namespace 755 | Name: primeiro-namespace 756 | Labels: 757 | Annotations: 758 | Status: Active 759 | 760 | No resource quota. 761 | 762 | No LimitRange resource. 763 | ``` 764 | 765 | 766 | Como podemos ver nosso namespace ainda está cru sem configurações, vamos incrementar esse namespace e colocar limite de recursos, para isso vamos utilizar o LimitRange. 767 | 768 | Vamos criar o manifesto do LimitRange: 769 | 770 | 771 | ``` 772 | # vim limitando-recursos.yaml 773 | 774 | apiVersion: v1 775 | kind: LimitRange 776 | metadata: 777 | name: limitando-recursos 778 | spec: 779 | limits: 780 | - default: 781 | cpu: 1 782 | memory: 100Mi 783 | defaultRequest: 784 | cpu: 0.5 785 | memory: 80Mi 786 | type: Container 787 | ``` 788 | 789 | 790 | Agora vamos adicionar esse LimitRange ao Namespace: 791 | 792 | 793 | ``` 794 | # kubectl create -f limitando-recursos.yaml -n primeiro-namespace 795 | limitrange/limitando-recursos created 796 | ``` 797 | 798 | 799 | Listando o LimitRange 800 | 801 | 802 | ``` 803 | # kubectl get limitranges 804 | No resources found in default namespace. 805 | ``` 806 | 807 | 808 | Opa, não encontramos não é mesmo? mas claro esquecemos de passar nosso namespace na hora de listar: 809 | 810 | 811 | ``` 812 | # kubectl get limitrange -n primeiro-namespace 813 | NAME CREATED AT 814 | limitando-recursos 2020-05-10T18:02:51Z 815 | ``` 816 | 817 | 818 | Ou 819 | 820 | 821 | ``` 822 | # kubectl get limitrange --all-namespaces 823 | NAMESPACE NAME CREATED AT 824 | primeiro-namespace limitando-recursos 2020-05-10T18:02:51Z 825 | ``` 826 | 827 | 828 | Vamos dar um describe no LimitRange: 829 | 830 | 831 | ``` 832 | # kubectl describe limitrange -n primeiro-namespace 833 | Name: limitando-recursos 834 | Namespace: primeiro-namespace 835 | Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio 836 | ---- -------- --- --- --------------- ------------- ----------------------- 837 | Container cpu - - 500m 1 - 838 | Container memory - - 80Mi 100Mi - 839 | ``` 840 | 841 | 842 | Como podemos observar adicionamos limites de memória e cpu para cada container que subir nesse Namespace, se algum container for criado dentro do Namespace sem as configurações de Limitrange o container vai pegar essa configuração default com limite de recursos. 843 | 844 | Vamos criar um pod para verificar se o limite se aplicará. 845 | 846 | 847 | ``` 848 | # vim pod-limitrange.yaml 849 | apiVersion: v1 850 | kind: Pod 851 | metadata: 852 | name: limit-pod 853 | spec: 854 | containers: 855 | - name: meu-container 856 | image: nginx 857 | ``` 858 | 859 | 860 | Agora vamos criar um pod fora do namespace limitado e outro dentro do namespace limitado (primeiro-namespace) e vamos observar os limites de recursos de cada container e como foram aplicados: 861 | 862 | 863 | ``` 864 | # kubectl create -f pod-limitrange.yaml 865 | pod/limit-pod created 866 | ``` 867 | 868 | ``` 869 | # kubectl create -f pod-limitrange.yaml -n primeiro-namespace 870 | pod/limit-pod created 871 | ``` 872 | 873 | 874 | Vamos listar esses pods e na sequência ver mais detalhes : 875 | 876 | 877 | ``` 878 | # kubectl get pods --all-namespaces 879 | NAMESPACE NAME READY STATUS RESTARTS AGE 880 | default limit-pod 1/1 Running 0 10s 881 | primeiro-namespace limit-pod 1/1 Running 0 5s 882 | ``` 883 | 884 | ``` 885 | # kubectl describe pod limit-pod 886 | Name: limit-pod 887 | Namespace: default 888 | Priority: 0 889 | Node: elliot-02/172.31.19.123 890 | Start Time: Sun, 10 May 2020 18:03:52 +0000 891 | Labels: 892 | Annotations: 893 | Status: Running 894 | IP: 10.32.0.4 895 | IPs: 896 | IP: 10.32.0.4 897 | Containers: 898 | meu-container: 899 | Container ID: docker://19850dc935ffa41b1754cb58ab60ec5bb3616bbbe6a958abe1b2575bd26ee73d 900 | Image: nginx 901 | ... 902 | ``` 903 | 904 | ``` 905 | # kubectl describe pod limit-pod -n primeiro-namespace 906 | Name: limit-pod 907 | Namespace: primeiro-namespace 908 | Priority: 0 909 | Node: elliot-03/172.31.24.60 910 | Start Time: Sun, 10 May 2020 18:03:57 +0000 911 | Labels: 912 | Annotations: kubernetes.io/limit-ranger: 913 | LimitRanger plugin set: cpu, memory request for container meu-container; cpu, memory limit for container meu-container 914 | Status: Running 915 | IP: 10.46.0.3 916 | IPs: 917 | IP: 10.46.0.3 918 | Containers: 919 | meu-container: 920 | Container ID: docker://ad3760837d71955df47263a2031d4238da2e94002ce4a0631475d301faf1ddef 921 | Image: nginx 922 | ... 923 | Limits: 924 | cpu: 1 925 | memory: 100Mi 926 | Requests: 927 | cpu: 500m 928 | memory: 80Mi 929 | ``` 930 | 931 | 932 | Como podemos ver o Pod no Namespace primeiro-namespace está com limit de recursos configurados. 933 | 934 | 935 | # 936 | 937 | 938 | # Kubectl taint 939 | 940 | O Taint nada mais é do que adicionar propriedades ao nó do cluster para impedir que os pods sejam alocados em nós inapropriados. 941 | 942 | Por exemplo, todo nó master do cluster é marcado para não receber pods que não sejam de gerenciamento do cluster. 943 | 944 | O nó master está marcado com o taint NoSchedule assim o scheduler do Kubernetes não aloca pods no nó master , e procurar outros nós no cluster sem essa marca. 945 | 946 | 947 | ``` 948 | # kubectl describe node elliot-01 | grep -i taint 949 | Taints: node-role.kubernetes.io/master:NoSchedule 950 | ``` 951 | 952 | 953 | **Vamos testar algumas coisas e permita que o nó master rode outros pods.** 954 | 955 | Primeiro vamos rodar 3 réplicas de nginx : 956 | 957 | 958 | ``` 959 | # kubectl create deployment nginx --image=nginx 960 | deployment.apps/nginx created 961 | ``` 962 | 963 | ``` 964 | # kubectl get deployments.apps 965 | NAME READY UP-TO-DATE AVAILABLE AGE 966 | nginx 1/1 1 1 5s 967 | ``` 968 | 969 | ``` 970 | # kubectl scale deployment nginx --replicas=3 971 | deployment.apps/nginx scaled 972 | ``` 973 | 974 | ``` 975 | # kubectl get deployments.apps 976 | NAME READY UP-TO-DATE AVAILABLE AGE 977 | nginx 3/3 3 3 1m5s 978 | ``` 979 | 980 | ``` 981 | # kubectl get pods -o wide 982 | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 983 | limit-pod 1/1 Running 0 3m44s 10.32.0.4 elliot-02 984 | nginx 1/1 Running 0 25m 10.46.0.1 elliot-03 985 | nginx-85f7fb6b45-9bzwc 1/1 Running 0 6m7s 10.32.0.3 elliot-02 986 | nginx-85f7fb6b45-cbmtr 1/1 Running 0 6m7s 10.46.0.2 elliot-03 987 | nginx-85f7fb6b45-rprz5 1/1 Running 0 6m7s 10.32.0.2 elliot-02 988 | ``` 989 | 990 | 991 | Vamos adicionar a marca NoSchedule aos nós slave também para ver como eles se comportam. 992 | 993 | 994 | ``` 995 | # kubectl taint node elliot-02 key1=value1:NoSchedule 996 | node/elliot-02 tainted 997 | ``` 998 | 999 | ``` 1000 | # kubectl taint node elliot-03 key1=value1:NoSchedule 1001 | node/elliot-03 tainted 1002 | ``` 1003 | 1004 | ``` 1005 | # kubectl describe node elliot-02 | grep -i taint 1006 | Taints: key1=value1:NoSchedule 1007 | ``` 1008 | 1009 | ``` 1010 | # kubectl describe node elliot-03 | grep -i taint 1011 | Taints: key1=value1:NoSchedule 1012 | ``` 1013 | 1014 | 1015 | Agora vamos aumentar a quantidade de réplicas: 1016 | 1017 | 1018 | ``` 1019 | # kubectl scale deployment nginx --replicas=5 1020 | deployment.apps/nginx scaled 1021 | ``` 1022 | 1023 | ``` 1024 | # kubectl get pods -o wide 1025 | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 1026 | limit-pod 1/1 Running 0 5m23s 10.32.0.4 elliot-02 1027 | nginx 1/1 Running 0 27m 10.46.0.1 elliot-03 1028 | nginx-85f7fb6b45-9bzwc 1/1 Running 0 7m46s 10.32.0.3 elliot-02 1029 | nginx-85f7fb6b45-cbmtr 1/1 Running 0 7m46s 10.46.0.2 elliot-03 1030 | nginx-85f7fb6b45-qnhtl 0/1 Pending 0 18s 1031 | nginx-85f7fb6b45-qsvpp 0/1 Pending 0 18s 1032 | nginx-85f7fb6b45-rprz5 1/1 Running 0 7m46s 10.32.0.2 elliot-02 1033 | ``` 1034 | 1035 | 1036 | Como podemos ver , as nova replicas ficaram órfãs esperando aparece um nó com as prioridades adequadas para o Scheduler. 1037 | 1038 | Vamos remover o esse Taint dos nossos nós slave: 1039 | 1040 | 1041 | ``` 1042 | # kubectl taint node elliot-02 key1:NoSchedule- 1043 | node/elliot-02 untainted 1044 | ``` 1045 | 1046 | ``` 1047 | # kubectl taint node elliot-03 key1:NoSchedule- 1048 | node/elliot-03 untainted 1049 | ``` 1050 | 1051 | ``` 1052 | # kubectl get pods -o wide 1053 | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 1054 | limit-pod 1/1 Running 0 6m17s 10.32.0.4 elliot-02 1055 | nginx 1/1 Running 0 27m 10.46.0.1 elliot-03 1056 | nginx-85f7fb6b45-9bzwc 1/1 Running 0 8m40s 10.32.0.3 elliot-02 1057 | nginx-85f7fb6b45-cbmtr 1/1 Running 0 8m40s 10.46.0.2 elliot-03 1058 | nginx-85f7fb6b45-qnhtl 1/1 Running 0 72s 10.46.0.5 elliot-03 1059 | nginx-85f7fb6b45-qsvpp 1/1 Running 0 72s 10.46.0.4 elliot-03 1060 | nginx-85f7fb6b45-rprz5 1/1 Running 0 8m40s 10.32.0.2 elliot-02 1061 | ``` 1062 | 1063 | 1064 | Existem vários tipos de marcas que podemos usar para classificar os nós, vamos testar uma outra chamada NoExecute, que impede o Scheduler de agendar Pods nesses nós. 1065 | 1066 | 1067 | ``` 1068 | # kubectl taint node elliot-02 key1=value1:NoExecute 1069 | node/elliot-02 tainted 1070 | ``` 1071 | 1072 | ``` 1073 | # kubectl taint node elliot-03 key1=value1:NoExecute 1074 | node/elliot-03 tainted 1075 | ``` 1076 | ``` 1077 | # kubectl get pods 1078 | NAME READY STATUS RESTARTS AGE 1079 | nginx-85f7fb6b45-87sq5 0/1 Pending 0 20s 1080 | nginx-85f7fb6b45-8q99g 0/1 Pending 0 20s 1081 | nginx-85f7fb6b45-drmzz 0/1 Pending 0 20s 1082 | nginx-85f7fb6b45-hb4dp 0/1 Pending 0 20s 1083 | nginx-85f7fb6b45-l6zln 0/1 Pending 0 20s 1084 | ``` 1085 | 1086 | 1087 | Como podemos ver todos os Pods estão órfãs. Porque o nó master tem a marca taint NoScheduler default do kubernetes e os nós Slave tem a marca NoExecute. 1088 | 1089 | Vamos diminuir a quantidade de réplicas para ver o que acontece: 1090 | 1091 | 1092 | ``` 1093 | # kubectl scale deployment nginx --replicas=1 1094 | deployment.apps/nginx scaled 1095 | ``` 1096 | 1097 | ``` 1098 | # kubectl get pods 1099 | nginx-85f7fb6b45-drmzz 0/1 Pending 0 43s 1100 | ``` 1101 | 1102 | 1103 | Vamos remover o taint NoExecute do nó slave: 1104 | 1105 | 1106 | ``` 1107 | # kubectl taint node elliot-02 key1:NoExecute- 1108 | node/elliot-02 untainted 1109 | ``` 1110 | 1111 | ``` 1112 | # kubectl taint node elliot-03 key1:NoExecute- 1113 | node/elliot-03 untainted 1114 | ``` 1115 | 1116 | ``` 1117 | # kubectl get pods 1118 | NAME READY STATUS RESTARTS AGE 1119 | nginx-85f7fb6b45-drmzz 1/1 Running 0 76s 1120 | ``` 1121 | 1122 | 1123 | Agora temos um nó operando normalmente. 1124 | 1125 | Mas e se nossos Slaves ficarem indisponíveis, podemos rodar Pods no nó master? 1126 | 1127 | Claro que podemos, vamos configurar nosso nó master para que o Scheduler consiga agenda Pods nele. 1128 | 1129 | 1130 | ``` 1131 | # kubectl taint nodes --all node-role.kubernetes.io/master- 1132 | node/elliot-01 untainted 1133 | ``` 1134 | 1135 | ``` 1136 | # kubectl describe node elliot-01 | grep -i taint 1137 | Taints: 1138 | ``` 1139 | 1140 | 1141 | Agora vamos aumentar a quantidade de réplicas do nosso nginx. 1142 | 1143 | 1144 | ``` 1145 | # kubectl scale deployment nginx --replicas=4 1146 | deployment.apps/nginx scaled 1147 | ``` 1148 | 1149 | ``` 1150 | # kubectl get pods -o wide 1151 | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 1152 | nginx-85f7fb6b45-2c6dm 1/1 Running 0 9s 10.32.0.2 elliot-02 1153 | nginx-85f7fb6b45-4jzcn 1/1 Running 0 9s 10.32.0.3 elliot-02 1154 | nginx-85f7fb6b45-drmzz 1/1 Running 0 114s 10.46.0.1 elliot-03 1155 | nginx-85f7fb6b45-rstvq 1/1 Running 0 9s 10.46.0.2 elliot-03 1156 | ``` 1157 | 1158 | 1159 | Vamos adicionar o Taint NoExecute nos nós slave para ver o que acontece: 1160 | 1161 | 1162 | ``` 1163 | # kubectl taint node elliot-02 key1=value1:NoExecute 1164 | node/elliot-02 tainted 1165 | ``` 1166 | 1167 | ``` 1168 | # kubectl taint node elliot-03 key1=value1:NoExecute 1169 | node/elliot-03 tainted 1170 | ``` 1171 | 1172 | ``` 1173 | # kubectl get pods -o wide 1174 | NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES 1175 | nginx-85f7fb6b45-49knz 1/1 Running 0 14s 10.40.0.5 elliot-01 1176 | nginx-85f7fb6b45-4cm9x 1/1 Running 0 14s 10.40.0.4 elliot-01 1177 | nginx-85f7fb6b45-kppnd 1/1 Running 0 14s 10.40.0.6 elliot-01 1178 | nginx-85f7fb6b45-rjlmj 1/1 Running 0 14s 10.40.0.3 elliot-01 1179 | ``` 1180 | 1181 | ``` 1182 | # kubectl delete deployment nginx 1183 | deployment.extensions "nginx" deleted 1184 | ``` 1185 | 1186 | 1187 | O Scheduler alocou tudo no nó master, como podemos ver o Taint pode ser usado para ajustar configurações de qual Pod deve ser alocado em qual nó. 1188 | 1189 | vamos permitir que nosso Scheduler aloque e execute os Pods em todos os nós: 1190 | 1191 | 1192 | ``` 1193 | # kubectl taint node --all key1:NoSchedule- 1194 | node/elliot-01 untainted 1195 | node/elliot-02 untainted 1196 | node/elliot-03 untainted 1197 | ``` 1198 | 1199 | ``` 1200 | # kubectl taint node --all key1:NoExecute- 1201 | node/elliot-01 untainted 1202 | node/elliot-02 untainted 1203 | node/elliot-03 untainted 1204 | ``` -------------------------------------------------------------------------------- /day-3/DescomplicandoKubernetes-Day3.md: -------------------------------------------------------------------------------- 1 | # Deployments 2 | 3 | O Deployment é um resource com a responsabilidade de instruir o Kubernetes a criar, atualizar e monitorar a saúde das instâncias de suas aplicações. 4 | Um Deployment é o responsável por gerenciar o seu ReplicaSet (que iremos falar logo menos), ou seja, o Deployment é quem vai determinar a configuração de sua aplicação e como ela será implementada. O Deployment é o controller que irá cuidar, por exemplo, uma instância de sua aplicação por algum motivo for interrompida. O Deployment controller irá identificar o problema com a instância e irá criar uma nova em seu lugar. 5 | 6 | Quando você utiliza o _kubectl create deployment_, você está realizando o deploy de um objeto chamado Deployment. Como outros objetos, o Deployment também pode ser criado através de um arquivo YAML ou de um JSON, os manifestos. 7 | 8 | Se você deseja alterar alguma configuração de seus objetos, como o pod, você pode utilizar o _kubectl apply_, através de um manifesto, ou ainda através do _kubectl edit_. 9 | 10 | Normalmente, quando você faz uma alteração em seu Deployment, é criado uma nova versão do ReplicaSet, esse se tornando o ativo e fazendo com que seu antecessor seja desativado. 11 | 12 | As versões anteriores dos ReplicaSets são mantidas, possibilitando o _rollback_ em caso de falhas. 13 | 14 | As labels são importantes para o gerenciamento do cluster, pois com ela é possível buscar ou selecionar recursos em seu cluster, fazendo com que você consiga organizar em pequenas categorias, facilitando assim a sua busca e organizando seus pods e seus recursos do cluster. As labels não são recursos do API server, eles são armazenados no metadata em formato chave-valor. 15 | 16 | Antes nos tinhas somente o RC, _Replication Controller_, que era um controle sobre o número de réplicas que determinado pod estava executando, o problema que todo esse gerenciamento era feito do lado do client. Para solucionar esse problema, foi adicionado o objeto Deployment, que permite a atualização pelo lado do server. Deployments geram ReplicaSets, que oferecerem melhores opções do que o ReplicationController, e por esse motivo está sendo substituído. 17 | 18 | Vamos criar os nossos primeiros Deployments: 19 | 20 | 21 | ``` 22 | # vim primeiro-deployment.yaml 23 | apiVersion: apps/v1 24 | kind: Deployment 25 | metadata: 26 | labels: 27 | run: nginx 28 | app: giropops 29 | name: primeiro-deployment 30 | namespace: default 31 | spec: 32 | replicas: 1 33 | selector: 34 | matchLabels: 35 | run: nginx 36 | template: 37 | metadata: 38 | labels: 39 | run: nginx 40 | dc: UK 41 | spec: 42 | containers: 43 | - image: nginx 44 | imagePullPolicy: Always 45 | name: nginx2 46 | ports: 47 | - containerPort: 80 48 | protocol: TCP 49 | resources: {} 50 | terminationMessagePath: /dev/termination-log 51 | terminationMessagePolicy: File 52 | dnsPolicy: ClusterFirst 53 | restartPolicy: Always 54 | schedulerName: default-scheduler 55 | securityContext: {} 56 | terminationGracePeriodSeconds: 30 57 | ``` 58 | 59 | ``` 60 | # kubectl create -f primeiro-deployment.yaml 61 | deployment.extensions/primeiro-deployment created 62 | ``` 63 | 64 | ``` 65 | # vim segundo-deployment.yaml 66 | apiVersion: apps/v1 67 | kind: Deployment 68 | metadata: 69 | labels: 70 | run: nginx 71 | name: segundo-deployment 72 | namespace: default 73 | spec: 74 | replicas: 1 75 | selector: 76 | matchLabels: 77 | run: nginx 78 | template: 79 | metadata: 80 | labels: 81 | run: nginx 82 | dc: Netherlands 83 | spec: 84 | containers: 85 | - image: nginx 86 | imagePullPolicy: Always 87 | name: nginx2 88 | ports: 89 | - containerPort: 80 90 | protocol: TCP 91 | resources: {} 92 | terminationMessagePath: /dev/termination-log 93 | terminationMessagePolicy: File 94 | dnsPolicy: ClusterFirst 95 | restartPolicy: Always 96 | schedulerName: default-scheduler 97 | securityContext: {} 98 | terminationGracePeriodSeconds: 30 99 | ``` 100 | 101 | ``` 102 | # kubectl create -f segundo-deployment.yaml 103 | deployment.extensions/segundo-deployment created 104 | ``` 105 | 106 | ``` 107 | # kubectl get deployment 108 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 109 | primeiro-deployment 1 1 1 1 6m 110 | segundo-deployment 1 1 1 1 1m 111 | ``` 112 | 113 | ``` 114 | # kubectl get pods 115 | NAME READY STATUS RESTARTS AGE 116 | primeiro-deployment-68c9dbf8b8-kjqpt 1/1 Running 0 19s 117 | segundo-deployment-59db86c584-cf9pp 1/1 Running 0 15s 118 | ``` 119 | 120 | ``` 121 | # kubectl describe pod primeiro-deployment-68c9dbf8b8-kjqpt 122 | Name: primeiro-deployment-68c9dbf8b8-kjqpt 123 | Namespace: default 124 | Priority: 0 125 | PriorityClassName: 126 | Node: elliot-02/10.138.0.3 127 | Start Time: Sat, 04 Aug 2018 00:45:29 +0000 128 | Labels: dc=UK 129 | pod-template-hash=2475869464 130 | run=nginx 131 | Annotations: 132 | Status: Running 133 | IP: 10.46.0.1 134 | Controlled By: ReplicaSet/primeiro-deployment-68c9dbf8b8 135 | Containers: 136 | nginx2: 137 | Container ID: docker://963ec997a0aa4aa3cecabdb3c59f67d80e7010c51eac23735524899f7f2dd4f9 138 | Image: nginx 139 | Image ID: docker-pullable://nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424 140 | Port: 80/TCP 141 | Host Port: 0/TCP 142 | State: Running 143 | Started: Sat, 04 Aug 2018 00:45:36 +0000 144 | Ready: True 145 | Restart Count: 0 146 | Environment: 147 | Mounts: 148 | /var/run/secrets/kubernetes.io/serviceaccount from default-token-np77m (ro) 149 | Conditions: 150 | Type Status 151 | Initialized True 152 | Ready True 153 | ContainersReady True 154 | PodScheduled True 155 | Volumes: 156 | default-token-np77m: 157 | Type: Secret (a volume populated by a Secret) 158 | SecretName: default-token-np77m 159 | Optional: false 160 | QoS Class: BestEffort 161 | Node-Selectors: 162 | Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s 163 | node.kubernetes.io/unreachable:NoExecute for 300s 164 | Events: 165 | Type Reason Age From Message 166 | ---- ------ ---- ---- ------- 167 | Normal Scheduled 51s default-scheduler Successfully assigned default/primeiro-deployment-68c9dbf8b8-kjqpt to elliot-02 168 | Normal Pulling 50s kubelet, elliot-02 pulling image "nginx" 169 | Normal Pulled 44s kubelet, elliot-02 Successfully pulled image "nginx" 170 | Normal Created 44s kubelet, elliot-02 Created container 171 | Normal Started 44s kubelet, elliot-02 Started container 172 | ``` 173 | 174 | ``` 175 | # kubectl describe pod segundo-deployment-59db86c584-cf9pp 176 | Name: segundo-deployment-59db86c584-cf9pp 177 | Namespace: default 178 | Priority: 0 179 | PriorityClassName: 180 | Node: elliot-02/10.138.0.3 181 | Start Time: Sat, 04 Aug 2018 00:45:49 +0000 182 | Labels: dc=Netherlands 183 | pod-template-hash=1586427140 184 | run=nginx 185 | Annotations: 186 | Status: Running 187 | IP: 10.46.0.2 188 | Controlled By: ReplicaSet/segundo-deployment-59db86c584 189 | Containers: 190 | nginx2: 191 | Container ID: docker://a9e6b5463341e62eff9e45c8c0aace14195f35e41be088ca386949500a1f2bb0 192 | Image: nginx 193 | Image ID: docker-pullable://nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424 194 | Port: 80/TCP 195 | Host Port: 0/TCP 196 | State: Running 197 | Started: Sat, 04 Aug 2018 00:45:51 +0000 198 | Ready: True 199 | Restart Count: 0 200 | Environment: 201 | Mounts: 202 | /var/run/secrets/kubernetes.io/serviceaccount from default-token-np77m (ro) 203 | Conditions: 204 | Type Status 205 | Initialized True 206 | Ready True 207 | ContainersReady True 208 | PodScheduled True 209 | Volumes: 210 | default-token-np77m: 211 | Type: Secret (a volume populated by a Secret) 212 | SecretName: default-token-np77m 213 | Optional: false 214 | QoS Class: BestEffort 215 | Node-Selectors: 216 | Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s 217 | node.kubernetes.io/unreachable:NoExecute for 300s 218 | Events: 219 | Type Reason Age From Message 220 | ---- ------ ---- ---- ------- 221 | Normal Scheduled 2m default-scheduler Successfully assigned default/segundo-deployment-59db86c584-cf9pp to elliot-02 222 | Normal Pulling 2m kubelet, elliot-02 pulling image "nginx" 223 | Normal Pulled 2m kubelet, elliot-02 Successfully pulled image "nginx" 224 | Normal Created 2m kubelet, elliot-02 Created container 225 | Normal Started 2m kubelet, elliot-02 Started container 226 | ``` 227 | 228 | ``` 229 | # kubectl describe deployment primeiro-deployment 230 | Name: primeiro-deployment 231 | Namespace: default 232 | CreationTimestamp: Sat, 04 Aug 2018 00:45:29 +0000 233 | Labels: app=giropops 234 | run=nginx 235 | Annotations: deployment.kubernetes.io/revision=1 236 | Selector: run=nginx 237 | Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable 238 | StrategyType: RollingUpdate 239 | MinReadySeconds: 0 240 | RollingUpdateStrategy: 1 max unavailable, 1 max surge 241 | Pod Template: 242 | Labels: dc=UK 243 | run=nginx 244 | Containers: 245 | nginx2: 246 | Image: nginx 247 | Port: 80/TCP 248 | Host Port: 0/TCP 249 | Environment: 250 | Mounts: 251 | Volumes: 252 | Conditions: 253 | Type Status Reason 254 | ---- ------ ------ 255 | Available True MinimumReplicasAvailable 256 | Progressing True NewReplicaSetAvailable 257 | OldReplicaSets: 258 | NewReplicaSet: primeiro-deployment-68c9dbf8b8 (1/1 replicas created) 259 | Events: 260 | Type Reason Age From Message 261 | ---- ------ ---- ---- ------- 262 | Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set primeiro-deployment-68c9dbf8b8 to 1 263 | ``` 264 | 265 | ``` 266 | # kubectl describe deployment segundo-deployment 267 | Name: segundo-deployment 268 | Namespace: default 269 | CreationTimestamp: Sat, 04 Aug 2018 00:45:49 +0000 270 | Labels: run=nginx 271 | Annotations: deployment.kubernetes.io/revision=1 272 | Selector: run=nginx 273 | Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable 274 | StrategyType: RollingUpdate 275 | MinReadySeconds: 0 276 | RollingUpdateStrategy: 1 max unavailable, 1 max surge 277 | Pod Template: 278 | Labels: dc=Netherlands 279 | run=nginx 280 | Containers: 281 | nginx2: 282 | Image: nginx 283 | Port: 80/TCP 284 | Host Port: 0/TCP 285 | Environment: 286 | Mounts: 287 | Volumes: 288 | Conditions: 289 | Type Status Reason 290 | ---- ------ ------ 291 | Available True MinimumReplicasAvailable 292 | Progressing True NewReplicaSetAvailable 293 | OldReplicaSets: 294 | NewReplicaSet: segundo-deployment-59db86c584 (1/1 replicas created) 295 | Events: 296 | Type Reason Age From Message 297 | ---- ------ ---- ---- ------- 298 | Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set segundo-deployment-59db86c584 to 1 299 | ``` 300 | 301 | 302 | 303 | ## Filtrando por Labels 304 | 305 | Quando criamos nossos Deployments adicionamos os Labels abaixo : 306 | 307 | 308 | ``` 309 | labels: 310 | run: nginx 311 | dc: UK 312 | --- 313 | labels: 314 | run: nginx 315 | dc: Netherlands 316 | ``` 317 | 318 | 319 | Os Labels são utilizados para a organização do cluster, vamos listar nossos Pods procurando pelas Labels. 320 | 321 | Primeiro vamos realizar uma pesquisa utilizando as labels dc=UK e dc=Netherlands: 322 | 323 | 324 | ``` 325 | # kubectl get pods -l dc=UK 326 | NAME READY STATUS RESTARTS AGE 327 | primeiro-deployment-68c9dbf8b8-kjqpt 1/1 Running 0 3m 328 | ``` 329 | 330 | ``` 331 | # kubectl get pods -l dc=Netherlands 332 | NAME READY STATUS RESTARTS AGE 333 | segundo-deployment-59db86c584-cf9pp 1/1 Running 0 4m 334 | ``` 335 | 336 | 337 | Caso queira uma saída mais personalizada podemos listar da seguinte forma, veja. 338 | 339 | 340 | ``` 341 | # kubectl get pod -L dc 342 | NAME READY STATUS RESTARTS AGE DC 343 | primeiro-deployment-68c9... 1/1 Running 0 5m UK 344 | segundo-deployment-59db ... 1/1 Running 0 5m Netherlands 345 | ``` 346 | 347 | 348 | Removendo o label: 349 | 350 | 351 | ``` 352 | # kubectl label nodes elliot-02 dc- 353 | ``` 354 | 355 | 356 | Removendo um determinado label de todos os nodes: 357 | 358 | 359 | ``` 360 | # kubectl label nodes --all dc- 361 | ``` 362 | 363 | 364 | 365 | ## Node Selector 366 | 367 | O Node Selector é uma forma de classificar nosso nodes como por exemplo nosso node elliot-02 que possui disco SSD e está localizado no DataCenter UK, e o node elliot-03 que possui disco HDD e está localizado no DataCenter Netherlands. 368 | 369 | Agora que temos essas informações vamos criar esses labels em nossos nodes, para utilizar os nodeSelector. 370 | 371 | 372 | ``` 373 | # kubectl label node elliot-02 disk=SSD 374 | node/elliot-02 labeled 375 | ``` 376 | 377 | ``` 378 | # kubectl label node elliot-02 dc=UK 379 | node/elliot-02 labeled 380 | ``` 381 | 382 | ``` 383 | # kubectl label node elliot-03 dc=Netherlands 384 | node/elliot-03 labeled 385 | ``` 386 | 387 | ``` 388 | # kubectl label nodes elliot-03 disk=hdd 389 | node/elliot-03 labeled 390 | ``` 391 | 392 | 393 | Opa! Acabamos declarando o disk=hdd em letra minúscula, como arrumamos isso? Subscrevendo o label como no comando abaixo: 394 | 395 | 396 | ``` 397 | # kubectl label nodes elliot-03 disk=HDD --overwrite 398 | node/elliot-03 labeled 399 | ``` 400 | 401 | 402 | Para saber os labels configurado em cada node basta executar o comando: 403 | 404 | 405 | ``` 406 | # kubectl label nodes elliot-02 --list 407 | dc=UK 408 | disk=SSD 409 | kubernetes.io/hostname=elliot-02 410 | beta.kubernetes.io/arch=amd64 411 | beta.kubernetes.io/os=linux 412 | ``` 413 | 414 | ``` 415 | # kubectl label nodes elliot-03 --list 416 | beta.kubernetes.io/os=linux 417 | dc=Netherlands 418 | disk=HDD 419 | kubernetes.io/hostname=elliot-03 420 | beta.kubernetes.io/arch=amd64 421 | ``` 422 | 423 | 424 | Agora, basta realizar o deploy novamente, porém antes vamos adicionar duas novas opções ao yaml e vamos ver a mágica acontecer. O nosso pod irá ser criado no node elliot-02, onde possui a label disk=SSD. 425 | 426 | 427 | ``` 428 | # vim terceiro-deployment.yaml 429 | apiVersion: apps/v1 430 | kind: Deployment 431 | metadata: 432 | labels: 433 | run: nginx 434 | name: terceiro-deployment 435 | namespace: default 436 | spec: 437 | replicas: 1 438 | selector: 439 | matchLabels: 440 | run: nginx 441 | template: 442 | metadata: 443 | creationTimestamp: null 444 | labels: 445 | run: nginx 446 | dc: Netherlands 447 | spec: 448 | containers: 449 | - image: nginx 450 | imagePullPolicy: Always 451 | name: nginx2 452 | ports: 453 | - containerPort: 80 454 | protocol: TCP 455 | resources: {} 456 | terminationMessagePath: /dev/termination-log 457 | terminationMessagePolicy: File 458 | dnsPolicy: ClusterFirst 459 | restartPolicy: Always 460 | schedulerName: default-scheduler 461 | securityContext: {} 462 | terminationGracePeriodSeconds: 30 463 | nodeSelector: 464 | disk: SSD 465 | ``` 466 | 467 | ``` 468 | # kubectl create -f terceiro-deployment.yaml 469 | deployment.extensions/terceiro-deployment created 470 | ``` 471 | 472 | ``` 473 | # kubectl get pods -o wide 474 | NAME READY STATUS RESTARTS AGE IP NODE 475 | primeiro-deployment-56d9... 1/1 Running 0 14m 172.17.0.4 elliot-03 476 | segundo-deployment-869f... 1/1 Running 0 14m 172.17.0.5 elliot-03 477 | terceiro-deployment-59cd... 1/1 Running 0 22s 172.17.0.6 elliot-02 478 | ``` 479 | 480 | 481 | Agora imagina as infinitas possibilidades que isso poderá lhe proporcionar… Já estou pensando em várias, como por exemplo se é produção ou não, se consome muita CPU ou muita RAM, se precisa estar em determinado rack e por ae vai. 😃 482 | 483 | Simples como voar, não? 484 | 485 | 486 | ## Kubectl Edit 487 | 488 | Agora vamos fazer o seguinte, vamos utilizar o comando Edit para editar nosso primeiro Deployment, digamos que a "quente" com o Pod ainda em execução. 489 | 490 | 491 | ``` 492 | # kubectl edit deployment primeiro-deployment 493 | ``` 494 | 495 | 496 | Abriu um editor, correto?. Vamos alterar o DC, vamos imaginar que esse Deployment agora rodará no DC de Netherlands, precisamos adicionar o Label e o nodeSelector: 497 | 498 | 499 | ``` 500 | spec: 501 | replicas: 1 502 | selector: 503 | matchLabels: 504 | run: nginx 505 | strategy: 506 | rollingUpdate: 507 | maxSurge: 1 508 | maxUnavailable: 1 509 | type: RollingUpdate 510 | template: 511 | metadata: 512 | creationTimestamp: null 513 | labels: 514 | dc: Netherlands 515 | app: giropops 516 | run: nginx 517 | spec: 518 | containers: 519 | - image: nginx 520 | imagePullPolicy: Always 521 | name: nginx2 522 | ports: 523 | - containerPort: 80 524 | protocol: TCP 525 | resources: {} 526 | terminationMessagePath: /dev/termination-log 527 | terminationMessagePolicy: File 528 | dnsPolicy: ClusterFirst 529 | nodeSelector: 530 | dc: Netherlands 531 | ... 532 | 533 | deployment.extensions/primeiro-deployment edited 534 | ``` 535 | 536 | 537 | Como podemos ver mudamos o valor do label dc e também modificamos o nodeSelector, onde ele agora subirá no node que tiver a label dc com o valor Netherlands, fácil! 😀 538 | 539 | Veja se o resultado foi conforme esperado: 540 | 541 | 542 | ``` 543 | # kubectl get pods -l dc=Netherlands -o wide 544 | NAME READY STATUS RESTARTS AGE ..NODE 545 | primeiro-deployment-7.. 1/1 Running 0 3m elliot-03 546 | segundo-deployment-5.. 1/1 Running 0 49m elliot-02 547 | terceiro-deployment-5.. 1/1 Running 0 14m elliot-02 548 | ``` 549 | 550 | 551 | Com certeza, esse pod foi criado no node elliot-03, pois havíamos dito que ele possua essa label anteriormente. 552 | 553 | 554 | # ReplicaSet 555 | 556 | O ReplicaSet garante a quantidade solicitada de pods e os recursos necessários para um Deployment. Uma vez que o Deployment é criado, é o ReplicaSet que controla a quantidade de pods em execução, caso algum pod seja finalizado, ele que irá detectar e solicitar que outro pod seja executado em seu lugar, garantindo assim a quantidade de réplicas solicitadas. 557 | 558 | Vamos criar nosso primeiro ReplicarSet: 559 | 560 | 561 | ``` 562 | # vim primeiro-replicaset.yaml 563 | apiVersion: apps/v1 564 | kind: ReplicaSet 565 | metadata: 566 | name: replica-set-primeiro 567 | spec: 568 | replicas: 3 569 | selector: 570 | matchLabels: 571 | system: Giropops 572 | template: 573 | metadata: 574 | labels: 575 | system: Giropops 576 | spec: 577 | containers: 578 | - name: nginx 579 | image: nginx:1.7.9 580 | ports: 581 | - containerPort: 80 582 | ``` 583 | 584 | ``` 585 | 586 | # kubectl create -f primeiro-replicaset.yaml 587 | replicaset.extensions/replica-set-primeiro created 588 | ``` 589 | 590 | ``` 591 | # kubectl get replicaset 592 | NAME DESIRED CURRENT READY AGE 593 | replica-set-primeiro 3 3 1 2s 594 | ``` 595 | 596 | 597 | Podemos observar os pods em execução: 598 | 599 | 600 | ``` 601 | #kubectl get pods 602 | NAME READY STATUS RESTARTS AGE 603 | replica-set-primeiro-6drmt 1/1 Running 0 12s 604 | replica-set-primeiro-7j59w 1/1 Running 0 12s 605 | replica-set-primeiro-mg8q9 1/1 Running 0 12s 606 | ``` 607 | 608 | 609 | Temos exatamente 3 pods de nginx rodando simultaneamente. 610 | 611 | Podemos obter mais informações do nosso ReplicaSet utilizando o comando describe: 612 | 613 | 614 | ``` 615 | # kubectl describe rs replica-set-primeiro 616 | Name: replica-set-primeiro 617 | Namespace: default 618 | Selector: system=Giropops 619 | Labels: system=Giropops 620 | Annotations: 621 | Replicas: 3 current / 3 desired 622 | Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed 623 | Pod Template: 624 | Labels: system=Giropops 625 | Containers: 626 | nginx: 627 | Image: nginx:1.7.9 628 | Port: 80/TCP 629 | Host Port: 0/TCP 630 | Environment: 631 | Mounts: 632 | Volumes: 633 | Events: 634 | Type Reason Age From Message 635 | ---- ------ ---- ---- ------- 636 | Normal SuccessfulCreate 31s replicaset-controller Created pod: replica-set-primeiro-mg8q9 637 | Normal SuccessfulCreate 31s replicaset-controller Created pod: replica-set-primeiro-6drmt 638 | Normal SuccessfulCreate 31s replicaset-controller Created pod: replica-set-primeiro-7j59w 639 | ``` 640 | 641 | 642 | Assim podemos ver todos os pods associados ao ReplicaSet, e se excluirmos um desses Pods, o que será que acontece? 643 | 644 | Vamos testar: 645 | 646 | 647 | ``` 648 | # kubectl delete pod replica-set-primeiro-6drmt 649 | pod "replica-set-primeiro-6drmt" deleted 650 | ``` 651 | 652 | 653 | Agora vamos verificar novamente os Pods em execução: 654 | 655 | 656 | ``` 657 | # kubectl get pods -l system=Giropops 658 | NAME READY STATUS RESTARTS AGE 659 | replica-set-primeiro-7j59w 1/1 Running 0 1m 660 | replica-set-primeiro-mg8q9 1/1 Running 0 1m 661 | replica-set-primeiro-s5dz2 1/1 Running 0 15s 662 | ``` 663 | 664 | 665 | Percebeu que ele recriou outro Pod? o ReplicaSet faz com que sempre tenha 3 pods disponíveis. 666 | 667 | Vamos alterar para 4 réplicas e recriar o ReplicaSet, para isso vamos utilizar o kubectl edit visto anteriormente assim podemos alterar o ReplicaSet já em execução: 668 | 669 | 670 | ``` 671 | # kubectl edit rs replica-set-primeiro 672 | apiVersion: apps/v1 673 | kind: ReplicaSet 674 | metadata: 675 | creationTimestamp: 2018-07-05T04:32:42Z 676 | generation: 2 677 | labels: 678 | system: Giropops 679 | name: replica-set-primeiro 680 | namespace: default 681 | resourceVersion: "471758" 682 | selfLink: /apis/extensions/v1beta1/namespaces/default/replicasets/replica-set-primeiro 683 | uid: 753290c1-800c-11e8-b889-42010a8a0002 684 | spec: 685 | replicas: 4 686 | selector: 687 | matchLabels: 688 | system: Giropops 689 | template: 690 | metadata: 691 | creationTimestamp: null 692 | labels: 693 | system: Giropops 694 | ... 695 | 696 | replicaset.extensions/replica-set-primeiro edited 697 | ``` 698 | 699 | ``` 700 | # kubectl get pods -l system=Giropops 701 | NAME READY STATUS RESTARTS AGE 702 | replica-set-primeiro-7j59w 1/1 Running 0 2m 703 | replica-set-primeiro-96hj7 1/1 Running 0 10s 704 | replica-set-primeiro-mg8q9 1/1 Running 0 2m 705 | replica-set-primeiro-s5dz2 1/1 Running 0 1m 706 | ``` 707 | 708 | 709 | Veja que ele não cria um deployment para esse replicaset: 710 | 711 | 712 | ``` 713 | # kubectl get deployment 714 | No resources found. 715 | ``` 716 | 717 | 718 | Agora vamos editar um dos pods e modificar a versão da imagem do Nginx que estamos utilizando no exemplo, vamos alterar de "_ image: nginx:1.7.9_" para "_image: nginx:1.15.0_" utilizando o "kubectl edit": 719 | 720 | 721 | ``` 722 | # kubectl edit pod replica-set-primeiro-7j59w 723 | apiVersion: v1 724 | kind: Pod 725 | metadata: 726 | name: replica-set-primeiro 727 | ... 728 | spec: 729 | containers: 730 | - name: nginx 731 | image: nginx:1.15.0 732 | ports: 733 | - containerPort: 80 734 | ... 735 | 736 | pod/replica-set-primeiro-7j59w edited 737 | ``` 738 | 739 | 740 | Agora vamos observar novamente os pods, como estão? 741 | 742 | 743 | ``` 744 | # kubectl get pods -l system=Giropops 745 | NAME READY STATUS RESTARTS AGE 746 | replica-set-primeiro-7j59w 1/1 Running 1 8m 747 | replica-set-primeiro-96hj7 1/1 Running 0 6m 748 | replica-set-primeiro-mg8q9 1/1 Running 0 8m 749 | replica-set-primeiro-s5dz2 1/1 Running 0 7m 750 | ``` 751 | 752 | 753 | Aparentemente nada aconteceu concordam? vamos detalhar melhor esse pod que acabamos de alterar. 754 | 755 | 756 | ``` 757 | #kubectl describe pod replica-set-primeiro-7j59w 758 | Name: replica-set-primeiro-7j59w 759 | Namespace: default 760 | Priority: 0 761 | PriorityClassName: 762 | Node: elliot-02/10.138.0.3 763 | Start Time: Sat, 04 Aug 2018 01:47:56 +0000 764 | Labels: system=Giropops 765 | Annotations: 766 | Status: Running 767 | IP: 10.46.0.2 768 | Controlled By: ReplicaSet/replica-set-primeiro 769 | Containers: 770 | nginx: 771 | Container ID: docker://6991b627cf4d6daca039ab9d6336929c0de1fc279c55a451cf9c7304e1c46504 772 | Image: nginx:1.15.0 773 | ... 774 | Successfully assigned default/replica-set-primeiro-7j59w to elliot-02 775 | Normal Pulled 9m kubelet, elliot-02 Container image "nginx:1.7.9" already present on machine 776 | Normal Killing 1m kubelet, elliot-02 Killing container with id docker://nginx:Container spec hash changed (3238050430 vs 811632170).. Container will be killed and recreated. 777 | Normal Pulling 1m kubelet, elliot-02 pulling image "nginx:1.15.0" 778 | Normal Created 1m (x2 over 9m) kubelet, elliot-02 Created container 779 | Normal Started 1m (x2 over 9m) kubelet, elliot-02 Started container 780 | Normal Pulled 1m kubelet, elliot-02 Successfully pulled image "nginx:1.15.0" 781 | ``` 782 | 783 | 784 | Como podemos observar ele alterou a imagem do nginx do 1.7.9 para 1.15.0, como o replicaset não tem um deployment ele apenas destruiu o container sem destruir o pod, então a configuração passada manualmente é uma configuração válida, mas caso o pod seja removido o ReplicaSet vai recriá-lo com as configurações originais. 785 | 786 | Vamos apagar o pod e ver se realmente acontece isso: 787 | 788 | 789 | ``` 790 | # kubectl delete pod replica-set-primeiro-7j59w 791 | pod "replica-set-primeiro-7j59w" delete 792 | ``` 793 | 794 | ``` 795 | # kubectl get pods -l system=Giropops 796 | NAME READY STATUS RESTARTS AGE 797 | replica-set-primeiro-96hj7 1/1 Running 0 12m 798 | replica-set-primeiro-mg8q9 1/1 Running 0 14m 799 | replica-set-primeiro-s5dz2 1/1 Running 0 13m 800 | replica-set-primeiro-xzfvg 1/1 Running 0 5s 801 | ``` 802 | 803 | ``` 804 | # kubectl describe pod replica-set-primeiro-xzfvg 805 | Name: replica-set-primeiro-xzfvg 806 | Namespace: default 807 | Priority: 0 808 | PriorityClassName: 809 | Node: elliot-02/10.138.0.3 810 | Start Time: Sat, 04 Aug 2018 02:02:35 +0000 811 | Labels: system=Giropops 812 | Annotations: 813 | Status: Running 814 | IP: 10.46.0.2 815 | Controlled By: ReplicaSet/replica-set-primeiro 816 | Containers: 817 | nginx: 818 | Container ID: docker://e8b88065640ba3ea346c93bb368ae6b7fb7b1d9507a948d891ca632df0dfc071 819 | Image: nginx:1.7.9 820 | ... 821 | ``` 822 | 823 | 824 | Olha só, o novo pod foi criado com a imagem configurada no replicaset. 825 | 826 | Agora vamos apagar nosso ReplicaSet. 827 | 828 | 829 | ``` 830 | # kubectl get rs 831 | NAME DESIRED CURRENT READY AGE 832 | replica-set-primeiro 4 4 4 25m 833 | ``` 834 | 835 | ``` 836 | # kubectl delete rs replica-set-primeiro 837 | replicaset.apps "replica-set-primeiro" deleted 838 | ``` 839 | 840 | 841 | 842 | # DaemonSet 843 | 844 | Basicamente a mesma coisa do que o ReplicaSet, com a diferença que quando você utiliza o DaemonSet você não especifica o número de réplicas, ele subirá um pod por node de seu cluster. 845 | 846 | É sempre interessante quando criar usar e abusar dos labels, assim você conseguirá ter melhor flexibilidade na distribuição mais adequada de sua aplicação. 847 | 848 | Ele é bem interessante para serviços que necessitem rodar em todos os nodes do cluster, como por exemplo, coletores de logs e agentes de monitoração. 849 | 850 | Vamos criar o nosso primeiro DaemonSet: 851 | 852 | 853 | ``` 854 | # vim primeiro-daemonset.yaml 855 | apiVersion: apps/v1 856 | kind: DaemonSet 857 | metadata: 858 | name: daemon-set-primeiro 859 | spec: 860 | selector: 861 | matchLabels: 862 | system: Strigus 863 | template: 864 | metadata: 865 | labels: 866 | system: Strigus 867 | spec: 868 | containers: 869 | - name: nginx 870 | image: nginx:1.7.9 871 | ports: 872 | - containerPort: 80 873 | ``` 874 | 875 | 876 | Mas antes vamos permitir que todos os nossos nodes executem pods. 877 | 878 | 879 | ``` 880 | # kubectl taint nodes --all node-role.kubernetes.io/master- 881 | node/elliot-01 untainted 882 | taint "node-role.kubernetes.io/master:" not found 883 | taint "node-role.kubernetes.io/master:" not found 884 | ``` 885 | 886 | 887 | Agora podemos criar nosso DaemonSet. 888 | 889 | 890 | ``` 891 | # kubectl create -f primeiro-daemonset.yaml 892 | daemonset.extensions/daemon-set-primeiro created 893 | ``` 894 | 895 | 896 | Vamos listar nossos DaemonSet: 897 | 898 | 899 | ``` 900 | # kubectl get daemonset 901 | NAME DESIRED CURRENT READY UP-TO-DATE ... AGE 902 | daemon-set-primeiro 3 3 3 3 30s 903 | ``` 904 | 905 | ``` 906 | # kubectl describe ds daemon-set-primeiro 907 | Name: daemon-set-primeiro 908 | Selector: system=Strigus 909 | Node-Selector: 910 | Labels: system=Strigus 911 | Annotations: 912 | Desired Number of Nodes Scheduled: 3 913 | Current Number of Nodes Scheduled: 3 914 | Number of Nodes Scheduled with Up-to-date Pods: 3 915 | Number of Nodes Scheduled with Available Pods: 3 916 | Number of Nodes Misscheduled: 0 917 | Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed 918 | Pod Template: 919 | Labels: system=Strigus 920 | Containers: 921 | nginx: 922 | Image: nginx:1.7.9 923 | Port: 80/TCP 924 | Host Port: 0/TCP 925 | Environment: 926 | Mounts: 927 | Volumes: 928 | Events: 929 | Type Reason Age From Message 930 | ---- ------ ---- ---- ------- 931 | Normal SuccessfulCreate 41s daemonset-controller Created pod: daemon-set-primeiro-jl6f5 932 | Normal SuccessfulCreate 412 daemonset-controller Created pod: daemon-set-primeiro-jh2sp 933 | Normal SuccessfulCreate 412 daemonset-controller Created pod: daemon-set-primeiro-t9rv9 934 | ``` 935 | 936 | ``` 937 | # kubectl get pods -o wide 938 | NAME READY STATUS RESTARTS AGE .. NODE 939 | daemon-set-primeiro.. 1/1 Running 0 1m elliot-01 940 | daemon-set-primeiro.. 1/1 Running 0 1m elliot-02 941 | daemon-set-primeiro.. 1/1 Running 0 1m elliot-03 942 | ``` 943 | 944 | 945 | Como podemos observar temos um pod por nó rodando nosso daemon-set-primeiro. 946 | 947 | Vamos alterar a imagem desse pod diretamente no DaemonSet, usando o comando kubectl set: 948 | 949 | 950 | ``` 951 | # kubectl set image ds daemon-set-primeiro nginx=nginx:1.15.0 952 | daemonset.extensions/daemon-set-primeiro image updated 953 | ``` 954 | 955 | 956 | Vamos confirmar se a imagem foi realmente alterada: 957 | 958 | 959 | ``` 960 | # kubectl describe ds daemon-set-primeiro 961 | Name: daemon-set-primeiro 962 | Selector: system=Strigus 963 | Node-Selector: 964 | Labels: system=Strigus 965 | Annotations: 966 | Desired Number of Nodes Scheduled: 3 967 | Current Number of Nodes Scheduled: 3 968 | Number of Nodes Scheduled with Up-to-date Pods: 0 969 | Number of Nodes Scheduled with Available Pods: 3 970 | Number of Nodes Misscheduled: 0 971 | Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed 972 | Pod Template: 973 | Labels: system=Strigus 974 | Containers: 975 | nginx: 976 | Image: nginx:1.15.0 977 | Port: 80/TCP 978 | Host Port: 0/TCP 979 | Environment: 980 | Mounts: 981 | Volumes: 982 | Events: 983 | Type Reason Age From Message 984 | ---- ------ ---- ---- ------- 985 | Normal SuccessfulCreate 2m daemonset-controller Created pod: daemon-set-primeiro-jl6f5 986 | Normal SuccessfulCreate 2m daemonset-controller Created pod: daemon-set-primeiro-jh2sp 987 | Normal SuccessfulCreate 2m daemonset-controller Created pod: daemon-set-primeiro-t9rv9 988 | ``` 989 | 990 | 991 | Agora vamos verificar se as imagens dos pods estão atualizadas: 992 | 993 | 994 | ``` 995 | # kubectl get pods 996 | NAME READY STATUS RESTARTS AGE 997 | daemon-set-primeiro-jh2sp 1/1 Running 0 2m 998 | daemon-set-primeiro-jl6f5 1/1 Running 0 2m 999 | daemon-set-primeiro-t9rv9 1/1 Running 0 2m 1000 | ``` 1001 | 1002 | 1003 | Como podemos observar não tivemos nenhum restart nos pods. 1004 | 1005 | Vamos verificar a imagem executando em um dos pods. 1006 | 1007 | 1008 | ``` 1009 | # kubectl describe pod daemon-set-primeiro-jh2sp | grep -i image: 1010 | Image: nginx:1.7.9 1011 | ``` 1012 | 1013 | 1014 | Exatamente, Não conseguimos alterar informações do DaemonSet em execução. 1015 | 1016 | E se o pod for deletado? 1017 | 1018 | 1019 | ``` 1020 | # kubectl delete pod daemon-set-primeiro-jh2sp 1021 | pod "daemon-set-primeiro-jh2sp" deleted 1022 | ``` 1023 | 1024 | ``` 1025 | # kubectl get pods 1026 | NAME READY STATUS RESTARTS AGE 1027 | daemon-set-primeiro-hp4qc 1/1 Running 0 3s 1028 | daemon-set-primeiro-jl6f5 1/1 Running 0 10m 1029 | daemon-set-primeiro-t9rv9 1/1 Running 0 10m 1030 | ``` 1031 | 1032 | 1033 | Vamos listar o novo Pod que foi criado, após deletarmos o Pod antigo: 1034 | 1035 | 1036 | ``` 1037 | # kubectl describe pod daemon-set-primeiro-hp4qc | grep -i image: 1038 | Image: nginx:1.15.0 1039 | ``` 1040 | 1041 | 1042 | Agora um Pod que já estava em execução: 1043 | 1044 | 1045 | ``` 1046 | # kubectl describe pod daemon-set-primeiro-jl6f5 | grep -i image: 1047 | Image: nginx:1.7.9 1048 | ``` 1049 | 1050 | 1051 | Como podemos observar, para atualizar todos os pods do DaemonSet precisamos recriar-lo ou destruir todos os pods relacionado a ele, mas isso não é muito ruim? sim é bem ruim para melhorar nossas vidas temos a opção RollingUpdate que vamos ver no próximo capítulo. 1052 | 1053 | 1054 | # Rollouts e Rollbacks 1055 | 1056 | Agora vamos imaginar que essa nossa última edição utilizando o comando "kubectl set" no DaemonSet não foi correta e precisamos voltar a configuração anterior, onde a versão da imagem era outra, como faremos? 1057 | 1058 | É muito simples, para isso existe o _Rollout_. Com ele você pode verificar quais foram as modificações que aconteceram em seu Deployment ou DaemonSet, como se fosse um versionamento. Vejaaaa! (Com a voz do Nelson Rubens) 1059 | 1060 | 1061 | ``` 1062 | # kubectl rollout history ds daemon-set-primeiro 1063 | daemonsets "daemon-set-primeiro" 1064 | REVISION CHANGE-CAUSE 1065 | 1 1066 | 2 1067 | ``` 1068 | 1069 | 1070 | Ele irá mostrar duas linhas, a primeira que é a original, com a imagem do nginx:1.7.9 e a segunda já com a imagem nginx:1.15.0. As informações não estão muito detalhada s concordam ? 1071 | 1072 | Veja como verificar os detalhes de cada uma dessas entradas, que são chamadas de revision: 1073 | 1074 | 1075 | ``` 1076 | # kubectl rollout history ds daemon-set-primeiro --revision=1 1077 | daemonsets "daemon-set-primeiro" with revision #1 1078 | Pod Template: 1079 | Labels: system=DaemonOne 1080 | Containers: 1081 | nginx: 1082 | Image: nginx:1.7.9 1083 | Port: 80/TCP 1084 | Host Port: 0/TCP 1085 | Environment: 1086 | Mounts: 1087 | Volumes: 1088 | ``` 1089 | 1090 | ``` 1091 | # kubectl rollout history ds daemon-set-primeiro --revision=2 1092 | daemonsets "daemon-set-primeiro" with revision #2 1093 | Pod Template: 1094 | Labels: system=DaemonOne 1095 | Containers: 1096 | nginx: 1097 | Image: nginx:1.15.0 1098 | Port: 80/TCP 1099 | Host Port: 0/TCP 1100 | Environment: 1101 | Mounts: 1102 | Volumes: 1103 | ``` 1104 | 1105 | 1106 | Para voltar para a revision desejada, basta fazer o seguinte: 1107 | 1108 | 1109 | ``` 1110 | # kubectl rollout undo ds daemon-set-primeiro --to-revision=1 1111 | daemonset.extensions/daemon-set-primeiro rolled back 1112 | ``` 1113 | 1114 | 1115 | Perceba que trocamos o history por undo e o revision por to-revision, assim faremos o rollback em nosso DaemonSet, e voltamos a versão da imagem que desejamos. 😃 1116 | 1117 | Para acompanhar o rollout, execute: 1118 | 1119 | 1120 | ``` 1121 | # kubectl rollout status ds daemon-set-primeiro 1122 | ``` 1123 | 1124 | 1125 | Vamos confirmar se já estamos executando a nova imagem e um dos nosso pods: 1126 | 1127 | 1128 | ``` 1129 | # kubectl describe daemon-set-primeiro-hp4qc | grep -i image: 1130 | Image: nginx:1.15.0 1131 | ``` 1132 | 1133 | 1134 | Não funcionou, porque? porque teremos que matar o Pod para ele ser recriado com as novas configuração. 1135 | 1136 | Vamos afinar esse nosso DamonSet, vamos adicionar o RollingUpdate e esse cara vai atualizar automaticamente os Pods quando houver alguma alteração. 1137 | 1138 | Vamos lá, primeiro vamos remover o DaemonSet adicionar duas novas informações em nosso manifesto yaml e em seguida criar outro DaemonSet em seu lugar. 1139 | 1140 | 1141 | ``` 1142 | # kubectl delete -f primeiro-daemonset.yaml 1143 | daemonset.extensions "daemon-set-primeiro" deleted 1144 | ``` 1145 | 1146 | ``` 1147 | # vim primeiro-daemonset.yaml 1148 | apiVersion: extensions/v1beta1 1149 | kind: DaemonSet 1150 | metadata: 1151 | name: daemon-set-primeiro 1152 | spec: 1153 | template: 1154 | metadata: 1155 | labels: 1156 | system: DaemonOne 1157 | spec: 1158 | containers: 1159 | - name: nginx 1160 | image: nginx:1.7.9 1161 | ports: 1162 | - containerPort: 80 1163 | updateStrategy: 1164 | type: RollingUpdate 1165 | ``` 1166 | 1167 | ``` 1168 | # kubectl create -f primeiro-daemonset.yaml 1169 | daemonset.extensions/daemon-set-primeiro created 1170 | ``` 1171 | 1172 | 1173 | Sucesso, vamos verificar se nosso DaemonSet foi inicializado certinho. 1174 | 1175 | 1176 | ``` 1177 | # kubectl get daemonset 1178 | NAME DESIRED CURRENT READY ... AGE 1179 | daemon-set-primeiro 3 3 3 ... 5m 1180 | ``` 1181 | 1182 | ``` 1183 | # kubectl describe ds daemon-set-primeiro 1184 | Name: daemon-set-primeiro 1185 | Selector: system=DaemonOne 1186 | Node-Selector: 1187 | Labels: system=DaemonOne 1188 | Annotations: 1189 | Desired Number of Nodes Scheduled: 3 1190 | Current Number of Nodes Scheduled: 3 1191 | Number of Nodes Scheduled with Up-to-date Pods: 3 1192 | Number of Nodes Scheduled with Available Pods: 3 1193 | Number of Nodes Misscheduled: 0 1194 | Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed 1195 | Pod Template: 1196 | Labels: system=DaemonOne 1197 | Containers: 1198 | nginx: 1199 | Image: nginx:1.7.9 1200 | Port: 80/TCP 1201 | Host Port: 0/TCP 1202 | Environment: 1203 | Mounts: 1204 | Volumes: 1205 | Events: 1206 | Type Reason Age From Message 1207 | ---- ------ ---- ---- ------- 1208 | Normal SuccessfulCreate 5m daemonset-controller Created pod: daemon-set-primeiro-52k8k 1209 | Normal SuccessfulCreate 5m daemonset-controller Created pod: daemon-set-primeiro-6sln2 1210 | Normal SuccessfulCreate 5m daemonset-controller Created pod: daemon-set-primeiro-9v2w9 1211 | daemonset-controller Created pod: daemon-set-primeiro-9dktj 1212 | ``` 1213 | 1214 | 1215 | Vamos verificar nossa recém adicionada configuração de RollingUpdate: 1216 | 1217 | 1218 | ``` 1219 | # kubectl get ds daemon-set-primeiro -o yaml | grep -A 2 Strategy 1220 | updateStrategy: 1221 | rollingUpdate: 1222 | maxUnavailable: 1 1223 | ``` 1224 | 1225 | 1226 | Agora com nosso DaemonSet já configurado, vamos alterar aquela mesma imagem do nginx e ver o que acontece de fato: 1227 | 1228 | 1229 | ``` 1230 | # kubectl set image ds daemon-set-primeiro nginx=nginx:1.15.0 1231 | daemonset.extensions/daemon-set-primeiro image updated 1232 | ``` 1233 | 1234 | 1235 | Vamos listar o DaemonSet e os Pods para ter certeza de que nada se quebrou. 1236 | 1237 | 1238 | ``` 1239 | # kubectl get daemonset 1240 | NAME DESIRED CURRENT READY ... AGE 1241 | daemon-set-primeiro 3 3 3 ... 6m 1242 | ``` 1243 | 1244 | ``` 1245 | # kubectl get pods -o wide 1246 | NAME READY STATUS RESTARTS AGE NODE 1247 | daemon-set-primeiro-7m... 1/1 Running 0 10s elliot-02 1248 | daemon-set-primeiro-j7... 1/1 Running 0 10s elliot-03 1249 | daemon-set-primeiro-v5... 1/1 Running 0 10s elliot-01 1250 | ``` 1251 | 1252 | 1253 | Como podemos observar nosso DaemonSet se manteve o mesmo, porém os pods foram recriados, vamos detalhar o DaemonSet para visualizar as alterações realizadas. 1254 | 1255 | 1256 | ``` 1257 | # kubectl describe ds daemon-set-primeiro 1258 | Name: daemon-set-primeiro 1259 | Selector: system=DaemonOne 1260 | Node-Selector: 1261 | Labels: system=DaemonOne 1262 | Annotations: 1263 | Desired Number of Nodes Scheduled: 3 1264 | Current Number of Nodes Scheduled: 3 1265 | Number of Nodes Scheduled with Up-to-date Pods: 3 1266 | Number of Nodes Scheduled with Available Pods: 3 1267 | Number of Nodes Misscheduled: 0 1268 | Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed 1269 | Pod Template: 1270 | Labels: system=DaemonOne 1271 | Containers: 1272 | nginx: 1273 | Image: nginx:1.15.0 1274 | Port: 80/TCP 1275 | Host Port: 0/TCP 1276 | Environment: 1277 | Mounts: 1278 | Volumes: 1279 | Events: 1280 | Type Reason Age From Message 1281 | ---- ------ ---- ---- ------- 1282 | Normal SuccessfulCreate 8m daemonset-controller Created pod: daemon-set-primeiro-52k8k 1283 | Normal SuccessfulCreate 8m daemonset-controller Created pod: daemon-set-primeiro-6sln2 1284 | Normal SuccessfulCreate 8m daemonset-controller Created pod: daemon-set-primeiro-9v2w9 1285 | Normal SuccessfulDelete 10m daemonset-controller Deleted pod: daemon-set-primeiro-6sln2 1286 | Normal SuccessfulCreate 1m daemonset-controller Created pod: daemon-set-primeiro-j788v 1287 | Normal SuccessfulDelete 10m daemonset-controller Deleted pod: daemon-set-primeiro-52k8k 1288 | Normal SuccessfulCreate 1m daemonset-controller Created pod: daemon-set-primeiro-7mpwr 1289 | Normal SuccessfulDelete 10m daemonset-controller Deleted pod: daemon-set-primeiro-9v2w9 1290 | Normal SuccessfulCreate 1m daemonset-controller Created pod: daemon-set-primeiro-v5m47 1291 | ``` 1292 | 1293 | 1294 | Olha que Bacana, se observamos o campo **Events** podemos ver que o RollingUpdate matou os pods antigos e recriou com a nova imagem que alteramos utilizando o kubectl set. 1295 | 1296 | Podemos também verificar em um dos Pod se essa alteração realmente aconteceu. 1297 | 1298 | 1299 | ``` 1300 | # kubectl describe pod daemon-set-primeiro-j788v | grep -i image: 1301 | Image: nginx:1.15.0 1302 | ``` 1303 | 1304 | 1305 | Viram? Muito sensacional esse negócio de RollingUpdate. 1306 | 1307 | Vamos verificar nosso histórico de modificações: 1308 | 1309 | 1310 | ``` 1311 | # kubectl rollout history ds daemon-set-primeiro 1312 | daemonsets "daemon-set-primeiro" 1313 | REVISION CHANGE-CAUSE 1314 | 1 1315 | 2 1316 | ``` 1317 | 1318 | 1319 | Sim temos duas alterações, vamos detalhar para saber qual é qual: 1320 | 1321 | 1322 | ``` 1323 | # kubectl rollout history ds daemon-set-primeiro --revision=1 1324 | daemonsets "daemon-set-primeiro" with revision #1 1325 | Pod Template: 1326 | Labels: system=DaemonOne 1327 | Containers: 1328 | nginx: 1329 | Image: nginx:1.7.9 1330 | Port: 80/TCP 1331 | Host Port: 0/TCP 1332 | Environment: 1333 | Mounts: 1334 | Volumes: 1335 | ``` 1336 | 1337 | ``` 1338 | # kubectl rollout history ds daemon-set-primeiro --revision=2 1339 | daemonsets "daemon-set-primeiro" with revision #2 1340 | Pod Template: 1341 | Labels: system=DaemonOne 1342 | Containers: 1343 | nginx: 1344 | Image: nginx:1.15.0 1345 | Port: 80/TCP 1346 | Host Port: 0/TCP 1347 | Environment: 1348 | Mounts: 1349 | Volumes: 1350 | ``` 1351 | 1352 | 1353 | Agora vamos realizar o RollBack do nosso DaemonSet para a revision 1: 1354 | 1355 | 1356 | ``` 1357 | # kubectl rollout undo ds daemon-set-primeiro --to-revision=1 1358 | daemonset.extensions/daemon-set-primeiro rolled back 1359 | kubectl rollout undo ds daem kubectl rollout undo ds daem 1360 | ``` 1361 | 1362 | ``` 1363 | # kubectl get pods 1364 | NAME READY STATUS RESTARTS AGE 1365 | daemon-set-primeiro-c2jjk 1/1 Running 0 19s 1366 | daemon-set-primeiro-hrn48 1/1 Running 0 19s 1367 | daemon-set-primeiro-t6mr9 1/1 Running 0 19s 1368 | ``` 1369 | 1370 | ``` 1371 | # kubectl describe pod daemon-set-primeiro-c2jjk | grep -i image: 1372 | Image: nginx:1.7.9 1373 | ``` 1374 | 1375 | 1376 | Sensacional não? 1377 | 1378 | Deu ruim? 1379 | 1380 | Basta retornar para a outra configuração: 1381 | 1382 | 1383 | ``` 1384 | # kubectl rollout undo ds daemon-set-primeiro --to-revision=2 1385 | daemonset.extensions/daemon-set-primeiro rolled back 1386 | ``` 1387 | 1388 | ``` 1389 | # kubectl rollout status ds daemon-set-primeiro 1390 | daemon set "daemon-set-primeiro" successfully rolled out 1391 | ``` 1392 | 1393 | ``` 1394 | # kubectl get pods 1395 | NAME READY STATUS RESTARTS AGE 1396 | daemon-set-primeiro-jzck9 1/1 Running 0 32s 1397 | daemon-set-primeiro-td7h5 1/1 Running 0 29s 1398 | daemon-set-primeiro-v5c86 1/1 Running 0 40s 1399 | ``` 1400 | 1401 | ``` 1402 | # kubectl describe pod daemon-set-primeiro-jzck9 | grep -i image: 1403 | Image: nginx:1.15.0 1404 | ``` 1405 | 1406 | 1407 | Agora vamos deletar nosso DaemonSet. 1408 | 1409 | 1410 | ``` 1411 | # kubectl delete ds daemon-set-primeiro 1412 | daemonset.extensions "daemon-set-primeiro" deleted 1413 | --------------------------------------------------------------------------------