├── LICENSE ├── README.md ├── app ├── Dockerfile ├── build-container ├── cloudbuild.yaml └── main.go ├── configurator ├── Dockerfile ├── build-container ├── cloudbuild.yaml ├── configurator └── main.go ├── kubelet.service └── pods ├── app-v0.1.0.yaml └── app-v0.2.0.yaml /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Standalone Kubelet Tutorial 2 | 3 | This tutorial will guide you through running the Kubernetes [Kubelet](https://kubernetes.io/docs/admin/kubelet/) in standalone mode on [Container Linux](https://coreos.com/why). You will also deploy an application using a [static pod](https://kubernetes.io/docs/tasks/administer-cluster/static-pod/), test it, then upgrade the application. 4 | 5 | ## Rationale 6 | 7 | In some cases you just want to run one or more compute instances without the need for the entire Kubernetes feature set. There are many options for managing containers on a single compute instance including [docker compose](https://docs.docker.com/compose/), or some configuration management tool like [ansible](https://www.ansible.com/) or [chef](https://www.chef.io/chef/), however the Kubernetes Kubelet running in standalone mode may be the better option. In standalone mode the Kubelet allows you to manage containers using [pod manifests](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/), which brings the benefits of running tightly coupled application as a single unit while leveraging a subset of advanced features including init containers, CNI networking, and built-in health checks. 8 | 9 | Running the Kubelet in standalone mode provides a nice on-ramp to a full Kubernetes cluster; if the time comes your pod manifests can be reused. 10 | 11 | ## Compute Instance 12 | 13 | Create the `standalone-kubelet` compute instance: 14 | 15 | ``` 16 | gcloud compute instances create standalone-kubelet \ 17 | --async \ 18 | --boot-disk-size 200 \ 19 | --can-ip-forward \ 20 | --image-family coreos-stable \ 21 | --image-project coreos-cloud \ 22 | --machine-type n1-standard-1 \ 23 | --tags standalone-kubelet 24 | ``` 25 | 26 | Allow HTTP traffic to the `standalone-kubelet` instance: 27 | 28 | ``` 29 | gcloud compute firewall-rules create allow-standalone-kubelet \ 30 | --allow tcp:80 \ 31 | --target-tags standalone-kubelet 32 | ``` 33 | 34 | ## Install the Standalone Kubelet 35 | 36 | SSH into the `standalone-kubelet` compute instance: 37 | 38 | ``` 39 | gcloud compute ssh standalone-kubelet 40 | ``` 41 | 42 | Download the Kubelet systemd unit file: 43 | 44 | ``` 45 | wget -q --show-progress --https-only --timestamping \ 46 | https://raw.githubusercontent.com/kelseyhightower/standalone-kubelet-tutorial/master/kubelet.service 47 | ``` 48 | 49 | Move the `kubelet.service` unit file to the systemd configuration directory: 50 | 51 | ``` 52 | sudo mv kubelet.service /etc/systemd/system/ 53 | ``` 54 | 55 | Start the `kubelet` service: 56 | 57 | ``` 58 | sudo systemctl daemon-reload 59 | ``` 60 | 61 | ``` 62 | sudo systemctl enable kubelet 63 | ``` 64 | 65 | ``` 66 | sudo systemctl start kubelet 67 | ``` 68 | 69 | ### Verification 70 | 71 | It will take a few minutes for the `kubelet` container to download and initialize. Verify the `kubelet` is running: 72 | 73 | ``` 74 | sudo systemctl status kubelet 75 | ``` 76 | 77 | ## Static Pods 78 | 79 | In this section you will deploy an application that responds to HTTP requests with its running config and version. The application configuration will be initialized before the HTTP service starts by using an [init container](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/). Once the pod has started the application configuration will be updated every 30 seconds by a configuration sidecar. 80 | 81 | SSH into the `standalone-kubelet` compute instance: 82 | 83 | ``` 84 | gcloud compute ssh standalone-kubelet 85 | ``` 86 | 87 | Verify no containers are running: 88 | 89 | ``` 90 | sudo docker ps 91 | ``` 92 | 93 | Verify no container images are installed: 94 | 95 | ``` 96 | sudo docker images 97 | ``` 98 | 99 | Create the kubelet manifests directory: 100 | 101 | ``` 102 | sudo mkdir -p /etc/kubernetes/manifests 103 | ``` 104 | 105 | Download the `app-v0.1.0.yaml` pod manifest: 106 | 107 | ``` 108 | wget -q --show-progress --https-only --timestamping \ 109 | https://raw.githubusercontent.com/kelseyhightower/standalone-kubelet-tutorial/master/pods/app-v0.1.0.yaml 110 | ``` 111 | 112 | Move the `app-v0.1.0.yaml` pod manifest to the kubelet manifest directory: 113 | 114 | ``` 115 | sudo mv app-v0.1.0.yaml /etc/kubernetes/manifests/app.yaml 116 | ``` 117 | 118 | > Notice the `app-v0.1.0.yaml` pod manifest is being renamed to `app.yaml`. This prevents our application from being deployed twice. Each pod must have a unique `metadata.name`. 119 | 120 | List the installed container images: 121 | 122 | ``` 123 | sudo docker images 124 | ``` 125 | ``` 126 | REPOSITORY TAG IMAGE ID CREATED SIZE 127 | gcr.io/hightowerlabs/app 0.1.0 c7d7002a0776 23 minutes ago 6.325 MB 128 | gcr.io/hightowerlabs/configurator 0.1.0 164e54187008 4 hours ago 2.346 MB 129 | gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 16 months ago 746.9 kB 130 | ``` 131 | 132 | List the running containers: 133 | 134 | ``` 135 | docker ps 136 | ``` 137 | 138 | > You should see three containers running which represent the `app` pod. Docker does not understand pods so the containers are listed as individual containers following the Kubernetes naming convention. 139 | 140 | ### Verification 141 | 142 | At this point the `app` pod is up and running on port 80 in the host namespace. Make a HTTP request to the `app` pod using the localhost address: 143 | 144 | ``` 145 | curl http://127.0.0.1 146 | ``` 147 | 148 | ``` 149 | version: 0.1.0 150 | hostname: standalone-kubelet.c.hightowerlabs.internal 151 | key: 1506065606 152 | ``` 153 | 154 | Wait about 30 seconds and make another HTTP request to the `app` pod: 155 | 156 | ``` 157 | curl http://127.0.0.1 158 | ``` 159 | 160 | ``` 161 | version: 0.1.0 162 | hostname: standalone-kubelet.c.hightowerlabs.internal 163 | key: 1506065636 164 | ``` 165 | 166 | > Notice the `key` field has changed. This configuration setting is being updated by the `configurator` sidecar container running in the `app` pod. 167 | 168 | ### Testing Remote Access 169 | 170 | The `app` pod is listening on `0.0.0.0:80` in the host network and is accessible via the external IP of the `standalone-kubelet` compute instance. 171 | 172 | Get the external IP of the `standalone-kubelet` instance: 173 | 174 | ``` 175 | EXTERNAL_IP=$(gcloud compute instances describe standalone-kubelet \ 176 | --format 'value(networkInterfaces[0].accessConfigs[0].natIP)') 177 | ``` 178 | 179 | Make a HTTP request to the `app` pod using the `standalone-kubelet` external IP address: 180 | 181 | ``` 182 | curl http://${EXTERNAL_IP} 183 | ``` 184 | 185 | ``` 186 | version: 0.1.0 187 | hostname: standalone-kubelet.c.hightowerlabs.internal 188 | key: 1506065696 189 | ``` 190 | 191 | ## Updating Static Pods 192 | 193 | ``` 194 | gcloud compute ssh standalone-kubelet 195 | ``` 196 | 197 | Download the `app-v0.2.0.yaml` pod manifest: 198 | 199 | ``` 200 | wget -q --show-progress --https-only --timestamping \ 201 | https://raw.githubusercontent.com/kelseyhightower/standalone-kubelet-tutorial/master/pods/app-v0.2.0.yaml 202 | ``` 203 | 204 | Move the `app-v0.2.0.yaml` pod manifest to the kubelet manifest directory: 205 | 206 | ``` 207 | sudo mv app-v0.2.0.yaml /etc/kubernetes/manifests/app.yaml 208 | ``` 209 | 210 | > Notice the `app-v0.2.0.yaml` is being renamed to `app.yaml`. This overwrites the current pod manifest and will force the kubelet upgrade the `app` pod. 211 | 212 | List the installed container images: 213 | 214 | ``` 215 | docker images 216 | ``` 217 | ``` 218 | REPOSITORY TAG IMAGE ID CREATED SIZE 219 | gcr.io/hightowerlabs/app 0.1.0 c7d7002a0776 30 minutes ago 6.325 MB 220 | gcr.io/hightowerlabs/app 0.2.0 3028d4a68eb1 31 minutes ago 6.325 MB 221 | gcr.io/hightowerlabs/configurator 0.1.0 164e54187008 4 hours ago 2.346 MB 222 | gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 16 months ago 746.9 kB 223 | ``` 224 | 225 | > Notice the `gcr.io/hightowerlabs/app:0.2.0` image has been added to the local repository. 226 | 227 | ### Verification 228 | 229 | At this point `app` version `0.2.0` is up and running. Make a HTTP request to the `app` pod using the localhost address: 230 | 231 | ``` 232 | curl http://127.0.0.1 233 | ``` 234 | 235 | ``` 236 | version: 0.2.0 237 | hostname: standalone-kubelet.c.hightowerlabs.internal 238 | key: 1506065786 239 | ``` 240 | 241 | ## Cleanup 242 | 243 | ``` 244 | gcloud -q compute instances delete standalone-kubelet 245 | ``` 246 | 247 | ``` 248 | gcloud -q compute firewall-rules delete allow-standalone-kubelet 249 | ``` 250 | -------------------------------------------------------------------------------- /app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | ADD app /app 3 | ENTRYPOINT ["/app"] 4 | -------------------------------------------------------------------------------- /app/build-container: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GOOS=linux go build -o app . 4 | gcloud container builds submit --config cloudbuild.yaml . 5 | rm app 6 | -------------------------------------------------------------------------------- /app/cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: "gcr.io/cloud-builders/docker" 3 | args: ["build", "-t", "gcr.io/${PROJECT_ID}/app:0.1.0", "."] 4 | 5 | images: ["gcr.io/${PROJECT_ID}/app:0.1.0"] 6 | -------------------------------------------------------------------------------- /app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "flag" 6 | "fmt" 7 | "io/ioutil" 8 | "log" 9 | "net/http" 10 | ) 11 | 12 | var ( 13 | addr string 14 | configFile string 15 | ) 16 | 17 | var version = "0.1.0" 18 | 19 | type Config struct { 20 | Hostname string `json:"hostname"` 21 | Key int64 `json:"key"` 22 | } 23 | 24 | func main() { 25 | flag.StringVar(&addr, "addr", "0.0.0.0:80", "HTTP listen address.") 26 | flag.StringVar(&configFile, "config", "/etc/app/config.json", "Path to config file.") 27 | flag.Parse() 28 | 29 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 30 | config, err := getConfig(configFile) 31 | if err != nil { 32 | log.Println(err) 33 | w.WriteHeader(500) 34 | return 35 | } 36 | 37 | fmt.Fprintf(w, "version: %s\nhostname: %s\nkey: %d\n", version, config.Hostname, config.Key) 38 | }) 39 | 40 | log.Println("Starting the HTTP service...") 41 | http.ListenAndServe(addr, nil) 42 | } 43 | 44 | func getConfig(path string) (*Config, error) { 45 | data, err := ioutil.ReadFile(path) 46 | if err != nil { 47 | return nil, err 48 | } 49 | 50 | var config Config 51 | if err := json.Unmarshal(data, &config); err != nil { 52 | return nil, err 53 | } 54 | 55 | return &config, nil 56 | } 57 | -------------------------------------------------------------------------------- /configurator/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | ADD configurator /configurator 3 | ENTRYPOINT ["/configurator"] 4 | -------------------------------------------------------------------------------- /configurator/build-container: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GOOS=linux go build -o configurator . 4 | gcloud container builds submit --config cloudbuild.yaml . 5 | rm configurator 6 | -------------------------------------------------------------------------------- /configurator/cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: "gcr.io/cloud-builders/docker" 3 | args: ["build", "-t", "gcr.io/${PROJECT_ID}/configurator:0.1.0", "."] 4 | 5 | images: ["gcr.io/${PROJECT_ID}/configurator:0.1.0"] 6 | -------------------------------------------------------------------------------- /configurator/configurator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kelseyhightower/standalone-kubelet-tutorial/98b0b5b000cc687cc9c85c54ded7b39f4322d4ba/configurator/configurator -------------------------------------------------------------------------------- /configurator/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "flag" 6 | "io/ioutil" 7 | "log" 8 | "os" 9 | "time" 10 | ) 11 | 12 | var ( 13 | config string 14 | onetime bool 15 | ) 16 | 17 | type Config struct { 18 | Hostname string `json:"hostname"` 19 | Key int64 `json:"key"` 20 | } 21 | 22 | func main() { 23 | flag.StringVar(&config, "config", "", "Path to config file.") 24 | flag.BoolVar(&onetime, "onetime", false, "Generate config and exit") 25 | flag.Parse() 26 | 27 | if config == "" { 28 | log.Fatal("The -config flag is required. Exiting...") 29 | } 30 | 31 | for { 32 | log.Println("Generating configuration file...") 33 | c, err := getConfig() 34 | 35 | if err != nil { 36 | time.Sleep(30 * time.Second) 37 | log.Println(err) 38 | continue 39 | } 40 | 41 | data, err := json.MarshalIndent(&c, "", " ") 42 | if err != nil { 43 | time.Sleep(30 * time.Second) 44 | log.Println(err) 45 | continue 46 | } 47 | 48 | if err := ioutil.WriteFile(config, data, 0644); err != nil { 49 | time.Sleep(30 * time.Second) 50 | log.Println(err) 51 | continue 52 | } 53 | 54 | log.Printf("Wrote config %s", config) 55 | 56 | if onetime { 57 | log.Println("Onetime mode set. Exiting...") 58 | os.Exit(0) 59 | } 60 | 61 | time.Sleep(30 * time.Second) 62 | } 63 | } 64 | 65 | func getConfig() (*Config, error) { 66 | hostname, err := os.Hostname() 67 | if err != nil { 68 | return nil, err 69 | } 70 | 71 | c := Config{ 72 | Hostname: hostname, 73 | Key: time.Now().Unix(), 74 | } 75 | 76 | return &c, nil 77 | } 78 | -------------------------------------------------------------------------------- /kubelet.service: -------------------------------------------------------------------------------- 1 | [Service] 2 | Environment=KUBELET_IMAGE_TAG=v1.7.6_coreos.0 3 | Environment="RKT_RUN_ARGS=--uuid-file-save=/var/run/kubelet-pod.uuid \ 4 | --volume=resolv,kind=host,source=/etc/resolv.conf \ 5 | --mount volume=resolv,target=/etc/resolv.conf" 6 | ExecStartPre=-/usr/bin/rkt rm --uuid-file=/var/run/kubelet-pod.uuid 7 | ExecStart=/usr/lib/coreos/kubelet-wrapper \ 8 | --allow-privileged \ 9 | --file-check-frequency 30s \ 10 | --max-pods 10 \ 11 | --minimum-image-ttl-duration 300s \ 12 | --pod-manifest-path=/etc/kubernetes/manifests \ 13 | --sync-frequency 30s 14 | ExecStop=-/usr/bin/rkt stop --uuid-file=/var/run/kubelet-pod.uuid 15 | Restart=always 16 | RestartSec=10s 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /pods/app-v0.1.0.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: app 5 | spec: 6 | hostNetwork: true 7 | initContainers: 8 | - name: configurator-init 9 | image: gcr.io/hightowerlabs/configurator:0.1.0 10 | args: 11 | - "-config=/etc/app/app.json" 12 | - "-onetime" 13 | volumeMounts: 14 | - name: config 15 | mountPath: /etc/app 16 | containers: 17 | - name: app 18 | image: gcr.io/hightowerlabs/app:0.1.0 19 | args: 20 | - "-config=/etc/app/app.json" 21 | resources: 22 | limits: 23 | cpu: "100m" 24 | memory: "50Mi" 25 | volumeMounts: 26 | - name: config 27 | mountPath: /etc/app 28 | - name: configurator 29 | image: gcr.io/hightowerlabs/configurator:0.1.0 30 | args: 31 | - "-config=/etc/app/app.json" 32 | volumeMounts: 33 | - name: config 34 | mountPath: /etc/app 35 | volumes: 36 | - name: config 37 | emptyDir: {} 38 | -------------------------------------------------------------------------------- /pods/app-v0.2.0.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: app 5 | spec: 6 | hostNetwork: true 7 | initContainers: 8 | - name: configurator-init 9 | image: gcr.io/hightowerlabs/configurator:0.1.0 10 | args: 11 | - "-config=/etc/app/app.json" 12 | - "-onetime" 13 | volumeMounts: 14 | - name: config 15 | mountPath: /etc/app 16 | containers: 17 | - name: app 18 | image: gcr.io/hightowerlabs/app:0.2.0 19 | args: 20 | - "-config=/etc/app/app.json" 21 | resources: 22 | limits: 23 | cpu: "100m" 24 | memory: "50Mi" 25 | volumeMounts: 26 | - name: config 27 | mountPath: /etc/app 28 | - name: configurator 29 | image: gcr.io/hightowerlabs/configurator:0.1.0 30 | args: 31 | - "-config=/etc/app/app.json" 32 | volumeMounts: 33 | - name: config 34 | mountPath: /etc/app 35 | volumes: 36 | - name: config 37 | emptyDir: {} 38 | --------------------------------------------------------------------------------