File tree Expand file tree Collapse file tree 4 files changed +134
-0
lines changed Expand file tree Collapse file tree 4 files changed +134
-0
lines changed Original file line number Diff line number Diff line change 1+ tgz :
2+ @find . -regex ' ./[A-Z][a-z].*\.yaml' -type f -print0 \
3+ | tar --null --files-from - -cf examples.tar
4+ @tar -uf examples.tar kubectl-examples
5+ gzip examples.tar
6+
7+ sha = $(shell shasum -a 256 < examples.tar.gz|cut -d" " -f1)
8+
9+ update :
10+ @sed -i ' s/sha256: .*$$/sha256: $(sha)/' plugins/examples.yaml
11+
12+ install : clean tgz update
13+ kubectl krew install --manifest=plugins/examples.yaml --archive=examples.tar.gz
14+
15+ clean :
16+ @rm -f examples.tar.gz
17+ @kubectl krew uninstall examples || :
Original file line number Diff line number Diff line change @@ -15,6 +15,37 @@ At Container Solutions we find we regularly need chunks of YAML to demonstrate
1515
1616This might be to do a basic test of an environment, find an example to tinker with, or send to someone to get them going.
1717
18+ ## Usage
19+
20+ The examples can be used by a kubectl plugin ` examples ` . This plugin can be installed
21+ by [ krew] ( https://krew.sigs.k8s.io/ ) :
22+
23+ - first [ install krew] ( https://krew.sigs.k8s.io/docs/user-guide/setup/install/ )
24+ - Install a custom plugin index: ` kubectl krew index add cs https://github.com/lalyos/kubernetes-examples.git `
25+ - Install this plugin: ` kubectl krew install cs/examples `
26+
27+ Interactively discover by first selecting the resource type:
28+ ```
29+ $ kubectl examples
30+ ```
31+
32+ filter by resource type
33+ ```
34+ $ kubectl examples Service
35+ ```
36+
37+ filter by resource type and pattern
38+ ```
39+ $ kubectl examples Pod res
40+ ```
41+
42+ If there is only a single match selected by the parameters, it is printed to the stdout.
43+ So you can deploy a modified version of a sample by:
44+ ```
45+ $ export KUBE_EDITOR='code -w'
46+ $ kubectl examples Ingress fanout | kubectl create -f - --edit
47+ ```
48+
1849## Sections
1950
2051` broken-* ` - yamls that exemplify broken kubernetes yaml states
@@ -27,6 +58,8 @@ If an example is an exemplar of a particular feature but tightly related to anot
2758
2859Symlinks are also used to make finding things easier, eg ` Service/headless-service -> Service/spec.clusterIP ` .
2960
61+ ` plugins ` - a directory following the spec for a Custom krew [ plugin index] ( https://krew.sigs.k8s.io/docs/user-guide/custom-indexes/ )
62+
3063## Principles
3164
3265The examples seek to be:
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ debug () {
4+ [[ " $DEBUG " ]] && echo " -----> $* " 1>&2
5+ }
6+
7+ print-example () {
8+ declare res=$1 pattern=$2
9+
10+ dir=$( dirname $( readlink $BASH_SOURCE ) )
11+ debug " dir=${dir} "
12+
13+ if [[ $res == " " ]]; then
14+ PS3=" Resource Type: "
15+ select res in $( ls -1 $dir | grep -v kubectl-examples) ; do
16+ debug " res type choosen: ${res} "
17+ break
18+ done
19+ fi
20+
21+ # resorce names can be abreviated
22+ [[ -d ${dir} /${res} ]] || res=" ${res} *"
23+
24+ match=0
25+ for f in ${dir} /${res} /** /* ${pattern} * .yaml; do
26+ [[ -e ${f} ]] && : $(( match++ ))
27+ done
28+
29+ case ${match} in
30+ 0)
31+ debug " no match ..."
32+ return
33+ ;;
34+ 1)
35+ debug " exact match"
36+ yaml=${dir} /${res} * /** /* ${pattern} * .yaml
37+ ;;
38+ * )
39+ debug " multiple choice"
40+ PS3=" Yaml example: "
41+ select yaml in ${dir} /${res} /** /* ${pattern} * .yaml; do
42+ debug " YAML selected: ${yaml} "
43+ break
44+ done
45+ ;;
46+ esac
47+
48+ cat ${yaml}
49+ }
50+
51+ main () {
52+ : ${DEBUG:= 1}
53+ shopt -s globstar
54+ print-example " $@ "
55+ }
56+
57+ [[ " $0 " == " $BASH_SOURCE " ]] && main " $@ " || true
Original file line number Diff line number Diff line change 1+ ---
2+ apiVersion : krew.googlecontainertools.github.com/v1alpha2
3+ kind : Plugin
4+ metadata :
5+ name : examples
6+ spec :
7+ version : " v0.0.1"
8+ homepage : https://github.com/ContainerSolutions/kubernetes-examples
9+ shortDescription : " Prints sample manifests"
10+ description : |
11+ A reference repository of YAML with canonical
12+ and as-simple-as-possible demonstrations of
13+ kubernetes functionality and features.
14+ platforms :
15+ - selector :
16+ matchExpressions :
17+ - key : " os"
18+ operator : " In"
19+ values :
20+ - darwin
21+ - linux
22+ uri : https://github.com/lalyos/kubernetes-examples/releases/download/v0.0.1/examples.tar.gz
23+ sha256 : f6e5cab7e4a94f322f0521b3384c0470ac7f0d8136af115e44423d2533885b5e
24+ files :
25+ - from : " *"
26+ to : " ."
27+ bin : kubectl-examples
You can’t perform that action at this time.
0 commit comments