├── .gitignore ├── README.md ├── LICENSE └── kid /.gitignore: -------------------------------------------------------------------------------- 1 | *.key 2 | *.key.pub 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kid - [Kubernetes](http://kubernetes.io) in [Docker](https://www.docker.com) 2 | 3 | Launch Kubernetes 1.3 in Docker in one `kid up` command. 4 | 5 | ``` 6 | ❱ kid 7 | kid is a utility for launching Kubernetes in Docker 8 | Usage: kid [command] 9 | 10 | Available commands: 11 | up Starts Kubernetes in the Docker host currently configured with your local docker command 12 | down Tear down a previously started Kubernetes cluster 13 | restart Restart Kubernetes 14 | ``` 15 | 16 | ## Linux - Local Docker 17 | 18 | On Linux kid will launch Kubernetes using the local Docker Engine. 19 | 20 | ## macOS - Docker Machine or Docker for Mac 21 | 22 | On macOS kid will start Kubernetes in the boot2docker VM if there is an active Docker Machine. kid then sets up port forwarding so that you can use kubectl locally without having to ssh into boot2docker. 23 | 24 | If kid detects a local installation of [Docker for macOS](https://www.docker.com/products/docker#/mac), it uses that instead. 25 | 26 | ## Prerequisites 27 | 28 | In order for `kid` to operate you must have installed the following and have the commands available on your `PATH`. 29 | 30 | - kubectl - (Linux | macOS[https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl] 31 | - docker - (Linux | macOs)[https://www.docker.com/community-edition#/download] 32 | - socat - (macOs)[http://brewformulas.org/Socat] 33 | 34 | ## Addons 35 | 36 | kid also sets up: 37 | 38 | * The [DNS addon](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) 39 | * The [Kubernetes Dashboard](https://github.com/kubernetes/dashboard) 40 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /kid: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # kid is a helper script for launching Kubernetes in Docker 4 | 5 | KUBERNETES_VERSION=${KUBERNETES_VERSION:-1.5.7} 6 | KUBERNETES_API_PORT=8080 7 | KUBERNETES_DASHBOARD_NODEPORT=31999 8 | DNS_DOMAIN=cluster.local 9 | DNS_SERVER_IP=10.0.0.10 10 | 11 | function print_usage { 12 | cat << EOF 13 | kid is a utility for launching Kubernetes in Docker 14 | 15 | Usage: kid [command] 16 | 17 | Available commands: 18 | up Starts Kubernetes in the Docker host currently configured with your local docker command 19 | down Tear down a previously started Kubernetes cluster 20 | restart Restart Kubernetes 21 | EOF 22 | } 23 | 24 | function check_prerequisites { 25 | function require_command_exists() { 26 | command -v "$1" >/dev/null 2>&1 || \ 27 | { echo "$1 is required but is not installed. Aborting." >&2; exit 1; } 28 | } 29 | require_command_exists kubectl 30 | require_command_exists docker 31 | require_command_exists socat 32 | docker info > /dev/null 33 | if [ $? != 0 ]; then 34 | echo A running Docker engine is required. Is your Docker host up? 35 | exit 1 36 | fi 37 | 38 | # Fixed shared mount for docker machine. 39 | if [ -n $(active_docker_machine) ]; then 40 | fix_shared_mount "/" 41 | fi 42 | 43 | docker info | egrep -q 'Kernel Version: .*-moby' 44 | if [ $? -eq 0 ]; then 45 | echo "Docker for Mac detected" 46 | 47 | # Mount /var as shared to fix configmaps. 48 | fix_shared_mount "/var" 49 | fi 50 | } 51 | 52 | function fix_shared_mount { 53 | path=$1 54 | docker run -it --rm --entrypoint=sh --privileged --net=host -e sysimage=/host -v /:/host -v /dev:/dev -v /run:/run gcr.io/google_containers/hyperkube-amd64:v${KUBERNETES_VERSION} -c 'nsenter --mount=$sysimage/proc/1/ns/mnt -- mount --make-shared '$path'' 55 | } 56 | 57 | function active_docker_machine { 58 | docker-machine active &> /dev/null 59 | if [[ $? == 0 ]]; then 60 | docker-machine active 61 | fi 62 | } 63 | 64 | function mount_filesystem_shared_if_necessary { 65 | local machine=$(active_docker_machine) 66 | if [ -n "$machine" ]; then 67 | docker-machine ssh $machine sudo mount --make-shared / 68 | fi 69 | } 70 | 71 | function forward_port_if_necessary { 72 | local port=$1 73 | local machine=$(active_docker_machine) 74 | 75 | if [ -n "$machine" ]; then 76 | if ! pgrep -f "ssh.*$port:localhost" > /dev/null; then 77 | docker-machine ssh "$machine" -f -N -L "$port:localhost:$port" 78 | else 79 | echo Did not set up port forwarding to the Docker machine: An ssh tunnel on port $port already exists. The kubernetes cluster may not be reachable from local kubectl. 80 | fi 81 | fi 82 | 83 | docker info | egrep -q 'Kernel Version: .*-moby' 84 | if [ $? -eq 0 ]; then 85 | # Forward request on localhost:8080 to the kubeproxy via the kubelet container with socat. 86 | nohup socat TCP-LISTEN:8080,reuseaddr,fork 'EXEC:docker exec -i kubelet "socat STDIO TCP-CONNECT:localhost:8080"' >/dev/null 2>&1 & 87 | fi 88 | } 89 | 90 | function forward_canary_port_if_necessary { 91 | port=$1 92 | docker info | egrep -q 'Kernel Version: .*-moby' 93 | if [ $? -eq 0 ]; then 94 | # Keep port forward alive. 95 | nohup bash -c 'while true; do kubectl --namespace kube-system port-forward $(kubectl --namespace kube-system get pod --selector=app=kubernetes-dashboard-canary -o jsonpath={.items..metadata.name}) '$port':9090; sleep 2; done' >/dev/null 2>&1 & 96 | nc -z localhost 31999 97 | while [ $? -ne 0 ]; do sleep 1 ; nc -z localhost 31999; done 98 | fi 99 | } 100 | 101 | function remove_port_forward_if_forwarded { 102 | local port=$1 103 | 104 | # port-forward the canary dashboard. 105 | docker info | egrep -q 'Kernel Version: .*-moby' 106 | if [ $? -eq 0 ]; then 107 | pkill -f "kubectl.*port-forward.*dashboard-canary.*" 108 | pkill -f "socat.*TCP-LISTEN:8080.*" 109 | fi 110 | } 111 | 112 | function wait_for_kubernetes { 113 | until $(kubectl cluster-info &> /dev/null); do 114 | sleep 1 115 | done 116 | } 117 | 118 | function create_kube_system_namespace { 119 | kubectl create -f - << EOF > /dev/null 120 | kind: Namespace 121 | apiVersion: v1 122 | metadata: 123 | name: kube-system 124 | labels: 125 | name: kube-system 126 | EOF 127 | } 128 | 129 | function activate_kubernetes_dashboard { 130 | local dashboard_service_nodeport=$1 131 | kubectl create -f - << EOF > /dev/null 132 | # Source: https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard-canary.yaml 133 | kind: List 134 | apiVersion: v1 135 | items: 136 | - kind: ReplicationController 137 | apiVersion: v1 138 | metadata: 139 | labels: 140 | app: kubernetes-dashboard-canary 141 | version: canary 142 | name: kubernetes-dashboard-canary 143 | namespace: kube-system 144 | spec: 145 | replicas: 1 146 | selector: 147 | app: kubernetes-dashboard-canary 148 | version: canary 149 | template: 150 | metadata: 151 | labels: 152 | app: kubernetes-dashboard-canary 153 | version: canary 154 | spec: 155 | containers: 156 | - name: kubernetes-dashboard-canary 157 | image: gcr.io/google_containers/kubernetes-dashboard-amd64:canary 158 | imagePullPolicy: Always 159 | ports: 160 | - containerPort: 9090 161 | protocol: TCP 162 | args: 163 | # Uncomment the following line to manually specify Kubernetes API server Host 164 | # If not specified, Dashboard will attempt to auto discover the API server and connect 165 | # to it. Uncomment only if the default does not work. 166 | # - --apiserver-host=http://my-address:port 167 | livenessProbe: 168 | httpGet: 169 | path: / 170 | port: 9090 171 | initialDelaySeconds: 30 172 | timeoutSeconds: 30 173 | - kind: Service 174 | apiVersion: v1 175 | metadata: 176 | labels: 177 | app: kubernetes-dashboard-canary 178 | name: dashboard-canary 179 | namespace: kube-system 180 | spec: 181 | type: NodePort 182 | ports: 183 | - port: 80 184 | targetPort: 9090 185 | nodePort: $dashboard_service_nodeport # Addition. Not present in upstream definition. 186 | selector: 187 | app: kubernetes-dashboard-canary 188 | EOF 189 | } 190 | 191 | function start_dns { 192 | local dns_domain=$1 193 | local dns_server_ip=$2 194 | 195 | kubectl create -f - << EOF > /dev/null 196 | apiVersion: v1 197 | kind: ReplicationController 198 | metadata: 199 | name: kube-dns-v10 200 | namespace: kube-system 201 | labels: 202 | k8s-app: kube-dns 203 | version: v10 204 | kubernetes.io/cluster-service: "true" 205 | spec: 206 | replicas: 1 207 | selector: 208 | k8s-app: kube-dns 209 | version: v10 210 | template: 211 | metadata: 212 | labels: 213 | k8s-app: kube-dns 214 | version: v10 215 | kubernetes.io/cluster-service: "true" 216 | spec: 217 | containers: 218 | - name: etcd 219 | image: gcr.io/google_containers/etcd-amd64:2.2.5 220 | resources: 221 | # keep request = limit to keep this container in guaranteed class 222 | limits: 223 | cpu: 100m 224 | memory: 50Mi 225 | requests: 226 | cpu: 100m 227 | memory: 50Mi 228 | command: 229 | - /usr/local/bin/etcd 230 | - -data-dir 231 | - /var/etcd/data 232 | - -listen-client-urls 233 | - http://127.0.0.1:2379,http://127.0.0.1:4001 234 | - -advertise-client-urls 235 | - http://127.0.0.1:2379,http://127.0.0.1:4001 236 | - -initial-cluster-token 237 | - skydns-etcd 238 | volumeMounts: 239 | - name: etcd-storage 240 | mountPath: /var/etcd/data 241 | - name: kube2sky 242 | image: gcr.io/google_containers/kube2sky:1.15 243 | resources: 244 | # keep request = limit to keep this container in guaranteed class 245 | limits: 246 | cpu: 100m 247 | memory: 50Mi 248 | requests: 249 | cpu: 100m 250 | memory: 50Mi 251 | args: 252 | # command = "/kube2sky" 253 | - --domain=$dns_domain 254 | - name: skydns 255 | image: gcr.io/google_containers/skydns:2015-10-13-8c72f8c 256 | resources: 257 | # keep request = limit to keep this container in guaranteed class 258 | limits: 259 | cpu: 100m 260 | memory: 50Mi 261 | requests: 262 | cpu: 100m 263 | memory: 50Mi 264 | args: 265 | # command = "/skydns" 266 | - -machines=http://127.0.0.1:4001 267 | - -addr=0.0.0.0:53 268 | - -ns-rotate=false 269 | - -domain=${dns_domain}. 270 | ports: 271 | - containerPort: 53 272 | name: dns 273 | protocol: UDP 274 | - containerPort: 53 275 | name: dns-tcp 276 | protocol: TCP 277 | livenessProbe: 278 | httpGet: 279 | path: /healthz 280 | port: 8080 281 | scheme: HTTP 282 | initialDelaySeconds: 30 283 | timeoutSeconds: 5 284 | readinessProbe: 285 | httpGet: 286 | path: /healthz 287 | port: 8080 288 | scheme: HTTP 289 | initialDelaySeconds: 1 290 | timeoutSeconds: 5 291 | - name: healthz 292 | image: gcr.io/google_containers/exechealthz:1.1 293 | resources: 294 | # keep request = limit to keep this container in guaranteed class 295 | limits: 296 | cpu: 10m 297 | memory: 20Mi 298 | requests: 299 | cpu: 10m 300 | memory: 20Mi 301 | args: 302 | - -cmd=nslookup kubernetes.default.svc.${dns_domain} 127.0.0.1 >/dev/null 303 | - -port=8080 304 | ports: 305 | - containerPort: 8080 306 | protocol: TCP 307 | volumes: 308 | - name: etcd-storage 309 | emptyDir: {} 310 | dnsPolicy: Default # Don't use cluster DNS. 311 | --- 312 | apiVersion: v1 313 | kind: Service 314 | metadata: 315 | name: kube-dns 316 | namespace: kube-system 317 | labels: 318 | k8s-app: kube-dns 319 | kubernetes.io/cluster-service: "true" 320 | kubernetes.io/name: "KubeDNS" 321 | spec: 322 | selector: 323 | k8s-app: kube-dns 324 | clusterIP: $dns_server_ip 325 | ports: 326 | - name: dns 327 | port: 53 328 | protocol: UDP 329 | - name: dns-tcp 330 | port: 53 331 | protocol: TCP 332 | EOF 333 | } 334 | 335 | function start_kubernetes { 336 | local kubernetes_version=$1 337 | local kubernetes_api_port=$2 338 | local dashboard_service_nodeport=$3 339 | local dns_domain=$4 340 | local dns_server_ip=$5 341 | check_prerequisites 342 | 343 | if kubectl cluster-info 2> /dev/null; then 344 | echo kubectl is already configured to use an existing cluster 345 | exit 1 346 | fi 347 | 348 | mount_filesystem_shared_if_necessary 349 | 350 | docker run \ 351 | --name=kubelet \ 352 | --volume=/:/rootfs:ro \ 353 | --volume=/sys:/sys:ro \ 354 | --volume=/var/lib/docker/:/var/lib/docker:rw \ 355 | --volume=/var/lib/kubelet/:/var/lib/kubelet:rw,shared \ 356 | --volume=/var/run:/var/run:rw \ 357 | --net=host \ 358 | --pid=host \ 359 | --privileged=true \ 360 | -d \ 361 | gcr.io/google_containers/hyperkube-amd64:v${kubernetes_version} \ 362 | /hyperkube kubelet \ 363 | --containerized \ 364 | --hostname-override="127.0.0.1" \ 365 | --address="0.0.0.0" \ 366 | --api-servers=http://localhost:${kubernetes_api_port} \ 367 | --config=/etc/kubernetes/manifests \ 368 | --cluster-dns=$DNS_SERVER_IP \ 369 | --cluster-domain=$DNS_DOMAIN \ 370 | --allow-privileged=true --v=2 \ 371 | > /dev/null 372 | 373 | # TODO: Set and use a `kid` Kubernetes context instead of forwarding the port? 374 | forward_port_if_necessary $kubernetes_api_port 375 | 376 | echo Waiting for Kubernetes cluster to become available... 377 | wait_for_kubernetes 378 | create_kube_system_namespace 379 | start_dns $dns_domain $dns_server_ip 380 | activate_kubernetes_dashboard $dashboard_service_nodeport 381 | 382 | forward_canary_port_if_necessary $dashboard_service_nodeport 383 | 384 | echo Kubernetes cluster is up. The Kubernetes dashboard can be accessed via HTTP at port $dashboard_service_nodeport of your Docker host. 385 | } 386 | 387 | function delete_kubernetes_resources { 388 | kubectl delete replicationcontrollers,services,pods,secrets --all > /dev/null 2>&1 || : 389 | kubectl delete replicationcontrollers,services,pods,secrets --all --namespace=kube-system > /dev/null 2>&1 || : 390 | kubectl delete namespace kube-system > /dev/null 2>&1 || : 391 | } 392 | 393 | function delete_docker_containers { 394 | # Remove the kubelet first so that it doesn't restart pods that we're going to remove next 395 | docker stop kubelet > /dev/null 2>&1 396 | docker rm -fv kubelet > /dev/null 2>&1 397 | 398 | k8s_containers=$(docker ps -aqf "name=k8s_") 399 | if [ ! -z "$k8s_containers" ]; then 400 | docker stop $k8s_containers > /dev/null 2>&1 401 | docker wait $k8s_containers > /dev/null 2>&1 402 | docker rm -fv $k8s_containers > /dev/null 2>&1 403 | fi 404 | } 405 | 406 | function stop_kubernetes { 407 | local kubernetes_api_port=$1 408 | delete_kubernetes_resources 409 | delete_docker_containers 410 | remove_port_forward_if_forwarded $kubernetes_api_port 411 | } 412 | 413 | if [ "$1" == "up" ]; then 414 | start_kubernetes $KUBERNETES_VERSION \ 415 | $KUBERNETES_API_PORT \ 416 | $KUBERNETES_DASHBOARD_NODEPORT \ 417 | $DNS_DOMAIN $DNS_SERVER_IP 418 | elif [ "$1" == "down" ]; then 419 | # TODO: Ensure current Kubernetes context is set to local Docker (or Docker Machine VM) before downing 420 | stop_kubernetes $KUBERNETES_API_PORT 421 | elif [ "$1" == "restart" ]; then 422 | # TODO: Check if not currently running before downing. Show a message if not running. 423 | kid down && kid up 424 | else 425 | print_usage 426 | fi 427 | --------------------------------------------------------------------------------