├── .gitignore ├── Docker └── nodejs │ ├── app.Dockerfile │ └── base.Dockerfile ├── LICENSE ├── README.md ├── hard-way ├── 1.18.6 │ ├── README.md │ ├── Vagrantfile │ ├── config.yaml │ ├── lib │ │ ├── ha.rb │ │ ├── master.rb │ │ ├── node.rb │ │ └── trigger.rb │ └── script │ │ ├── bootstrap.sh │ │ ├── bootstrap_ha.sh │ │ ├── bootstrap_master.sh │ │ ├── bootstrap_node.sh │ │ ├── kube_config.sh │ │ └── provisioning.sh ├── 1.21.0 │ ├── README.md │ ├── Vagrantfile │ ├── config.yaml │ ├── lib │ │ ├── ha.rb │ │ ├── master.rb │ │ ├── node.rb │ │ └── trigger.rb │ └── script │ │ ├── bootstrap.sh │ │ ├── bootstrap_ha.sh │ │ ├── bootstrap_master.sh │ │ ├── bootstrap_node.sh │ │ ├── kube_config.sh │ │ └── provisioning.sh └── 1.21.1 │ ├── README.md │ ├── Vagrantfile │ ├── config.yaml │ ├── lib │ ├── ha.rb │ ├── master.rb │ ├── node.rb │ └── trigger.rb │ └── script │ ├── bootstrap.sh │ ├── bootstrap_ha.sh │ ├── bootstrap_master.sh │ ├── bootstrap_node.sh │ ├── kube_config.sh │ └── provisioning.sh ├── kubeadm-with-ca ├── centos │ ├── README.md │ ├── Vagrantfile │ ├── config.yaml │ ├── lib │ │ ├── master.rb │ │ ├── node.rb │ │ └── trigger.rb │ └── script │ │ ├── bootstrap.sh │ │ └── bootstrap_master.sh └── ubuntu │ ├── README.md │ ├── Vagrantfile │ ├── config.yaml │ ├── lib │ ├── master.rb │ ├── node.rb │ └── trigger.rb │ └── script │ ├── bootstrap.sh │ └── bootstrap_master.sh └── kubeadm ├── centos ├── README.md ├── Vagrantfile ├── config.yaml ├── lib │ ├── master.rb │ ├── node.rb │ └── trigger.rb └── script │ └── bootstrap.sh └── ubuntu ├── README.md ├── Vagrantfile ├── config.yaml ├── lib ├── master.rb ├── node.rb └── trigger.rb └── script └── bootstrap.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | .DS_Store/ 3 | .idea/ 4 | .DS_Store/ 5 | kubernetes/.vagrant/ 6 | kubernetes/.DS_Store 7 | kubernetes/.idea/ 8 | kubernetes/.DS_Store/ 9 | -------------------------------------------------------------------------------- /Docker/nodejs/app.Dockerfile: -------------------------------------------------------------------------------- 1 | ARG NODE_VERSION=12 2 | 3 | FROM nvm:node AS appbuild 4 | 5 | WORKDIR /usr/src/app 6 | 7 | ADD ["package.json", "src", "./"] 8 | 9 | RUN \ 10 | source /usr/local/nvm/nvm.sh && \ 11 | nvm install $NODE_VERSION && \ 12 | nvm use $NODE_VERSION && \ 13 | npm install && \ 14 | npm run build 15 | 16 | ENV PATH /usr/local/nvm/versions/node/v$NODE_VERSION/bin:$PATH 17 | 18 | 19 | FROM nvm:node 20 | 21 | WORKDIR /usr/src/app 22 | 23 | ADD ["package.json", "src", "./"] 24 | 25 | RUN \ 26 | source /usr/local/nvm/nvm.sh && \ 27 | nvm install $NODE_VERSION && \ 28 | nvm use $NODE_VERSION && \ 29 | npm install && \ 30 | npm run build 31 | 32 | COPY --from=appbuild /usr/src/app/dist ./dist 33 | 34 | EXPOSE 4002 35 | 36 | CMD npm start 37 | -------------------------------------------------------------------------------- /Docker/nodejs/base.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:latest 2 | 3 | # replace shell with bash so we can source files 4 | RUN rm /bin/sh && ln -s /bin/bash /bin/sh 5 | 6 | # and install dependencies 7 | RUN apt-get update \ 8 | && apt-get install -y curl ruby-full \ 9 | && apt-get -y autoclean 10 | 11 | # nvm environment variables 12 | ENV NVM_DIR /usr/local/nvm 13 | ENV NODE_VERSION 6.11.0 14 | 15 | RUN \ 16 | apt-get update && apt-get install -y build-essential libssl-dev python python3 gnupg2 && \ 17 | curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash && \ 18 | source /usr/local/nvm/nvm.sh 19 | 20 | CMD ["bash", "-l"] -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VAAS 2 | 3 | 4 | 5 | 6 | 7 | 8 | Vagrant As Automation Script 9 | 10 | DO SMART WORK RATHER THAN HARD WORK! 11 | 12 | ## Overview 13 | 14 | Welcome to the documentation for VAAS - the command line utility for managing the lifecycle of virtual machines. 15 | 16 | Automation for create/setup your POC/Working environment also for exam presentation like `CKA`, `CKAD`, `CKS`. 17 | 18 | `VAAS` helps you to make you by creating/setup your working Simulator or say POC/Work environment platform which will be ready for your work with minimum efforts. 19 | 20 | Every Vagarant file has its own configuration, just update as per your need and say `vagrant up` to start vm and setting up. It may take some time and as its completed you can follow the instructions under how to use section. 21 | 22 | ## Prerequisites 23 | 24 | This module requires [Vagrant](https://www.vagrantup.com/docs/installation) to pre-installed. 25 | And any virtual environment, defualt can use [oracle virtualbox](https://www.virtualbox.org/wiki/Downloads) 26 | 27 | ## Basic usage 28 | 29 | ### Command line 30 | 31 | To start working `VAAS`, very first clone under your workspace and change your path based on your need. 32 | For Example: Want to setup kubernetes cluster using centos base. 33 | 34 | ```bash 35 | cd 36 | git clone git@github.com:marthanda93/VAAS.git 37 | 38 | cd kubernetes/centos 39 | vagrant up 40 | ``` 41 | 42 | Once your `vagrant up` is complete, you can use below command line utility. 43 | 44 | ***To know about you vagarant environments / list down running VMs*** 45 | ```bash 46 | vagrant status 47 | ``` 48 | 49 | ***To SSH to VM*** 50 | ```bash 51 | vagrant ssh web 52 | ``` 53 | 54 | ***To shut down the virtual machine use the command:*** 55 | ```bash 56 | vagrant halt 57 | ``` 58 | 59 | For specific vm 60 | ```bash 61 | vagrant halt worker-node-2 62 | ``` 63 | 64 | ***To launch Vagrant using Amazon Web Services with:*** 65 | 66 | With default vm option 67 | ```bash 68 | vagrant up 69 | ``` 70 | 71 | With Vmware Fusion 72 | ```bash 73 | vagrant up –provider=vmware_fusion 74 | ``` 75 | 76 | Start specific vm 77 | ```bash 78 | vagrant up master-node 79 | ``` 80 | 81 | ***To remove all traces of the virtual machine from your system type in the following:*** 82 | For all VMs 83 | ```bash 84 | vagrant destroy -f 85 | ``` 86 | 87 | For specific VM 88 | ```bash 89 | vagrant destroy worker-node-1 -f 90 | ``` 91 | 92 | ***To stop the machine and save its current state run:*** 93 | ```bash 94 | vagrant suspend 95 | ``` 96 | 97 | ***To remove image*** 98 | ```bash 99 | vagrant box remove ubuntu/trusty64 100 | ``` 101 | -------------------------------------------------------------------------------- /hard-way/1.18.6/README.md: -------------------------------------------------------------------------------- 1 | # vagrant-kubernetes 2 | Kubernetes The Hard Way on Vagrant 3 | 4 | ## Big Thanks to kelseyhightower 5 | Most of steps taken from [kelseyhightower public repo](https://github.com/kelseyhightower/kubernetes-the-hard-way). 6 | Arranged accordingly to Vagrant with Virtualbox so that as you run `vagrant up` from `VAAS/kubernetes/hard-way` and wait for completion(it do everythings which is required to setup cluster), after that start using `kubectl` either from your host or any of vm expect `load balancer`. 7 | 8 | ```bash 9 | $ kubectl get cs 10 | NAME STATUS MESSAGE ERROR 11 | scheduler Healthy ok 12 | controller-manager Healthy ok 13 | etcd-3 Healthy {"health":"true"} 14 | etcd-0 Healthy {"health":"true"} 15 | etcd-1 Healthy {"health":"true"} 16 | ``` 17 | 18 | ```bash 19 | $ kubectl get nodes 20 | NAME STATUS ROLES AGE VERSION 21 | worker-1 Ready 88s v1.18.6 22 | worker-2 Ready 48s v1.18.6 23 | ``` 24 | 25 | ## Prerequisites 26 | This module requires [Vagrant](https://www.vagrantup.com/docs/installation) to pre-installed. 27 | And any virtual environment, defualt can use [oracle virtualbox](https://www.virtualbox.org/wiki/Downloads) 28 | 29 | To use kubernetes, can install `kubectl` to access cluster from host but can access via `ssh` to vritual machine also. 30 | 31 | ## Basic usage 32 | Very first `cd` to path where `Vagrant` file exists(`VAAS/kubernetes/hard-way`), and open `config.yaml` file to update setting before spin up cluster. 33 | 34 | ### Command line 35 | To start kubernetes cluster please follow below instructions: 36 | 37 | ```bash 38 | vagrant up 39 | ``` 40 | -------------------------------------------------------------------------------- /hard-way/1.18.6/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | require 'yaml' 5 | require 'open3' 6 | 7 | k8s = YAML.load_file(File.join(File.dirname(__FILE__), 'config.yaml')) 8 | ENV["LC_ALL"] = "en_US.UTF-8" 9 | 10 | msg = <> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{m}") 11 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['ha']) 12 | 13 | 1.step(k8s['resources']['master']['count']) do |n| 14 | next if m == n 15 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{n}") 16 | end 17 | 18 | 1.step(k8s['resources']['node']['count']) do |e| 19 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{e}") 20 | end 21 | 22 | # Push all required configs/certificates to master node 23 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no /opt/certificates/{encryption-config.yaml,kube-controller-manager.kubeconfig,kube-scheduler.kubeconfig,admin.kubeconfig,ca.pem,ca-key.pem,kubernetes-key.pem,kubernetes.pem,service-account-key.pem,service-account.pem} " + k8s['cluster']['master'] + "-#{m}" + ":~/certificates/' " + k8s['cluster']['ha']) 24 | # Start etcd on all controller 25 | system("vagrant ssh --no-tty -c 'sudo cp /home/vagrant/certificates/{ca.pem,kubernetes-key.pem,kubernetes.pem} /etc/etcd/; sudo cp /home/vagrant/certificates/{ca.pem,ca-key.pem,kubernetes-key.pem,kubernetes.pem,service-account-key.pem,service-account.pem,encryption-config.yaml} /var/lib/kubernetes/; sudo cp /home/vagrant/certificates/{kube-controller-manager.kubeconfig,kube-scheduler.kubeconfig} /var/lib/kubernetes/; sudo systemctl enable --now etcd; sudo systemctl enable --now kube-apiserver; sudo systemctl enable --now kube-controller-manager; sudo systemctl enable --now kube-scheduler; sudo systemctl enable --now nginx; mkdir -p /home/" + k8s['user'] + "/.kube; cp -i /home/" + k8s['user'] + "/certificates/admin.kubeconfig /home/" + k8s['user'] + "/.kube/config' " + k8s['cluster']['master'] + "-#{m}") 26 | end 27 | 28 | 1.step(k8s['resources']['node']['count']) do |m| 29 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 30 | system("vagrant ssh --no-tty -c 'echo \"#{lbpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 31 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['ha']) 32 | 33 | 1.step(k8s['resources']['node']['count']) do |n| 34 | next if m == n 35 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{n}") 36 | end 37 | 38 | 1.step(k8s['resources']['master']['count']) do |e| 39 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{e}") 40 | end 41 | 42 | # Push all required configs/certificates to worker node 43 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no /opt/certificates/{" + k8s['cluster']['node'] + "-#{m}.kubeconfig" + ",kube-proxy.kubeconfig,ca.pem,admin.kubeconfig," + k8s['cluster']['node'] + "-#{m}.pem," + k8s['cluster']['node'] + "-#{m}-key.pem} " + k8s['cluster']['node'] + "-#{m}" + ":~/certificates/' " + k8s['cluster']['ha']) 44 | # Bootstrapping the Kubernetes Worker Nodes 45 | system("vagrant ssh --no-tty -c 'sudo cp /home/vagrant/certificates/{" + k8s['cluster']['node'] + "-#{m}-key.pem," + k8s['cluster']['node'] + "-#{m}.pem} /var/lib/kubelet/; sudo cp /home/vagrant/certificates/" + k8s['cluster']['node'] + "-#{m}.kubeconfig /var/lib/kubelet/kubeconfig; sudo cp /home/vagrant/certificates/ca.pem /var/lib/kubernetes/; sudo cp /home/vagrant/certificates/kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig; sudo systemctl enable --now kubelet; sudo systemctl enable --now kube-proxy; sudo systemctl enable --now containerd; mkdir -p /home/" + k8s['user'] + "/.kube; cp -i /home/" + k8s['user'] + "/certificates/admin.kubeconfig /home/" + k8s['user'] + "/.kube/config' " + k8s['cluster']['node'] + "-#{m}") 46 | end 47 | 48 | system("vagrant ssh --no-tty -c 'kubectl apply --kubeconfig /home/vagrant/certificates/admin.kubeconfig -f /home/vagrant/certificates/cluster_role.yaml; kubectl apply --kubeconfig /home/vagrant/certificates/admin.kubeconfig -f /home/vagrant/certificates/cluster_role_binding.yaml' " + k8s['cluster']['master'] + "-1") 49 | 50 | # Configuring kubectl for Remote Access 51 | system("mkdir -p ${HOME}/.kube") 52 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/ca.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/ca.pem") 53 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/admin.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/admin.pem") 54 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/admin-key.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/admin-key.pem") 55 | system("kubectl config set-cluster kubernetes-the-hard-way --certificate-authority=${HOME}/.kube/ca.pem --embed-certs=true --server=https://#{k8s['ip_part']}.#{k8s['resources']['ha']['ip_prefix']}:6443 && kubectl config set-credentials admin --client-certificate=${HOME}/.kube/admin.pem --client-key=${HOME}/.kube/admin-key.pem && kubectl config set-context kubernetes-the-hard-way --cluster=kubernetes-the-hard-way --user=admin && kubectl config use-context kubernetes-the-hard-way") 56 | 57 | # Deploying the DNS Cluster Add-on 58 | system("kubectl apply -f https://storage.googleapis.com/kubernetes-the-hard-way/coredns-1.8.yaml") 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /hard-way/1.18.6/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cat < /etc/sysctl.d/k8s.conf 8 | net.bridge.bridge-nf-call-ip6tables = 1 9 | net.bridge.bridge-nf-call-iptables = 1 10 | net.ipv4.ip_forward = 1 11 | EOF 12 | sysctl --system 13 | 14 | # Disable all memory swaps to increase performance. 15 | sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 16 | swapoff -a 17 | 18 | # disable man-db installation 19 | { 20 | apt-get remove man-db --purge -y 21 | sudo rm -rf /usr/share/locale/ 22 | sudo rm -rf /usr/share/man/ 23 | sudo rm -rf /usr/share/doc/ 24 | 25 | cat > /etc/dpkg/dpkg.cfg.d/01_nodoc <> /etc/ssh/sshd_config 60 | -------------------------------------------------------------------------------- /hard-way/1.18.6/script/bootstrap_ha.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # disable man-db installation 4 | { 5 | apt-get remove man-db --purge -y 6 | sudo rm -rf /usr/share/locale/ 7 | sudo rm -rf /usr/share/man/ 8 | sudo rm -rf /usr/share/doc/ 9 | 10 | cat > /etc/dpkg/dpkg.cfg.d/01_nodoc <> /etc/ssh/sshd_config 65 | -------------------------------------------------------------------------------- /hard-way/1.18.6/script/bootstrap_master.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | apt-get update 4 | apt-get install -y nginx 5 | 6 | cat > kubernetes.default.svc.cluster.local < encryption-config.yaml < ca-config.json < ca-csr.json < admin-csr.json < ${instance}-csr.json < kube-controller-manager-csr.json < kube-proxy-csr.json < kube-scheduler-csr.json < kubernetes-csr.json < service-account-csr.json < 88s v1.18.6 22 | worker-2 Ready 48s v1.18.6 23 | ``` 24 | 25 | ## Prerequisites 26 | This module requires [Vagrant](https://www.vagrantup.com/docs/installation) to pre-installed. 27 | And any virtual environment, defualt can use [oracle virtualbox](https://www.virtualbox.org/wiki/Downloads) 28 | 29 | To use kubernetes, can install `kubectl` to access cluster from host but can access via `ssh` to vritual machine also. 30 | 31 | ## Basic usage 32 | Very first `cd` to path where `Vagrant` file exists(`VAAS/kubernetes/hard-way`), and open `config.yaml` file to update setting before spin up cluster. 33 | 34 | ### Command line 35 | To start kubernetes cluster please follow below instructions: 36 | 37 | ```bash 38 | vagrant up 39 | ``` 40 | -------------------------------------------------------------------------------- /hard-way/1.21.0/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | require 'yaml' 5 | require 'open3' 6 | 7 | k8s = YAML.load_file(File.join(File.dirname(__FILE__), 'config.yaml')) 8 | ENV["LC_ALL"] = "en_US.UTF-8" 9 | 10 | msg = <> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{m}") 11 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['ha']) 12 | 13 | 1.step(k8s['resources']['master']['count']) do |n| 14 | next if m == n 15 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{n}") 16 | end 17 | 18 | 1.step(k8s['resources']['node']['count']) do |e| 19 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{e}") 20 | end 21 | 22 | # Push all required configs/certificates to master node 23 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no /opt/certificates/{encryption-config.yaml,kube-controller-manager.kubeconfig,kube-scheduler.kubeconfig,admin.kubeconfig,ca.pem,ca-key.pem,kubernetes-key.pem,kubernetes.pem,service-account-key.pem,service-account.pem} " + k8s['cluster']['master'] + "-#{m}" + ":~/certificates/' " + k8s['cluster']['ha']) 24 | # Start etcd on all controller 25 | system("vagrant ssh --no-tty -c 'sudo cp /home/vagrant/certificates/{ca.pem,kubernetes-key.pem,kubernetes.pem} /etc/etcd/; sudo cp /home/vagrant/certificates/{ca.pem,ca-key.pem,kubernetes-key.pem,kubernetes.pem,service-account-key.pem,service-account.pem,encryption-config.yaml} /var/lib/kubernetes/; sudo cp /home/vagrant/certificates/{kube-controller-manager.kubeconfig,kube-scheduler.kubeconfig} /var/lib/kubernetes/; sudo systemctl enable --now etcd; sudo systemctl enable --now kube-apiserver; sudo systemctl enable --now kube-controller-manager; sudo systemctl enable --now kube-scheduler; sudo systemctl enable --now nginx; mkdir -p /home/" + k8s['user'] + "/.kube; cp -i /home/" + k8s['user'] + "/certificates/admin.kubeconfig /home/" + k8s['user'] + "/.kube/config' " + k8s['cluster']['master'] + "-#{m}") 26 | end 27 | 28 | 1.step(k8s['resources']['node']['count']) do |m| 29 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 30 | system("vagrant ssh --no-tty -c 'echo \"#{lbpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 31 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['ha']) 32 | 33 | 1.step(k8s['resources']['node']['count']) do |n| 34 | next if m == n 35 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{n}") 36 | end 37 | 38 | 1.step(k8s['resources']['master']['count']) do |e| 39 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{e}") 40 | end 41 | 42 | # Push all required configs/certificates to worker node 43 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no /opt/certificates/{" + k8s['cluster']['node'] + "-#{m}.kubeconfig" + ",kube-proxy.kubeconfig,ca.pem,admin.kubeconfig," + k8s['cluster']['node'] + "-#{m}.pem," + k8s['cluster']['node'] + "-#{m}-key.pem} " + k8s['cluster']['node'] + "-#{m}" + ":~/certificates/' " + k8s['cluster']['ha']) 44 | # Bootstrapping the Kubernetes Worker Nodes 45 | system("vagrant ssh --no-tty -c 'sudo cp /home/vagrant/certificates/{" + k8s['cluster']['node'] + "-#{m}-key.pem," + k8s['cluster']['node'] + "-#{m}.pem} /var/lib/kubelet/; sudo cp /home/vagrant/certificates/" + k8s['cluster']['node'] + "-#{m}.kubeconfig /var/lib/kubelet/kubeconfig; sudo cp /home/vagrant/certificates/ca.pem /var/lib/kubernetes/; sudo cp /home/vagrant/certificates/kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig; sudo systemctl enable --now kubelet; sudo systemctl enable --now kube-proxy; sudo systemctl enable --now containerd; mkdir -p /home/" + k8s['user'] + "/.kube; cp -i /home/" + k8s['user'] + "/certificates/admin.kubeconfig /home/" + k8s['user'] + "/.kube/config' " + k8s['cluster']['node'] + "-#{m}") 46 | end 47 | 48 | system("vagrant ssh --no-tty -c 'kubectl apply --kubeconfig /home/vagrant/certificates/admin.kubeconfig -f /home/vagrant/certificates/cluster_role.yaml; kubectl apply --kubeconfig /home/vagrant/certificates/admin.kubeconfig -f /home/vagrant/certificates/cluster_role_binding.yaml' " + k8s['cluster']['master'] + "-1") 49 | 50 | # Configuring kubectl for Remote Access 51 | system("mkdir -p ${HOME}/.kube") 52 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/ca.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/ca.pem") 53 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/admin.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/admin.pem") 54 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/admin-key.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/admin-key.pem") 55 | system("kubectl config set-cluster kubernetes-the-hard-way --certificate-authority=${HOME}/.kube/ca.pem --embed-certs=true --server=https://#{k8s['ip_part']}.#{k8s['resources']['ha']['ip_prefix']}:6443 && kubectl config set-credentials admin --client-certificate=${HOME}/.kube/admin.pem --client-key=${HOME}/.kube/admin-key.pem && kubectl config set-context kubernetes-the-hard-way --cluster=kubernetes-the-hard-way --user=admin && kubectl config use-context kubernetes-the-hard-way") 56 | 57 | # Deploying the DNS Cluster Add-on 58 | system("kubectl apply -f https://storage.googleapis.com/kubernetes-the-hard-way/coredns-1.8.yaml") 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /hard-way/1.21.0/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cat < /etc/sysctl.d/k8s.conf 8 | net.bridge.bridge-nf-call-ip6tables = 1 9 | net.bridge.bridge-nf-call-iptables = 1 10 | net.ipv4.ip_forward = 1 11 | EOF 12 | sysctl --system 13 | 14 | # Disable all memory swaps to increase performance. 15 | sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 16 | swapoff -a 17 | 18 | # disable man-db installation 19 | { 20 | apt-get remove man-db --purge -y 21 | sudo rm -rf /usr/share/locale/ 22 | sudo rm -rf /usr/share/man/ 23 | sudo rm -rf /usr/share/doc/ 24 | 25 | cat > /etc/dpkg/dpkg.cfg.d/01_nodoc <> /etc/ssh/sshd_config 60 | -------------------------------------------------------------------------------- /hard-way/1.21.0/script/bootstrap_ha.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # disable man-db installation 4 | { 5 | apt-get remove man-db --purge -y 6 | sudo rm -rf /usr/share/locale/ 7 | sudo rm -rf /usr/share/man/ 8 | sudo rm -rf /usr/share/doc/ 9 | 10 | cat > /etc/dpkg/dpkg.cfg.d/01_nodoc <> /etc/ssh/sshd_config 65 | -------------------------------------------------------------------------------- /hard-way/1.21.0/script/bootstrap_master.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | apt-get update 4 | apt-get install -y nginx 5 | 6 | cat > kubernetes.default.svc.cluster.local < encryption-config.yaml < ca-config.json < ca-csr.json < admin-csr.json < ${instance}-csr.json < kube-controller-manager-csr.json < kube-proxy-csr.json < kube-scheduler-csr.json < kubernetes-csr.json < service-account-csr.json < 88s v1.18.6 22 | worker-2 Ready 48s v1.18.6 23 | ``` 24 | 25 | ## Prerequisites 26 | This module requires [Vagrant](https://www.vagrantup.com/docs/installation) to pre-installed. 27 | And any virtual environment, defualt can use [oracle virtualbox](https://www.virtualbox.org/wiki/Downloads) 28 | 29 | To use kubernetes, can install `kubectl` to access cluster from host but can access via `ssh` to vritual machine also. 30 | 31 | ## Basic usage 32 | Very first `cd` to path where `Vagrant` file exists(`VAAS/kubernetes/hard-way`), and open `config.yaml` file to update setting before spin up cluster. 33 | 34 | ### Command line 35 | To start kubernetes cluster please follow below instructions: 36 | 37 | ```bash 38 | vagrant up 39 | ``` 40 | -------------------------------------------------------------------------------- /hard-way/1.21.1/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | require 'yaml' 5 | require 'open3' 6 | 7 | k8s = YAML.load_file(File.join(File.dirname(__FILE__), 'config.yaml')) 8 | ENV["LC_ALL"] = "en_US.UTF-8" 9 | 10 | msg = <> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{m}") 11 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['ha']) 12 | 13 | 1.step(k8s['resources']['master']['count']) do |n| 14 | next if m == n 15 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{n}") 16 | end 17 | 18 | 1.step(k8s['resources']['node']['count']) do |e| 19 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{e}") 20 | end 21 | 22 | # Push all required configs/certificates to master node 23 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no /opt/certificates/{encryption-config.yaml,kube-controller-manager.kubeconfig,kube-scheduler.kubeconfig,admin.kubeconfig,ca.pem,ca-key.pem,kubernetes-key.pem,kubernetes.pem,service-account-key.pem,service-account.pem} " + k8s['cluster']['master'] + "-#{m}" + ":~/certificates/' " + k8s['cluster']['ha']) 24 | # Start etcd on all controller 25 | system("vagrant ssh --no-tty -c 'sudo cp /home/vagrant/certificates/{ca.pem,kubernetes-key.pem,kubernetes.pem} /etc/etcd/; sudo cp /home/vagrant/certificates/{ca.pem,ca-key.pem,kubernetes-key.pem,kubernetes.pem,service-account-key.pem,service-account.pem,encryption-config.yaml} /var/lib/kubernetes/; sudo cp /home/vagrant/certificates/{kube-controller-manager.kubeconfig,kube-scheduler.kubeconfig} /var/lib/kubernetes/; sudo systemctl enable --now etcd; sudo systemctl enable --now kube-apiserver; sudo systemctl enable --now kube-controller-manager; sudo systemctl enable --now kube-scheduler; sudo systemctl enable --now nginx; mkdir -p /home/" + k8s['user'] + "/.kube; cp -i /home/" + k8s['user'] + "/certificates/admin.kubeconfig /home/" + k8s['user'] + "/.kube/config' " + k8s['cluster']['master'] + "-#{m}") 26 | end 27 | 28 | 1.step(k8s['resources']['node']['count']) do |m| 29 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 30 | system("vagrant ssh --no-tty -c 'echo \"#{lbpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 31 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['ha']) 32 | 33 | 1.step(k8s['resources']['node']['count']) do |n| 34 | next if m == n 35 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{n}") 36 | end 37 | 38 | 1.step(k8s['resources']['master']['count']) do |e| 39 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master'] + "-#{e}") 40 | end 41 | 42 | # Push all required configs/certificates to worker node 43 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no /opt/certificates/{" + k8s['cluster']['node'] + "-#{m}.kubeconfig" + ",kube-proxy.kubeconfig,ca.pem,admin.kubeconfig," + k8s['cluster']['node'] + "-#{m}.pem," + k8s['cluster']['node'] + "-#{m}-key.pem} " + k8s['cluster']['node'] + "-#{m}" + ":~/certificates/' " + k8s['cluster']['ha']) 44 | # Bootstrapping the Kubernetes Worker Nodes 45 | system("vagrant ssh --no-tty -c 'sudo cp /home/vagrant/certificates/{" + k8s['cluster']['node'] + "-#{m}-key.pem," + k8s['cluster']['node'] + "-#{m}.pem} /var/lib/kubelet/; sudo cp /home/vagrant/certificates/" + k8s['cluster']['node'] + "-#{m}.kubeconfig /var/lib/kubelet/kubeconfig; sudo cp /home/vagrant/certificates/ca.pem /var/lib/kubernetes/; sudo cp /home/vagrant/certificates/kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig; sudo systemctl enable --now kubelet; sudo systemctl enable --now kube-proxy; sudo systemctl enable --now containerd; mkdir -p /home/" + k8s['user'] + "/.kube; cp -i /home/" + k8s['user'] + "/certificates/admin.kubeconfig /home/" + k8s['user'] + "/.kube/config' " + k8s['cluster']['node'] + "-#{m}") 46 | end 47 | 48 | system("vagrant ssh --no-tty -c 'kubectl apply --kubeconfig /home/vagrant/certificates/admin.kubeconfig -f /home/vagrant/certificates/cluster_role.yaml; kubectl apply --kubeconfig /home/vagrant/certificates/admin.kubeconfig -f /home/vagrant/certificates/cluster_role_binding.yaml' " + k8s['cluster']['master'] + "-1") 49 | 50 | # Configuring kubectl for Remote Access 51 | system("mkdir -p ${HOME}/.kube") 52 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/ca.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/ca.pem") 53 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/admin.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/admin.pem") 54 | system("vagrant ssh --no-tty -c 'cat /opt/certificates/admin-key.pem' " + k8s['cluster']['ha'] + " > ${HOME}/.kube/admin-key.pem") 55 | system("kubectl config set-cluster kubernetes-the-hard-way --certificate-authority=${HOME}/.kube/ca.pem --embed-certs=true --server=https://#{k8s['ip_part']}.#{k8s['resources']['ha']['ip_prefix']}:6443 && kubectl config set-credentials admin --client-certificate=${HOME}/.kube/admin.pem --client-key=${HOME}/.kube/admin-key.pem && kubectl config set-context kubernetes-the-hard-way --cluster=kubernetes-the-hard-way --user=admin && kubectl config use-context kubernetes-the-hard-way") 56 | 57 | # Deploying the DNS Cluster Add-on 58 | system("kubectl apply -f https://storage.googleapis.com/kubernetes-the-hard-way/coredns-1.8.yaml") 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /hard-way/1.21.1/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cat < /etc/sysctl.d/k8s.conf 8 | net.bridge.bridge-nf-call-ip6tables = 1 9 | net.bridge.bridge-nf-call-iptables = 1 10 | net.ipv4.ip_forward = 1 11 | EOF 12 | sysctl --system 13 | 14 | # Disable all memory swaps to increase performance. 15 | sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 16 | swapoff -a 17 | 18 | # disable man-db installation 19 | { 20 | apt-get remove man-db --purge -y 21 | sudo rm -rf /usr/share/locale/ 22 | sudo rm -rf /usr/share/man/ 23 | sudo rm -rf /usr/share/doc/ 24 | 25 | cat > /etc/dpkg/dpkg.cfg.d/01_nodoc <> /etc/ssh/sshd_config 60 | -------------------------------------------------------------------------------- /hard-way/1.21.1/script/bootstrap_ha.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # disable man-db installation 4 | { 5 | apt-get remove man-db --purge -y 6 | sudo rm -rf /usr/share/locale/ 7 | sudo rm -rf /usr/share/man/ 8 | sudo rm -rf /usr/share/doc/ 9 | 10 | cat > /etc/dpkg/dpkg.cfg.d/01_nodoc <> /etc/ssh/sshd_config 65 | -------------------------------------------------------------------------------- /hard-way/1.21.1/script/bootstrap_master.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | apt-get update 4 | apt-get install -y nginx 5 | 6 | cat > kubernetes.default.svc.cluster.local < encryption-config.yaml < ca-config.json < ca-csr.json < admin-csr.json < ${instance}-csr.json < kube-controller-manager-csr.json < kube-proxy-csr.json < kube-scheduler-csr.json < kubernetes-csr.json < service-account-csr.json <> $HOME/.bash_profile' #{k8s['cluster']['master']}") 13 | system("vagrant ssh --no-tty -c 'sudo chown #{k8s['user']} /etc/kubernetes/admin.conf' #{k8s['cluster']['master']}") 14 | system('vagrant ssh --no-tty -c \'echo "export KUBEADM_JOIN=\"'+ kubeadm_join.strip + '\"" >> /home/vagrant/.bash_profile\' ' + k8s['cluster']['master']) 15 | system("vagrant ssh --no-tty -c 'kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml' #{k8s['cluster']['master']}") 16 | 17 | 1.step(k8s['resources']['node']['count']) do |m| 18 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 19 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master']) 20 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 21 | 22 | system("vagrant ssh --no-tty -c 'sudo #{kubeadm_join}' " + k8s['cluster']['node'] + "-#{m}") 23 | system("vagrant ssh --no-tty -c 'mkdir -p /home/#{k8s['user']}/.kube' " + k8s['cluster']['node'] + "-#{m}") 24 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no #{k8s['user']}@#{k8s['cluster']['master']}:/etc/kubernetes/admin.conf /home/#{k8s['user']}/.kube/' " + k8s['cluster']['node'] + "-#{m}") 25 | system("vagrant ssh --no-tty -c 'echo \"export KUBECONFIG=\${HOME}/.kube/admin.conf\" >> /home/#{k8s['user']}/.bash_profile' #{k8s['cluster']['node']}" + "-#{m}") 26 | system("vagrant ssh --no-tty -c 'kubectl label nodes #{k8s['cluster']['node']}-#{m} kubernetes.io/role=#{k8s['cluster']['node']}-#{m}' " + k8s['cluster']['node'] + "-#{m}") 27 | end 28 | 29 | system("vagrant ssh --no-tty -c 'cat /etc/kubernetes/admin.conf' #{k8s['cluster']['master']} > admin.conf && rm -f \${HOME}/.kube/config 2>/dev/null; mkdir -p \${HOME}/.kube; cp -i admin.conf \${HOME}/.kube/config; rm -f admin.conf") 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /kubeadm-with-ca/centos/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | tee /etc/yum.repos.d/kubernetes.repo< /etc/sysctl.d/k8s.conf 50 | net.bridge.bridge-nf-call-ip6tables = 1 51 | net.bridge.bridge-nf-call-iptables = 1 52 | net.ipv4.ip_forward = 1 53 | EOF 54 | sysctl --system 55 | 56 | # Disable all memory swaps to increase performance. 57 | sed -i '/swap/d' /etc/fstab 58 | swapoff -a 59 | 60 | echo "ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa << ca-config.json < ca-csr.json <> $HOME/.bash_profile' #{k8s['cluster']['master']}") 13 | system("vagrant ssh --no-tty -c 'sudo chown #{k8s['user']} /etc/kubernetes/admin.conf' #{k8s['cluster']['master']}") 14 | system('vagrant ssh --no-tty -c \'echo "export KUBEADM_JOIN=\"'+ kubeadm_join.strip + '\"" >> /home/vagrant/.bash_profile\' ' + k8s['cluster']['master']) 15 | system("vagrant ssh --no-tty -c 'kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml' #{k8s['cluster']['master']}") 16 | 17 | 1.step(k8s['resources']['node']['count']) do |m| 18 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 19 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master']) 20 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 21 | 22 | system("vagrant ssh --no-tty -c 'sudo #{kubeadm_join}' " + k8s['cluster']['node'] + "-#{m}") 23 | system("vagrant ssh --no-tty -c 'mkdir -p /home/#{k8s['user']}/.kube' " + k8s['cluster']['node'] + "-#{m}") 24 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no #{k8s['user']}@#{k8s['cluster']['master']}:/etc/kubernetes/admin.conf /home/#{k8s['user']}/.kube/' " + k8s['cluster']['node'] + "-#{m}") 25 | system("vagrant ssh --no-tty -c 'echo \"export KUBECONFIG=\${HOME}/.kube/admin.conf\" >> /home/#{k8s['user']}/.bash_profile' #{k8s['cluster']['node']}" + "-#{m}") 26 | system("vagrant ssh --no-tty -c 'kubectl label nodes #{k8s['cluster']['node']}-#{m} kubernetes.io/role=#{k8s['cluster']['node']}-#{m}' " + k8s['cluster']['node'] + "-#{m}") 27 | end 28 | 29 | system("vagrant ssh --no-tty -c 'cat /etc/kubernetes/admin.conf' #{k8s['cluster']['master']} > admin.conf && rm -f \${HOME}/.kube/config 2>/dev/null; mkdir -p \${HOME}/.kube; cp -i admin.conf \${HOME}/.kube/config; rm -f admin.conf") 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /kubeadm-with-ca/ubuntu/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cat < /etc/sysctl.d/k8s.conf 8 | net.bridge.bridge-nf-call-ip6tables = 1 9 | net.bridge.bridge-nf-call-iptables = 1 10 | net.ipv4.ip_forward = 1 11 | EOF 12 | sysctl --system 13 | 14 | # Disable all memory swaps to increase performance. 15 | sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 16 | swapoff -a 17 | 18 | apt-get update 19 | apt-get install -y apt-transport-https ca-certificates curl wget zip unzip vim git gnupg lsb-release software-properties-common telnet 20 | curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg 21 | echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list 22 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 23 | add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 24 | apt-get update 25 | apt-get install -y kubelet kubeadm kubectl docker-ce docker-ce-cli containerd.io 26 | apt-mark hold kubelet kubeadm kubectl 27 | usermod -aG docker ${1} 28 | 29 | cat < ca-config.json < ca-csr.json <> $HOME/.bash_profile' #{k8s['cluster']['master']}") 13 | system("vagrant ssh --no-tty -c 'sudo chown #{k8s['user']} /etc/kubernetes/admin.conf' #{k8s['cluster']['master']}") 14 | system('vagrant ssh --no-tty -c \'echo "export KUBEADM_JOIN=\"'+ kubeadm_join.strip + '\"" >> /home/vagrant/.bash_profile\' master-node') 15 | system("vagrant ssh --no-tty -c 'kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml' #{k8s['cluster']['master']}") 16 | 17 | 1.step(k8s['resources']['node']['count']) do |m| 18 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 19 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master']) 20 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 21 | 22 | system("vagrant ssh --no-tty -c 'sudo #{kubeadm_join}' " + k8s['cluster']['node'] + "-#{m}") 23 | system("vagrant ssh --no-tty -c 'mkdir -p /home/#{k8s['user']}/.kube' " + k8s['cluster']['node'] + "-#{m}") 24 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no #{k8s['user']}@#{k8s['cluster']['master']}:/etc/kubernetes/admin.conf /home/#{k8s['user']}/.kube/' " + k8s['cluster']['node'] + "-#{m}") 25 | system("vagrant ssh --no-tty -c 'echo \"export KUBECONFIG=\${HOME}/.kube/admin.conf\" >> /home/#{k8s['user']}/.bash_profile' #{k8s['cluster']['node']}" + "-#{m}") 26 | system("vagrant ssh --no-tty -c 'kubectl label nodes #{k8s['cluster']['node']}-#{m} kubernetes.io/role=#{k8s['cluster']['node']}-#{m}' " + k8s['cluster']['node'] + "-#{m}") 27 | end 28 | 29 | system("vagrant ssh --no-tty -c 'cat /etc/kubernetes/admin.conf' #{k8s['cluster']['master']} > admin.conf && rm -f \${HOME}/.kube/config 2>/dev/null; mkdir -p \${HOME}/.kube; cp -i admin.conf \${HOME}/.kube/config; rm -f admin.conf") 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /kubeadm/centos/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | tee /etc/yum.repos.d/kubernetes.repo< /etc/sysctl.d/k8s.conf 50 | net.bridge.bridge-nf-call-ip6tables = 1 51 | net.bridge.bridge-nf-call-iptables = 1 52 | net.ipv4.ip_forward = 1 53 | EOF 54 | sysctl --system 55 | 56 | # Disable all memory swaps to increase performance. 57 | sed -i '/swap/d' /etc/fstab 58 | swapoff -a 59 | 60 | echo "ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa <<> $HOME/.bash_profile' #{k8s['cluster']['master']}") 13 | system("vagrant ssh --no-tty -c 'sudo chown #{k8s['user']} /etc/kubernetes/admin.conf' #{k8s['cluster']['master']}") 14 | system('vagrant ssh --no-tty -c \'echo "export KUBEADM_JOIN=\"'+ kubeadm_join.strip + '\"" >> /home/vagrant/.bash_profile\' master-node') 15 | system("vagrant ssh --no-tty -c 'kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml' #{k8s['cluster']['master']}") 16 | 17 | 1.step(k8s['resources']['node']['count']) do |m| 18 | wpub, stdeerr, status = Open3.capture3("vagrant ssh --no-tty -c 'cat /home/" + k8s['user'] + "/.ssh/id_rsa.pub' " + k8s['cluster']['node'] + "-#{m}") 19 | system("vagrant ssh --no-tty -c 'echo \"#{wpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['master']) 20 | system("vagrant ssh --no-tty -c 'echo \"#{mpub}\" >> /home/" + k8s['user'] + "/.ssh/authorized_keys' " + k8s['cluster']['node'] + "-#{m}") 21 | 22 | system("vagrant ssh --no-tty -c 'sudo #{kubeadm_join}' " + k8s['cluster']['node'] + "-#{m}") 23 | system("vagrant ssh --no-tty -c 'mkdir -p /home/#{k8s['user']}/.kube' " + k8s['cluster']['node'] + "-#{m}") 24 | system("vagrant ssh --no-tty -c 'scp -o StrictHostKeyChecking=no #{k8s['user']}@#{k8s['cluster']['master']}:/etc/kubernetes/admin.conf /home/#{k8s['user']}/.kube/' " + k8s['cluster']['node'] + "-#{m}") 25 | system("vagrant ssh --no-tty -c 'echo \"export KUBECONFIG=\${HOME}/.kube/admin.conf\" >> /home/#{k8s['user']}/.bash_profile' #{k8s['cluster']['node']}" + "-#{m}") 26 | system("vagrant ssh --no-tty -c 'kubectl label nodes #{k8s['cluster']['node']}-#{m} kubernetes.io/role=#{k8s['cluster']['node']}-#{m}' " + k8s['cluster']['node'] + "-#{m}") 27 | end 28 | 29 | system("vagrant ssh --no-tty -c 'cat /etc/kubernetes/admin.conf' #{k8s['cluster']['master']} > admin.conf && rm -f \${HOME}/.kube/config 2>/dev/null; mkdir -p \${HOME}/.kube; cp -i admin.conf \${HOME}/.kube/config; rm -f admin.conf") 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /kubeadm/ubuntu/script/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cat < /etc/sysctl.d/k8s.conf 8 | net.bridge.bridge-nf-call-ip6tables = 1 9 | net.bridge.bridge-nf-call-iptables = 1 10 | net.ipv4.ip_forward = 1 11 | EOF 12 | sysctl --system 13 | 14 | # Disable all memory swaps to increase performance. 15 | sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 16 | swapoff -a 17 | 18 | apt-get update 19 | apt-get install -y apt-transport-https ca-certificates curl wget zip unzip vim git gnupg lsb-release software-properties-common telnet 20 | curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg 21 | echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list 22 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 23 | add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 24 | apt-get update 25 | apt-get install -y kubelet kubeadm kubectl docker-ce docker-ce-cli containerd.io 26 | apt-mark hold kubelet kubeadm kubectl 27 | usermod -aG docker ${1} 28 | 29 | cat <