├── .github └── workflows │ └── assign.yaml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cleanup.sh ├── config_maps ├── configmap.yaml ├── demo.sh └── pod.yaml ├── daemon_sets ├── daemon.yaml ├── demo.sh ├── split1_color_nodes.sh ├── split1_hit_svc.sh └── svc.yaml ├── demo-namespace.yaml ├── deployments ├── demo.sh ├── deployment.yaml ├── split1_control.sh ├── split1_hit_svc.sh ├── split1_watch.sh └── svc.yaml ├── example.sh ├── graceful_termination ├── demo.sh └── pod.yaml ├── init-containers ├── demo.sh └── pod.yaml ├── jobs ├── demo.sh └── job.yaml ├── mcs ├── demo.sh ├── deploy1.yaml ├── deploy2.yaml ├── export.yaml ├── reset.sh ├── svc.yaml ├── udemo.sh └── vars.sh ├── pod_autoscalers └── demo.sh ├── pods ├── demo.sh └── pod.yaml ├── pv-provisioning ├── claim.yaml ├── demo.sh └── pod.yaml ├── quota ├── demo.sh ├── limits.yaml ├── pod1.yaml ├── pod2.yaml └── quota.yaml ├── replicasets ├── demo.sh └── rs.yaml ├── replication_controllers └── demo.sh ├── reset.sh ├── rolling_update ├── demo.sh ├── rc-v1.yaml ├── rc-v2.yaml ├── split1_hit_svc.sh ├── split1_update.sh └── svc.yaml ├── secrets ├── demo.sh ├── pod.yaml └── secret.yaml ├── services ├── demo.sh ├── service.yaml ├── split1_hit_svc.sh └── split1_scale.sh ├── setup.sh └── util.sh /.github/workflows/assign.yaml: -------------------------------------------------------------------------------- 1 | name: Assign 2 | 3 | on: 4 | issues: 5 | types: [opened, reopened] 6 | pull_request_target: 7 | types: [opened, reopened] 8 | 9 | jobs: 10 | assign: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/github-script@v6 14 | with: 15 | script: | 16 | github.rest.issues.addAssignees({ 17 | issue_number: context.issue.number, 18 | owner: context.repo.owner, 19 | repo: context.repo.repo, 20 | assignees: ['thockin'] 21 | }) 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX leaves these everywhere on SMB shares 2 | ._* 3 | 4 | # OSX trash 5 | .DS_Store 6 | 7 | # Eclipse files 8 | .classpath 9 | .project 10 | .settings/** 11 | 12 | # Emacs save files 13 | *~ 14 | \#*\# 15 | .\#* 16 | 17 | # Vim-related files 18 | [._]*.s[a-w][a-z] 19 | [._]s[a-w][a-z] 20 | *.un~ 21 | Session.vim 22 | .netrwhist 23 | 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | services: 4 | - docker 5 | 6 | language: go 7 | 8 | matrix: 9 | include: 10 | - go: 1.9 11 | 12 | install: 13 | - mkdir -p $HOME/gopath/src/k8s.io 14 | - mv $TRAVIS_BUILD_DIR $HOME/gopath/src/k8s.io/contrib 15 | - hack/install-verify-tools.sh 16 | - export PATH=$GOPATH/bin:$PATH 17 | - hack/for-go-proj.sh install 18 | 19 | script: 20 | - hack/verify-all.sh -v 21 | - hack/for-go-proj.sh test 22 | 23 | notifications: 24 | irc: "chat.freenode.net#kubernetes-dev" 25 | -------------------------------------------------------------------------------- /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 | # Kubernetes micro-demos 2 | 3 | This is a collection of highly-targetted demonstrations of Kubernetes features. 4 | The demos are all text-based and automated, making them perfect for customer 5 | meetings, meetups, or just showing off to your colleagues. 6 | 7 | ## Running the demos 8 | 9 | To run these demos you need `pv` and `tmux` installed, and you need `kubectl` 10 | in your PATH. 11 | 12 | Some of the demos try to act in faster-than-real time. For best results: 13 | * SSH to your kubernetes-master and set the following flags (in this order): 14 | * kube-controllermanager: --pod-eviction-timeout=10s 15 | 16 | Before running a demo, make sure your cluster is demo-ready. The `reset.sh` 17 | script is provided for that. 18 | 19 | ## Writing new demos 20 | 21 | Each demo lives in its own directory. The bulk of the logic lives in 22 | `util.sh`. 23 | 24 | Demos should be small and focused - 2 to 3 minutes each. 25 | 26 | Demos should be repeatable. Make sure you are not relying on timing effects. 27 | If you need to `sleep`, you might have a problem. 28 | 29 | Demos should be self-contained. If you are depending on something being done 30 | before-hand, don't. Do it in the demo script. 31 | 32 | Demos should be single-terminal. Use `tmux` to split the window to show 33 | multiple parallel things. 34 | 35 | -------------------------------------------------------------------------------- /cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/util.sh 17 | 18 | desc "Nuke it all" 19 | run "kubectl delete namespace demos" 20 | while kubectl get namespace demos >/dev/null 2>&1; do 21 | run "kubectl get namespace demos" 22 | done 23 | run "kubectl get namespace demos" 24 | run "kubectl get namespaces" 25 | tmux kill-session -t my-session >/dev/null 2>&1 26 | -------------------------------------------------------------------------------- /config_maps/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | namespace: demos 5 | name: my-app-config 6 | data: 7 | cfg-version: "93" 8 | min-power: "1" 9 | max-power: "100" 10 | objective: "world domination" 11 | -------------------------------------------------------------------------------- /config_maps/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . $(dirname ${BASH_SOURCE})/../util.sh 4 | 5 | desc "Create a config map" 6 | run "cat $(relative configmap.yaml)" 7 | run "kubectl --namespace=demos create -f $(relative configmap.yaml)" 8 | 9 | desc "Create a pod which uses that config map" 10 | run "cat $(relative pod.yaml)" 11 | run "kubectl --namespace=demos create -f $(relative pod.yaml)" 12 | 13 | while true; do 14 | run "kubectl --namespace=demos get pod configmaps-demo-pod" 15 | status=$(kubectl --namespace=demos get pod configmaps-demo-pod | tail -1 | awk '{print $3}') 16 | if [ "$status" == "Running" ]; then 17 | break 18 | fi 19 | done 20 | run "kubectl --namespace=demos exec --tty -i configmaps-demo-pod sh" 21 | -------------------------------------------------------------------------------- /config_maps/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | name: configmaps-demo-pod 6 | spec: 7 | containers: 8 | - name: busybox 9 | image: busybox 10 | command: 11 | - sh 12 | - -c 13 | - while true; do sleep 3600; done 14 | volumeMounts: 15 | - name: my-config 16 | mountPath: /etc/config 17 | volumes: 18 | - name: my-config 19 | configMap: 20 | name: my-app-config 21 | -------------------------------------------------------------------------------- /daemon_sets/daemon.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: DaemonSet 3 | metadata: 4 | namespace: demos 5 | name: daemons-demo 6 | spec: 7 | template: 8 | metadata: 9 | labels: 10 | demo: daemons 11 | spec: 12 | nodeSelector: 13 | color: red 14 | containers: 15 | - name: hostname 16 | image: k8s.gcr.io/serve_hostname:1.1 17 | -------------------------------------------------------------------------------- /daemon_sets/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | for NODE in $(kubectl get nodes -o name | cut -f2 -d/); do 19 | kubectl label node $NODE color- --overwrite >/dev/null 2>&1 20 | done 21 | 22 | desc "No labels on nodes" 23 | run "kubectl get nodes \\ 24 | -o go-template='{{range .items}}{{.metadata.name}}{{\"\t\"}}{{.metadata.labels}}{{\"\n\"}}{{end}}'" 25 | 26 | desc "Run a service to front our daemon" 27 | run "cat $(relative svc.yaml)" 28 | run "kubectl --namespace=demos create -f $(relative svc.yaml)" 29 | 30 | desc "Run our daemon" 31 | run "cat $(relative daemon.yaml)" 32 | run "kubectl --namespace=demos create -f $(relative daemon.yaml) --validate=false" 33 | run "kubectl --namespace=demos describe ds daemons-demo" 34 | 35 | tmux new -d -s my-session \ 36 | "$(dirname ${BASH_SOURCE})/split1_color_nodes.sh" \; \ 37 | split-window -v -d "$(dirname $BASH_SOURCE)/split1_hit_svc.sh" \; \ 38 | attach \; 39 | -------------------------------------------------------------------------------- /daemon_sets/split1_color_nodes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | run "" # wait for first input 19 | desc "Color each node" 20 | for NODE in $(kubectl get nodes -o name | grep -v master | cut -f2 -d/); do 21 | run "kubectl label node $NODE color=red" 22 | run "kubectl --namespace=demos describe ds daemons-demo | head" 23 | done 24 | -------------------------------------------------------------------------------- /daemon_sets/split1_hit_svc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | IP=$(kubectl --namespace=demos get svc daemon-demo \ 19 | -o go-template='{{.spec.clusterIP}}') 20 | 21 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 22 | while true; do \\ 23 | curl --connect-timeout 1 -s $IP && echo || echo \"(timeout)\"; \\ 24 | sleep 1; \\ 25 | done \\ 26 | '" 27 | -------------------------------------------------------------------------------- /daemon_sets/svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | namespace: demos 5 | name: daemon-demo 6 | spec: 7 | ports: 8 | - port: 80 9 | protocol: TCP 10 | targetPort: 9376 11 | selector: 12 | demo: daemons 13 | -------------------------------------------------------------------------------- /demo-namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: demos 5 | -------------------------------------------------------------------------------- /deployments/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Create a service that fronts any version of this demo" 19 | run "cat $(relative svc.yaml)" 20 | run "kubectl --namespace=demos apply -f $(relative svc.yaml)" 21 | 22 | desc "Deploy v1 of our app" 23 | run "cat $(relative deployment.yaml)" 24 | run "kubectl --namespace=demos apply -f $(relative deployment.yaml)" 25 | 26 | # The output of describe is too wide, uncomment the following if needed. 27 | # desc "Check it" 28 | # run "kubectl --namespace=demos describe deployment deployment-demo" 29 | 30 | tmux new -d -s my-session \ 31 | "$(dirname $BASH_SOURCE)/split1_control.sh" \; \ 32 | split-window -v -p 66 "$(dirname ${BASH_SOURCE})/split1_hit_svc.sh" \; \ 33 | split-window -v "$(dirname ${BASH_SOURCE})/split1_watch.sh v1" \; \ 34 | split-window -h -d "$(dirname ${BASH_SOURCE})/split1_watch.sh v2" \; \ 35 | select-pane -t 0 \; \ 36 | attach \; 37 | -------------------------------------------------------------------------------- /deployments/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | name: deployment-demo 5 | namespace: demos 6 | spec: 7 | selector: 8 | matchLabels: 9 | demo: deployment 10 | replicas: 5 11 | strategy: 12 | rollingUpdate: 13 | maxSurge: 1 14 | maxUnavailable: 0 15 | type: RollingUpdate 16 | template: 17 | metadata: 18 | labels: 19 | demo: deployment 20 | version: v1 21 | spec: 22 | containers: 23 | - name: busybox 24 | image: busybox 25 | command: [ "sh", "-c", "while true; do echo $(hostname) v1 > /data/index.html; sleep 60; done" ] 26 | volumeMounts: 27 | - name: content 28 | mountPath: /data 29 | - name: nginx 30 | image: nginx 31 | volumeMounts: 32 | - name: content 33 | mountPath: /usr/share/nginx/html 34 | readOnly: true 35 | volumes: 36 | - name: content 37 | -------------------------------------------------------------------------------- /deployments/split1_control.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | run "" # wait for first input 19 | desc "Update the deployment" 20 | run "cat $(relative deployment.yaml) | sed 's/ v1/ v2/g' | kubectl --namespace=demos apply -f-" 21 | desc "Rollback the deployment" 22 | run "kubectl --namespace=demos rollout undo deployment deployment-demo" 23 | -------------------------------------------------------------------------------- /deployments/split1_hit_svc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | IP=$(kubectl --namespace=demos get svc deployment-demo \ 19 | -o go-template='{{.spec.clusterIP}}') 20 | 21 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 22 | while true; do \\ 23 | curl --connect-timeout 1 -s $IP; \\ 24 | sleep 0.5; \\ 25 | done \\ 26 | '" 27 | -------------------------------------------------------------------------------- /deployments/split1_watch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | target="$1" 19 | 20 | while true; do 21 | kubectl --namespace=demos get rs -l demo=deployment \ 22 | -o go-template='{{range .items}}{{.metadata.name}} {{.metadata.labels}}{{"\n"}}{{end}}' \ 23 | | while read NAME LABELS; do 24 | if echo "$LABELS" | grep -q "$target"; then 25 | trap "exit" INT 26 | while true; do 27 | kubectl --namespace=demos get rs "$NAME" \ 28 | -o go-template="$target Desired: {{.spec.replicas}} Running: {{.status.replicas}}{{\"\n\"}}" 29 | sleep 0.3 30 | done 31 | exit 0 32 | fi 33 | done 34 | done 35 | -------------------------------------------------------------------------------- /deployments/svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | namespace: demos 5 | name: deployment-demo 6 | spec: 7 | ports: 8 | - port: 80 9 | protocol: TCP 10 | selector: 11 | demo: deployment 12 | -------------------------------------------------------------------------------- /example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2024 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/util.sh 17 | 18 | desc "This is a comment. It will be printed, but not through the typing simulator." 19 | desc "After this it will run a command." 20 | desc "After each command, it will wait for to proceed." 21 | run "date" 22 | run "sleep 1" 23 | desc_type "This one will be printed through the typing simulator." 24 | run "date" 25 | desc "If you set \$DEMO_RUN_FAST=1, the typing will go faster" 26 | DEMO_RUN_FAST=1 27 | run "echo \"this is a long command which would have taken a while to type out\"" 28 | desc "If you set \$DEMO_RUN_SPEED to a value between 1 and 1000, the typing will go slower or faster" 29 | DEMO_RUN_SPEED=5 30 | run "echo \"this is DEMO_RUN_SPEED=5\"" 31 | DEMO_RUN_SPEED=25 32 | run "echo \"this is DEMO_RUN_SPEED=25, which is the default\"" 33 | DEMO_RUN_SPEED=100 34 | run "echo \"this is DEMO_RUN_SPEED=100, which is fast enough to need more text here\"" 35 | desc "If you set \$DEMO_AUTO_RUN=1 it will not wait for input between commands" 36 | DEMO_AUTO_RUN=1 37 | run "echo \"This is the first command\"" 38 | run "echo \"This is the second command\"" 39 | run "echo \"This is the third command\"" 40 | unset DEMO_AUTO_RUN 41 | desc "The output of the last command is in \$DEMO_RUN_STDOUT if you need it" 42 | run "date" 43 | run "echo \"$DEMO_RUN_STDOUT\"" 44 | desc "At the end it will wait for one last ." 45 | -------------------------------------------------------------------------------- /graceful_termination/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Create a pod" 19 | run "cat $(relative pod.yaml)" 20 | run "kubectl --namespace=demos create -f $(relative pod.yaml)" 21 | 22 | desc "Hey look, a pod!" 23 | run "kubectl --namespace=demos get pods" 24 | 25 | desc "Get the pod's logs" 26 | run "kubectl --namespace=demos logs graceful-demo --follow" 27 | 28 | desc "Delete the pod" 29 | run "kubectl --namespace=demos delete pod graceful-demo" 30 | run "kubectl --namespace=demos get pods graceful-demo" 31 | 32 | desc "Get the pod's logs" 33 | run "kubectl --namespace=demos logs graceful-demo --follow" 34 | -------------------------------------------------------------------------------- /graceful_termination/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | name: graceful-demo 6 | labels: 7 | demo: graceful-termination 8 | spec: 9 | terminationGracePeriodSeconds: 15 10 | containers: 11 | - name: busybox 12 | image: busybox 13 | command: 14 | - sh 15 | - -c 16 | - "trap \"while true; do echo 'self destructing'; sleep 1; done\" SIGTERM; while true; do date; sleep 1; done" 17 | -------------------------------------------------------------------------------- /init-containers/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Create a Pod with init containers" 19 | run "cat $(relative pod.yaml)" 20 | run "kubectl -n demos create -f $(relative pod.yaml)" 21 | 22 | desc "See what happened" 23 | run "kubectl -n demos exec -ti init-ctr-demo -c busybox cat /data/file" 24 | 25 | desc "Clean up" 26 | run "kubectl -n demos delete pod init-ctr-demo" 27 | -------------------------------------------------------------------------------- /init-containers/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: init-ctr-demo 5 | namespace: demos 6 | spec: 7 | volumes: 8 | - name: data 9 | emptyDir: {} 10 | initContainers: 11 | - name: init-1 12 | image: busybox 13 | command: [ "sh", "-c", "echo start 1 >> /data/file" ] 14 | volumeMounts: 15 | - name: data 16 | mountPath: /data 17 | - name: init-2 18 | image: busybox 19 | command: [ "sh", "-c", "echo start 2 >> /data/file" ] 20 | volumeMounts: 21 | - name: data 22 | mountPath: /data 23 | containers: 24 | - name: busybox 25 | image: busybox 26 | command: [ "sh", "-c", "sleep 1000" ] 27 | volumeMounts: 28 | - name: data 29 | mountPath: /data 30 | -------------------------------------------------------------------------------- /jobs/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Run some pods in a job" 19 | run "cat $(relative job.yaml)" 20 | run "kubectl --namespace=demos create -f $(relative job.yaml)" 21 | 22 | desc "See what we did" 23 | run "kubectl --namespace=demos describe job jobs-demo" 24 | 25 | desc "See pods run" 26 | while [ "$(kubectl --namespace=demos get job jobs-demo -o go-template='{{.status.succeeded}}')" != 15 ]; do 27 | run "kubectl --namespace=demos get pods -l demo=jobs" 28 | run "kubectl --namespace=demos describe job jobs-demo" 29 | done 30 | 31 | desc "Final status" 32 | run "kubectl --namespace=demos get pods --show-all -l demo=jobs --sort-by='{.status.phase}'" 33 | -------------------------------------------------------------------------------- /jobs/job.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Job 3 | metadata: 4 | name: jobs-demo 5 | namespace: demos 6 | spec: 7 | selector: 8 | matchLabels: 9 | demo: jobs 10 | parallelism: 5 11 | completions: 15 12 | template: 13 | metadata: 14 | labels: 15 | demo: jobs 16 | spec: 17 | containers: 18 | - name: sleep 19 | image: busybox 20 | command: ["sh", "-c", "sleep 5; if [ $((RANDOM % 4)) -eq 0 ]; then exit 1; fi"] 21 | restartPolicy: Never 22 | -------------------------------------------------------------------------------- /mcs/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . $(dirname ${BASH_SOURCE})/udemo.sh 4 | . $(dirname ${BASH_SOURCE})/vars.sh 5 | 6 | GCLOUD="gcloud --project=$PRJ" 7 | K1="kubectl --context=$CTX1" 8 | K2="kubectl --context=$CTX2" 9 | 10 | desc "look ma, clusters!" 11 | run "$GCLOUD container clusters list" 12 | desc "they are registered in an environ" 13 | run "$GCLOUD container hub memberships list" 14 | 15 | desc "but they are empty" 16 | run "$K1 get ns" 17 | run "$K2 get ns" 18 | 19 | desc "make namespaces for the demo" 20 | run "$K1 create ns demo" 21 | run "$K2 create ns demo" 22 | 23 | desc "let's deploy a service" 24 | run "cat $(relative deploy1.yaml)" 25 | run "$K1 -n demo apply -f $(relative deploy1.yaml)" 26 | run "$K1 -n demo expose deploy msg --port=80 --target-port=9376" 27 | 28 | desc "prove it" 29 | run "$K1 -n demo run -ti --rm --restart=Never --image=busybox shell-$RANDOM -- wget -qO- msg" 30 | 31 | desc "now for some fun" 32 | run "$K1 get crd" 33 | desc "export the service and import it into demo2" 34 | run "cat $(relative export.yaml)" 35 | run "$K1 -n demo apply -f $(relative export.yaml)" 36 | 37 | desc "see - it got imported" 38 | run "$K1 -n demo get importedservice" 39 | desc "even in the other cluster" 40 | run "$K2 -n demo get importedservice" 41 | desc "here's the WOW" 42 | run "$K2 -n demo run -ti --rm --restart=Never --image=busybox shell-$RANDOM -- wget -qO- 10.255.255.254" 43 | desc "even better" 44 | run "$K2 -n demo run -ti --rm --restart=Never --image=busybox shell-$RANDOM -- wget -qO- msg.demo.svc.supercluster.local" 45 | 46 | desc "let's go even farther" 47 | run "cat $(relative deploy2.yaml)" 48 | run "$K2 -n demo apply -f $(relative deploy2.yaml)" 49 | run "$K2 -n demo expose deploy msg --port=80 --target-port=9376" 50 | run "$K2 -n demo apply -f $(relative export.yaml)" 51 | 52 | desc "and the coup de grace" 53 | run "$K2 -n demo run -ti --rm --restart=Never --image=busybox shell-$RANDOM -- sh -c \"for i in \\\$(seq 1 10); do wget -qO- msg.demo.svc.supercluster.local; done\"" 54 | -------------------------------------------------------------------------------- /mcs/deploy1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: msg 5 | namespace: demo 6 | spec: 7 | replicas: 1 8 | selector: 9 | matchLabels: 10 | app: msg 11 | template: 12 | metadata: 13 | labels: 14 | app: msg 15 | spec: 16 | containers: 17 | - name: serve-msg 18 | image: thockin/serve-msg 19 | args: [ "hello from cluster 1" ] 20 | -------------------------------------------------------------------------------- /mcs/deploy2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: msg 5 | namespace: demo 6 | spec: 7 | replicas: 1 8 | selector: 9 | matchLabels: 10 | app: msg 11 | template: 12 | metadata: 13 | labels: 14 | app: msg 15 | spec: 16 | containers: 17 | - name: serve-msg 18 | image: thockin/serve-msg 19 | args: [ "hello from cluster 2" ] 20 | -------------------------------------------------------------------------------- /mcs/export.yaml: -------------------------------------------------------------------------------- 1 | kind: ServiceExport 2 | apiVersion: net.gke.io/v1alpha1 3 | metadata: 4 | name: msg 5 | namespace: demo 6 | spec: 7 | superclusterIP: 10.255.255.254 8 | -------------------------------------------------------------------------------- /mcs/reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . $(dirname ${BASH_SOURCE})/vars.sh 4 | 5 | kubectl --context=$CTX1 delete namespace demo --wait=false 6 | kubectl --context=$CTX2 delete namespace demo --wait=false 7 | -------------------------------------------------------------------------------- /mcs/svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: msg 5 | namespace: demo 6 | spec: 7 | ports: 8 | - port: 80 9 | targetPort: 9376 10 | selector: 11 | app: msg 12 | -------------------------------------------------------------------------------- /mcs/udemo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | readonly reset=$(tput sgr0) 17 | readonly green=$(tput bold; tput setaf 2) 18 | readonly yellow=$(tput bold; tput setaf 3) 19 | readonly blue=$(tput bold; tput setaf 6) 20 | readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi) 21 | 22 | function desc() { 23 | maybe_first_prompt 24 | echo "$blue# $@$reset" 25 | prompt 26 | } 27 | 28 | function prompt() { 29 | echo 30 | echo -n "$yellow\$ $reset" 31 | } 32 | 33 | started="" 34 | function maybe_first_prompt() { 35 | if [ -z "$started" ]; then 36 | prompt 37 | started=true 38 | fi 39 | } 40 | 41 | # After a `run` this variable will hold the stdout of the command that was run. 42 | # If the command was interactive, this will likely be garbage. 43 | DEMO_RUN_STDOUT="" 44 | 45 | function run() { 46 | maybe_first_prompt 47 | rate=25 48 | if [ -n "$DEMO_RUN_FAST" ]; then 49 | rate=1000 50 | fi 51 | echo "$green$1$reset" | pv -qL $rate 52 | if [ -n "$DEMO_RUN_FAST" ]; then 53 | sleep 0.5 54 | fi 55 | OFILE="$(mktemp -t $(basename $0).XXXXXX)" 56 | script -eq -c "$1" -f "$OFILE" 57 | r=$? 58 | read -d '' -t "${timeout}" -n 10000 # clear stdin 59 | prompt 60 | if [ -z "$DEMO_AUTO_RUN" ]; then 61 | read -s 62 | fi 63 | DEMO_RUN_STDOUT="$(tail -n +2 $OFILE | sed 's/\r//g')" 64 | return $r 65 | } 66 | 67 | function relative() { 68 | for arg; do 69 | echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|" 70 | done 71 | } 72 | 73 | trap "echo" EXIT 74 | -------------------------------------------------------------------------------- /mcs/vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PRJ=thockin-dev-2 4 | CTX1="demo1" 5 | CTX2="demo2" 6 | -------------------------------------------------------------------------------- /pod_autoscalers/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Run some pods under a replication controller" 19 | run "kubectl --namespace=demos run yes-autoscaler-demo \\ 20 | --image=busybox \\ 21 | --replicas=1 \\ 22 | --limits=cpu=100m \\ 23 | -o name \\ 24 | -- sh -c 'sleep 5; yes > /dev/null'" 25 | WHAT_WAS_RUN="$DEMO_RUN_STDOUT" 26 | 27 | desc "Look what I made!" 28 | run "kubectl --namespace=demos describe $WHAT_WAS_RUN" 29 | 30 | desc "One pod was created" 31 | run "kubectl --namespace=demos get pods -l run=yes-autoscaler-demo" 32 | 33 | desc "Create a pod autoscaler" 34 | run "kubectl --namespace=demos autoscale $WHAT_WAS_RUN --min=1 --max=10 --cpu-percent=25" 35 | 36 | desc "Watch pods get created" 37 | while true; do 38 | run "kubectl --namespace=demos describe hpa yes-autoscaler-demo" 39 | run "kubectl --namespace=demos get pods -l run=yes-autoscaler-demo" 40 | done 41 | -------------------------------------------------------------------------------- /pods/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "There are no running pods" 19 | run "kubectl --namespace=demos get pods" 20 | 21 | desc "Create a pod" 22 | run "cat $(relative pod.yaml)" 23 | run "kubectl --namespace=demos create -f $(relative pod.yaml)" 24 | 25 | desc "Hey look, a pod!" 26 | run "kubectl --namespace=demos get pods" 27 | 28 | desc "Get the pod's IP" 29 | run "kubectl --namespace=demos get pod pods-demo -o yaml | grep podIP" 30 | 31 | IP=$(kubectl --namespace=demos get pod pods-demo -o yaml \ 32 | | grep podIP \ 33 | | cut -f2 -d:) 34 | desc "SSH into my cluster and access the pod" 35 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 36 | for i in \$(seq 1 10); do \\ 37 | curl --connect-timeout 1 -s $IP; \\ 38 | sleep 1; \\ 39 | done\\ 40 | '" 41 | -------------------------------------------------------------------------------- /pods/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | name: pods-demo 6 | labels: 7 | demo: pods 8 | spec: 9 | containers: 10 | - name: busybox 11 | image: busybox 12 | command: 13 | - sh 14 | - -c 15 | - while true; do (hostname; date) > /data/index.html; sleep 1; done 16 | volumeMounts: 17 | - name: content 18 | mountPath: /data 19 | - name: nginx 20 | image: nginx 21 | volumeMounts: 22 | - name: content 23 | mountPath: /usr/share/nginx/html 24 | readOnly: true 25 | volumes: 26 | - name: content 27 | -------------------------------------------------------------------------------- /pv-provisioning/claim.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolumeClaim 3 | metadata: 4 | namespace: demos 5 | name: pv-provisioning-demo 6 | labels: 7 | demo: pv-provisioning 8 | annotations: 9 | volume.alpha.kubernetes.io/storage-class: anything 10 | spec: 11 | accessModes: [ "ReadWriteOnce" ] 12 | resources: 13 | requests: 14 | storage: 10Gi 15 | 16 | -------------------------------------------------------------------------------- /pv-provisioning/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2015 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | . $(dirname ${BASH_SOURCE})/../util.sh 18 | 19 | desc "There are no claims" 20 | run "kubectl --namespace=demos get pvc" 21 | 22 | desc "Create a claim" 23 | run "cat $(relative claim.yaml)" 24 | run "kubectl --namespace=demos create -f $(relative claim.yaml)" 25 | 26 | desc "Check it out" 27 | run "kubectl --namespace=demos describe pvc pv-provisioning-demo" 28 | 29 | desc "Wait for it to be satisfied" 30 | run "while true; do 31 | X=\$(kubectl --namespace=demos get pvc pv-provisioning-demo); 32 | echo \"\$X\"; 33 | echo \$X | grep Bound >/dev/null && break; 34 | sleep 1; 35 | done" 36 | 37 | desc "You can see it in gcloud" 38 | run "gcloud compute disks list | grep kubernetes-dynamic" 39 | 40 | desc "Create a pod using the claim" 41 | run "cat $(relative pod.yaml)" 42 | run "kubectl --namespace=demos create -f $(relative pod.yaml)" 43 | 44 | desc "Here's the pod" 45 | run "kubectl --namespace=demos describe pods -l demo=pv-provisioning" 46 | 47 | desc "Wait for it to be running" 48 | run "while true; do 49 | X=\$(kubectl --namespace=demos get pods -l demo=pv-provisioning); 50 | echo \"\$X\"; 51 | echo \$X | grep Running >/dev/null && break; 52 | sleep 1; 53 | done" 54 | 55 | POD=$(kubectl --namespace=demos get pods -l demo=pv-provisioning -o name | cut -d/ -f2) 56 | desc "Shell into it" 57 | run "kubectl --namespace=demos exec --tty -i $POD sh" 58 | 59 | desc "Kill the pod" 60 | run "kubectl --namespace=demos delete pods -l demo=pv-provisioning" 61 | run "kubectl --namespace=demos get pods -l demo=pv-provisioning" 62 | 63 | desc "The claim still exists" 64 | run "kubectl --namespace=demos describe pvc pv-provisioning-demo" 65 | 66 | desc "The disk still exists" 67 | run "gcloud compute disks list | grep kubernetes-dynamic" 68 | 69 | desc "Run another pod using the same claim" 70 | run "kubectl --namespace=demos create -f $(relative pod.yaml)" 71 | 72 | desc "Wait for it to be running" 73 | run "while true; do 74 | X=\$(kubectl --namespace=demos get pods -l demo=pv-provisioning); 75 | echo \"\$X\"; 76 | echo \$X | grep Running >/dev/null && break; 77 | sleep 1; 78 | done" 79 | 80 | POD=$(kubectl --namespace=demos get pods -l demo=pv-provisioning -o name | cut -d/ -f2) 81 | desc "Shell into the new one" 82 | run "kubectl --namespace=demos exec --tty -i $POD sh" 83 | 84 | desc "Tear it down" 85 | run "kubectl --namespace=demos delete pods -l demo=pv-provisioning" 86 | run "kubectl --namespace=demos get pods -l demo=pv-provisioning" 87 | run "kubectl --namespace=demos delete pvc -l demo=pv-provisioning" 88 | run "kubectl --namespace=demos get pvc -l demo=pv-provisioning" 89 | run "kubectl --namespace=demos get pv" 90 | -------------------------------------------------------------------------------- /pv-provisioning/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | generateName: pv-provisioning-demo- 6 | labels: 7 | demo: pv-provisioning 8 | spec: 9 | terminationGracePeriodSeconds: 0 10 | containers: 11 | - name: busybox 12 | image: busybox 13 | command: 14 | - sh 15 | - -c 16 | - touch /pv/`hostname`; while true; do sleep 3600; done 17 | volumeMounts: 18 | - name: pv 19 | mountPath: /pv 20 | volumes: 21 | - name: pv 22 | persistentVolumeClaim: 23 | claimName: pv-provisioning-demo 24 | -------------------------------------------------------------------------------- /quota/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "There is no quota" 19 | run "kubectl --namespace=demos get quota" 20 | 21 | desc "Install quota" 22 | run "cat $(relative quota.yaml)" 23 | run "kubectl --namespace=demos create -f $(relative quota.yaml)" 24 | run "kubectl --namespace=demos describe quota demo-quota" 25 | 26 | desc "Create a large pod - should fail" 27 | run "cat $(relative pod1.yaml)" 28 | run "kubectl --namespace=demos create -f $(relative pod1.yaml)" 29 | run "kubectl --namespace=demos describe quota demo-quota" 30 | 31 | desc "Create a pod with no limits - should fail" 32 | run "cat $(relative pod2.yaml)" 33 | run "kubectl --namespace=demos create -f $(relative pod2.yaml)" 34 | run "kubectl --namespace=demos describe quota demo-quota" 35 | 36 | desc "There are no default limits" 37 | run "kubectl --namespace=demos get limits" 38 | 39 | desc "Set default limits" 40 | run "cat $(relative limits.yaml)" 41 | run "kubectl --namespace=demos create -f $(relative limits.yaml)" 42 | run "kubectl --namespace=demos describe limits demo-limits" 43 | 44 | desc "Create a pod with no limits - should succeed now" 45 | run "cat $(relative pod2.yaml)" 46 | run "kubectl --namespace=demos create -f $(relative pod2.yaml)" 47 | run "kubectl --namespace=demos describe quota demo-quota" 48 | -------------------------------------------------------------------------------- /quota/limits.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: LimitRange 3 | metadata: 4 | name: demo-limits 5 | namespace: demos 6 | spec: 7 | limits: 8 | - type: Container 9 | defaultRequest: 10 | cpu: 100m 11 | memory: 256Mi 12 | -------------------------------------------------------------------------------- /quota/pod1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | name: quota-demo-large 6 | spec: 7 | containers: 8 | - name: hostname 9 | image: k8s.gcr.io/serve_hostname:1.1 10 | resources: 11 | limits: 12 | cpu: 4.1 13 | memory: 4.1Gi 14 | -------------------------------------------------------------------------------- /quota/pod2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | name: quota-demo-unspecified 6 | spec: 7 | containers: 8 | - name: hostname 9 | image: k8s.gcr.io/serve_hostname:1.1 10 | -------------------------------------------------------------------------------- /quota/quota.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ResourceQuota 3 | metadata: 4 | name: demo-quota 5 | namespace: demos 6 | spec: 7 | hard: 8 | cpu: 4 9 | memory: 4Gi 10 | -------------------------------------------------------------------------------- /replicasets/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Run some pods under a replica set" 19 | run "cat $(relative rs.yaml)" 20 | run "kubectl --namespace=demos create -f $(relative rs.yaml) --validate=false" 21 | desc "Look what I made!" 22 | run "kubectl --namespace=demos get replicasets" 23 | 24 | desc "These are the pods that were created" 25 | run "kubectl --namespace=demos get pods -l run=hostnames" 26 | 27 | trap "" SIGINT 28 | 29 | desc "Kill a pod" 30 | VICTIM=$(kubectl --namespace=demos get pods -o name -l run=hostnames | tail -1) 31 | run "kubectl --namespace=demos delete $VICTIM" 32 | run "kubectl --namespace=demos get pods -l run=hostnames" 33 | 34 | desc "Check on which nodes the pods are running" 35 | run "kubectl --namespace=demos get pods -l run=hostnames -o wide" 36 | desc "Kill a node" 37 | NODE=$(kubectl --namespace=demos get pods -l run=hostnames -o wide \ 38 | | tail -1 \ 39 | | awk '{print $NF}') 40 | 41 | run "gcloud compute ssh --zone=us-central1-b $NODE --command '\\ 42 | sudo shutdown -r now; \\ 43 | '" 44 | while true; do 45 | run "kubectl --namespace=demos get node $NODE" 46 | # TODO: It's possible the two runs get different results. Need to get the output of run. 47 | status=$(kubectl --namespace=demos get node $NODE | tail -1 | awk '{print $2}') 48 | if [ "$status" == "NotReady" ]; then 49 | break 50 | fi 51 | done 52 | 53 | while true; do 54 | run "kubectl --namespace=demos get pods -l run=hostnames -o wide" 55 | pods_on_restarting_node=$(kubectl --namespace=demos get pods -l run=hostnames -o wide | grep $NODE) 56 | if [ -z "${pods_on_restarting_node}" ]; then 57 | break 58 | fi 59 | done 60 | -------------------------------------------------------------------------------- /replicasets/rs.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: ReplicaSet 3 | metadata: 4 | name: hostnames 5 | spec: 6 | replicas: 5 7 | selector: 8 | matchLabels: 9 | run: hostnames 10 | template: 11 | metadata: 12 | labels: 13 | run: hostnames 14 | spec: 15 | containers: 16 | - name: demo 17 | image: k8s.gcr.io/serve_hostname:1.1 18 | -------------------------------------------------------------------------------- /replication_controllers/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Run some pods under a replication controller" 19 | run "kubectl --namespace=demos run hostnames \\ 20 | --image=k8s.gcr.io/serve_hostname:1.1 \\ 21 | --replicas=5 \\ 22 | -o name" 23 | WHAT_WAS_RUN="$DEMO_RUN_STDOUT" 24 | 25 | desc "Look what I made!" 26 | run "kubectl --namespace=demos describe $WHAT_WAS_RUN" 27 | 28 | desc "These are the pods that were created" 29 | run "kubectl --namespace=demos get pods -l run=hostnames" 30 | 31 | IPS=($(kubectl --namespace=demos get pods -l run=hostnames \ 32 | -o go-template='{{range .items}}{{.status.podIP}}{{"\n"}}{{end}}')) 33 | desc "SSH into my cluster and access the pods" 34 | run "kubectl --namespace=demos get pods -l run=hostnames \\ 35 | -o go-template='{{range .items}}{{.status.podIP}}{{\"\\n\"}}{{end}}'" 36 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 37 | for IP in ${IPS[*]}; do \\ 38 | curl --connect-timeout 1 -s \$IP:9376 && echo; \\ 39 | done \\ 40 | '" 41 | 42 | desc "Kill a pod" 43 | VICTIM=$(kubectl --namespace=demos get pods -o name -l run=hostnames | tail -1) 44 | run "kubectl --namespace=demos delete $VICTIM" 45 | run "kubectl --namespace=demos get pods -l run=hostnames" 46 | run "kubectl --namespace=demos describe $WHAT_WAS_RUN" 47 | 48 | desc "Kill a node" 49 | NODE=$(kubectl --namespace=demos get pods -l run=hostnames -o wide \ 50 | | tail -1 \ 51 | | awk '{print $NF}') 52 | run "kubectl --namespace=demos get pods -l run=hostnames -o wide" 53 | run "gcloud compute ssh --zone=us-central1-b $NODE --command '\\ 54 | sudo shutdown -r now; \\ 55 | '" 56 | while true; do 57 | run "kubectl --namespace=demos get node $NODE" 58 | status=$(kubectl --namespace=demos get node $NODE | tail -1 | awk '{print $2}') 59 | if [ "$status" == "NotReady" ]; then 60 | break 61 | fi 62 | done 63 | run "kubectl --namespace=demos get pods -l run=hostnames -o wide" 64 | run "kubectl --namespace=demos describe $WHAT_WAS_RUN" 65 | -------------------------------------------------------------------------------- /reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/util.sh 17 | kubectl delete namespace demos 18 | while kubectl get namespace demos >/dev/null 2>&1; do 19 | kubectl get namespace demos 20 | done 21 | kubectl apply -f $(relative demo-namespace.yaml) 22 | tmux kill-session -t my-session 23 | -------------------------------------------------------------------------------- /rolling_update/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Create a service that fronts any version of this demo" 19 | run "cat $(relative svc.yaml)" 20 | run "kubectl --namespace=demos create -f $(relative svc.yaml)" 21 | 22 | desc "Run v1 of our app" 23 | run "cat $(relative rc-v1.yaml)" 24 | run "kubectl --namespace=demos create -f $(relative rc-v1.yaml)" 25 | 26 | tmux new -d -s my-session \ 27 | "sleep 10; $(dirname ${BASH_SOURCE})/split1_update.sh" \; \ 28 | split-window -h -d "$(dirname $BASH_SOURCE)/split1_hit_svc.sh" \; \ 29 | attach \; 30 | -------------------------------------------------------------------------------- /rolling_update/rc-v1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ReplicationController 3 | metadata: 4 | namespace: demos 5 | name: update-demo-v1 6 | spec: 7 | replicas: 5 8 | selector: 9 | demo: update 10 | demo-version: v1 11 | template: 12 | metadata: 13 | labels: 14 | demo: update 15 | demo-version: v1 16 | spec: 17 | containers: 18 | - name: busybox 19 | image: busybox 20 | command: 21 | - sh 22 | - -c 23 | - while true; do echo "$(hostname) v1" > /data/index.html; sleep 60; done 24 | volumeMounts: 25 | - name: content 26 | mountPath: /data 27 | - name: nginx 28 | image: nginx 29 | volumeMounts: 30 | - name: content 31 | mountPath: /usr/share/nginx/html 32 | readOnly: true 33 | volumes: 34 | - name: content 35 | -------------------------------------------------------------------------------- /rolling_update/rc-v2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ReplicationController 3 | metadata: 4 | namespace: demos 5 | name: update-demo-v2 6 | spec: 7 | replicas: 5 8 | selector: 9 | demo: update 10 | demo-version: v2 11 | template: 12 | metadata: 13 | labels: 14 | demo: update 15 | demo-version: v2 16 | spec: 17 | containers: 18 | - name: busybox 19 | image: busybox 20 | command: 21 | - sh 22 | - -c 23 | - while true; do echo "$(hostname) v2" > /data/index.html; sleep 60; done 24 | volumeMounts: 25 | - name: content 26 | mountPath: /data 27 | - name: nginx 28 | image: nginx 29 | volumeMounts: 30 | - name: content 31 | mountPath: /usr/share/nginx/html 32 | readOnly: true 33 | volumes: 34 | - name: content 35 | -------------------------------------------------------------------------------- /rolling_update/split1_hit_svc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | IP=$(kubectl --namespace=demos get svc update-demo \ 19 | -o go-template='{{.spec.clusterIP}}') 20 | 21 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 22 | while true; do \\ 23 | curl --connect-timeout 1 -s $IP; \\ 24 | sleep 0.5; \\ 25 | done \\ 26 | '" 27 | -------------------------------------------------------------------------------- /rolling_update/split1_update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Do a rolling update to v2" 19 | run "cat $(relative rc-v2.yaml)" 20 | run "kubectl --namespace=demos rolling-update \\ 21 | update-demo-v1 -f $(relative rc-v2.yaml) --update-period=5s" 22 | -------------------------------------------------------------------------------- /rolling_update/svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | namespace: demos 5 | name: update-demo 6 | spec: 7 | ports: 8 | - port: 80 9 | protocol: TCP 10 | selector: 11 | demo: update 12 | -------------------------------------------------------------------------------- /secrets/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Create a secret" 19 | run "cat $(relative secret.yaml)" 20 | run "kubectl --namespace=demos create -f $(relative secret.yaml)" 21 | 22 | desc "Create a pod which uses that secret" 23 | run "cat $(relative pod.yaml)" 24 | run "kubectl --namespace=demos create -f $(relative pod.yaml)" 25 | 26 | while true; do 27 | run "kubectl --namespace=demos get pod secrets-demo" 28 | status=$(kubectl --namespace=demos get pod secrets-demo | tail -1 | awk '{print $3}') 29 | if [ "$status" == "Running" ]; then 30 | break 31 | fi 32 | done 33 | run "kubectl --namespace=demos exec --tty -i secrets-demo sh" 34 | -------------------------------------------------------------------------------- /secrets/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | namespace: demos 5 | name: secrets-demo 6 | spec: 7 | containers: 8 | - name: busybox 9 | image: busybox 10 | command: 11 | - sh 12 | - -c 13 | - while true; do sleep 3600; done 14 | volumeMounts: 15 | - name: my-password 16 | mountPath: /data 17 | volumes: 18 | - name: my-password 19 | secret: 20 | secretName: my-secret-password 21 | -------------------------------------------------------------------------------- /secrets/secret.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | metadata: 4 | namespace: demos 5 | name: my-secret-password 6 | type: opaque 7 | data: 8 | username: dGhvY2tpbgo= 9 | password: eW91IHdpc2gK 10 | -------------------------------------------------------------------------------- /services/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | desc "Run some pods" 19 | run "kubectl --namespace=demos run hostnames-svc \\ 20 | --image=k8s.gcr.io/serve_hostname:1.1 \\ 21 | --replicas=5 \\ 22 | -o name" 23 | WHAT_WAS_RUN="$DEMO_RUN_STDOUT" 24 | 25 | desc "Expose the result as a service" 26 | run "kubectl --namespace=demos expose $WHAT_WAS_RUN \\ 27 | --port=80 --target-port=9376" 28 | 29 | desc "Have a look at the service" 30 | run "kubectl --namespace=demos describe svc hostnames-svc" 31 | 32 | IP=$(kubectl --namespace=demos get svc hostnames-svc \ 33 | -o go-template='{{.spec.clusterIP}}') 34 | desc "See what happens when you access the service's IP" 35 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 36 | for i in \$(seq 1 10); do \\ 37 | curl --connect-timeout 1 -s $IP && echo; \\ 38 | done \\ 39 | '" 40 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 41 | for i in \$(seq 1 500); do \\ 42 | curl --connect-timeout 1 -s $IP && echo; \\ 43 | done | sort | uniq -c; \\ 44 | '" 45 | 46 | tmux new -d -s my-session \ 47 | "sleep 10; $(dirname ${BASH_SOURCE})/split1_scale.sh $WHAT_WAS_RUN" \; \ 48 | split-window -h -d "$(dirname $BASH_SOURCE)/split1_hit_svc.sh $WHAT_WAS_RUN" \; \ 49 | attach \; 50 | -------------------------------------------------------------------------------- /services/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: hostnames 5 | spec: 6 | ports: 7 | - port: 80 8 | targetPort: 9376 9 | selector: 10 | run: hostnames 11 | -------------------------------------------------------------------------------- /services/split1_hit_svc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | IP=$(kubectl --namespace=demos get svc hostnames-svc \ 19 | -o go-template='{{.spec.clusterIP}}') 20 | 21 | run "gcloud compute ssh --zone=us-central1-b $SSH_NODE --command '\\ 22 | while true; do \\ 23 | curl --connect-timeout 1 -s $IP && echo; \\ 24 | sleep 0.5; \\ 25 | done \\ 26 | '" 27 | -------------------------------------------------------------------------------- /services/split1_scale.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/../util.sh 17 | 18 | WHAT_WAS_RUN="$1" 19 | 20 | desc "Resize the RC and watch the service backends change" 21 | run "kubectl --namespace=demos scale $WHAT_WAS_RUN --replicas=1" 22 | run "kubectl --namespace=demos scale $WHAT_WAS_RUN --replicas=2" 23 | run "kubectl --namespace=demos scale $WHAT_WAS_RUN --replicas=5" 24 | 25 | desc "Fire up a cloud load-balancer" 26 | run "kubectl --namespace=demos get svc hostnames-svc -o yaml \\ 27 | | sed 's/ClusterIP/LoadBalancer/' \\ 28 | | kubectl replace -f -" 29 | while true; do 30 | run "kubectl --namespace=demos get svc hostnames -o yaml | grep loadBalancer -A 4" 31 | if kubectl --namespace=demos get svc hostnames \ 32 | -o go-template='{{index (index .status.loadBalancer.ingress 0) "ip"}}' \ 33 | >/dev/null 2>&1; then 34 | break 35 | fi 36 | done 37 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | . $(dirname ${BASH_SOURCE})/util.sh 17 | 18 | desc "The demo namespace does not exist" 19 | run "kubectl get namespaces" 20 | 21 | desc "Create a namespace for these demos" 22 | run "cat $(relative demo-namespace.yaml)" 23 | run "kubectl apply -f $(relative demo-namespace.yaml)" 24 | 25 | desc "Hey look, a namespace!" 26 | run "kubectl get namespaces" 27 | -------------------------------------------------------------------------------- /util.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 The Kubernetes Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | readonly reset=$(tput sgr0) 17 | readonly green=$(tput bold; tput setaf 2) 18 | readonly yellow=$(tput bold; tput setaf 3) 19 | readonly blue=$(tput bold; tput setaf 6) 20 | readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi) 21 | 22 | function desc() { 23 | maybe_first_prompt 24 | echo -e "$blue# $@$reset" 25 | prompt 26 | } 27 | 28 | function desc_type() { 29 | maybe_first_prompt 30 | rate=25 31 | if [ -n "$DEMO_RUN_FAST" ]; then 32 | rate=1000 33 | fi 34 | if [ -n "$DEMO_RUN_SPEED" ]; then 35 | rate=$DEMO_RUN_SPEED 36 | fi 37 | echo -e "$blue# $@$reset" | pv -qL $rate 38 | 39 | prompt 40 | } 41 | 42 | function prompt() { 43 | echo -n "$yellow\$ $reset" 44 | } 45 | 46 | started="" 47 | function maybe_first_prompt() { 48 | if [ -z "$started" ]; then 49 | prompt 50 | started=true 51 | fi 52 | } 53 | 54 | # After a `run` this variable will hold the stdout of the command that was run. 55 | # If the command was interactive, this will likely be garbage. 56 | DEMO_RUN_STDOUT="" 57 | 58 | function run() { 59 | maybe_first_prompt 60 | rate=25 61 | if [ -n "$DEMO_RUN_FAST" ]; then 62 | rate=1000 63 | fi 64 | if [ -n "$DEMO_RUN_SPEED" ]; then 65 | rate=$DEMO_RUN_SPEED 66 | fi 67 | echo "$green$1$reset" | pv -qL $rate 68 | if [ -n "$DEMO_RUN_FAST" ]; then 69 | sleep 0.5 70 | fi 71 | OFILE="$(mktemp)" 72 | script -eq -c "$1" -f "$OFILE" 73 | r=$? 74 | read -d '' -t "${timeout}" -n 10000 # clear stdin 75 | prompt 76 | if [ -z "$DEMO_AUTO_RUN" ]; then 77 | read -s 78 | fi 79 | DEMO_RUN_STDOUT="$(tail -n +2 $OFILE | head -n -2 | sed 's/\r//g')" 80 | rm $OFILE 81 | return $r 82 | } 83 | 84 | function relative() { 85 | for arg; do 86 | echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|" 87 | done 88 | } 89 | 90 | SSH_NODE=$(kubectl get nodes | tail -1 | cut -f1 -d' ') 91 | 92 | trap "echo" EXIT 93 | --------------------------------------------------------------------------------