onePageHelloWorld

This commit is contained in:
Jeffrey Regan 2018-04-06 11:02:42 -07:00
parent 3c0eaac23e
commit 7ee7fffe1c
17 changed files with 264 additions and 406 deletions

View File

@ -50,6 +50,5 @@ go get k8s.io/kubectl/cmd/kinflate
## Demos
* [hello world one-pager](demo/helloWorldOnePager.md)
* [hello world detailed](demo/helloWorldDetailed/README.md) (with instances, in slide format)
* [mysql one-pager](demo/mySql.md)
* [hello world](demo/helloWorld.md)
* [mysql](demo/mySql.md)

View File

@ -0,0 +1,262 @@
[manifest]: ../docs/glossary.md#manifest
[base]: ../docs/glossary.md#base
[overlay]: ../docs/glossary.md#overlay
[overlays]: ../docs/glossary.md#overlay
[instance]: ../docs/glossary.md#instance
[instances]: ../docs/glossary.md#instance
[hello]: https://github.com/monopole/hello
[off-the-shelf config]: https://github.com/kinflate/example-hello
[original]: https://github.com/kinflate/example-hello
# Demo: hello world with instances
Steps:
1. Clone an existing configuration as a [base].
1. Customize it.
1. Create two different [overlays] (_staging_ and _production_)
from the customized base.
1. Run kinflate and kubectl to deploy staging and production.
First define a place to work:
<!-- @makeWorkplace @test -->
```
DEMO_HOME=$(mktemp -d)
```
Alternatively, use
> ```
> DEMO_HOME=~/hello
> ```
## Clone an example
Let's run the [hello] service.
Here's an [off-the-shelf config] for it.
Clone it to a directory called `base`:
<!-- @cloneIt @test -->
```
git clone \
https://github.com/kinflate/example-hello \
$DEMO_HOME/base
```
<!-- @runTree @test -->
```
tree $DEMO_HOME
```
One could immediately apply these resources to a
cluster:
> ```
> kubectl apply -f $DEMO_HOME/base
> ```
to instantiate the _hello_ service. This ignores
the [manifest], and just uses the raw resources.
## The Manifest
The `base` directory has a [manifest] file:
<!-- @manifest @test -->
```
BASE=$DEMO_HOME/base
more $BASE/Kube-manifest.yaml
```
Run `kinflate` on the base to emit customized resources
to `stdout`:
<!-- @manifest @test -->
```
kinflate inflate $BASE
```
## Customize the base
A first customization step could be to change the _app
label_ applied to all resources:
<!-- @manifest @test -->
```
sed -i 's/app: hello/app: my-hello/' \
$BASE/Kube-manifest.yaml
```
See the effect:
<!-- @manifest @test -->
```
kinflate inflate $BASE | grep -C 3 app:
```
## Create Overlays
Create a _staging_ and _production_ [overlay]:
* _Staging_ enables a risky feature not enabled in production.
* _Production_ has a higher replica count.
* Greetings from these cluster [instances] will differ
from each other.
<!-- @overlayDirectories @test -->
```
OVERLAYS=$DEMO_HOME/overlays
mkdir -p $OVERLAYS/staging
mkdir -p $OVERLAYS/production
```
#### Staging Manifest
In the `staging` directory, make a manifest
defining a new name prefix, and some different labels.
<!-- @makeStagingManifest @test -->
```
cat <<'EOF' >$OVERLAYS/staging/Kube-manifest.yaml
apiVersion: manifest.k8s.io/v1alpha1
kind: Package
metadata:
name: makes-staging-hello
namePrefix: staging-
objectLabels:
instance: staging
org: acmeCorporation
objectAnnotations:
note: Hello, I am staging!
bases:
- ../../base
patches:
- map.yaml
EOF
```
#### Staging Patch
Add a configmap customization to change the server
greeting from _Good Morning!_ to _Have a pineapple!_
Also, enable the _risky_ flag.
<!-- @stagingMap @test -->
```
cat <<EOF >$OVERLAYS/staging/map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
altGreeting: "Have a pineapple!"
enableRisky: "true"
EOF
```
#### Production Manifest
In the production directory, make a manifest
with a different name prefix and labels.
<!-- @makeProductionManifest @test -->
```
cat <<EOF >$OVERLAYS/production/Kube-manifest.yaml
apiVersion: manifest.k8s.io/v1alpha1
kind: Package
metadata:
name: makes-production-tuthello
namePrefix: production-
objectLabels:
instance: production
org: acmeCorporation
objectAnnotations:
note: Hello, I am production!
bases:
- ../../base
patches:
- deployment.yaml
EOF
```
#### Production Patch
Make a production patch that increases the replica
count (because production takes more traffic).
<!-- @productionDeployment @test -->
```
cat <<EOF >$OVERLAYS/production/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: the-deployment
spec:
replicas: 10
EOF
```
## Compare overlays
`DEMO_HOME` now contains:
- a _base_ directory - a slightly customized clone
of the original configuration, and
- an _overlays_ directory, containing the manifests
and patches required to create distinct _staging_
and _production_ instance in a cluster.
Review the directory structure and differences:
<!-- @listFiles @test -->
```
tree $DEMO_HOME
```
<!-- @compareOutput -->
```
diff \
<(kinflate inflate $OVERLAYS/staging) \
<(kinflate inflate $OVERLAYS/production) |\
more
```
## Deploy
The individual resource sets are:
<!-- @runKinflateStaging @test -->
```
kinflate inflate $OVERLAYS/staging
```
<!-- @runKinflateProduction @test -->
```
kinflate inflate $OVERLAYS/production
```
To deploy, pipe the above commands to kubectl apply:
> ```
> kinflate inflate $OVERLAYS/staging |\
> kubectl apply -f -
> ```
> ```
> kinflate inflate $OVERLAYS/production |\
> kubectl apply -f -
> ```
## Rollback
To rollback, one would undo whatever edits were made to
the configuation in source control, then rerun kinflate
on the reverted configuration and apply it to the
cluster.

View File

@ -1,23 +0,0 @@
# Demo: hello world with instances
Steps:
1. Clone an off-the-shelf configuration as your base.
1. Customize it.
1. Create two different instances (_staging_ and _production_)
from your customized base.
First define a place to work:
<!-- @makeWorkplace @test -->
```
DEMO_HOME=$(mktemp -d)
```
Alternatively, use
> ```
> DEMO_HOME=~/hello
> ```
__Next:__ [Clone an Example](clone.md)

View File

@ -1,5 +0,0 @@
clone
manifest
customize
overlays
editor

View File

@ -1,33 +0,0 @@
# Clone
[hello]: https://github.com/monopole/hello
Assume you want to run the [hello] service.
[off-the-shelf config]: https://github.com/kinflate/example-hello
Find an [off-the-shelf config] for it, and clone that
config into a directory called `base`:
<!-- @cloneIt @test -->
```
git clone \
https://github.com/kinflate/example-hello \
$DEMO_HOME/base
```
<!-- @runTree @test -->
```
tree $DEMO_HOME
```
One could immediately apply these resources to a
cluster:
> ```
> kubectl apply -f $DEMO_HOME/base
> ```
to instantiate the _hello_ service in off-the-shelf form.
__Next:__ [The Base Manifest](manifest.md)

View File

@ -1,18 +0,0 @@
# Customize
A first customization step could be to change the _app label_
applied to all resources:
<!-- @manifest @test -->
```
sed -i 's/app: hello/app: my-hello/' \
$BASE/Kube-manifest.yaml
```
See the effect:
<!-- @manifest @test -->
```
kinflate inflate $BASE | grep -C 3 app:
```
__Next:__ [Overlays](overlays)

View File

@ -1,79 +0,0 @@
# Edit tool
Kinflate's basic function is to read manifests and resources to create new YAML.
It also offers some basic manifest file operations, to let one
change a manifest file safely without using a general editor.
Make a new workspace:
<!-- @workspace @test -->
```
rm -rf $DEMO_HOME/edits
mkdir -p $DEMO_HOME/edits
pushd $DEMO_HOME/edits
```
Create a manifest:
<!-- @init @test -->
```
kinflate init
```
<!-- @showIt @test -->
```
clear
cat Kube-manifest.yaml
```
Write a resource file:
<!-- @writeResource @test -->
```
cat <<EOF >configMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
altGreeting: "Good Morning!"
enableRisky: "false"
EOF
```
<!-- @ls @test -->
```
ls
```
Add it to the manifest:
<!-- @addResource @test -->
```
kinflate add resource configMap.yaml
```
<!-- @confirmIt @test -->
```
grep configMap.yaml Kube-manifest.yaml
```
Attempt to add a missing resource; kinflate should complain.
<!-- @addNoResource -->
```
kinflate add resource does_not_exist.yaml
```
Try to reinit; kinflate should complain.
<!-- @initAgain -->
```
kinflate init
```
<!-- @allDone @test -->
```
popd
```

View File

@ -1,19 +0,0 @@
# Base Manifest
The `base` directory has a _manifest_:
<!-- @manifest @test -->
```
BASE=$DEMO_HOME/base
more $BASE/Kube-manifest.yaml
```
Run kinflate on the base to emit customized resources
to `stdout`:
<!-- @manifest @test -->
```
kinflate inflate $BASE
```
__Next:__ [Customize it](customize.md)

View File

@ -1,16 +0,0 @@
# Overlays
Create a _staging_ and _production_ overlay:
* _Staging_ enables a risky feature not enabled in production.
* _Production_ has a higher replica count.
* Greetings from these instances will differ from each other.
<!-- @overlayDirectories @test -->
```
OVERLAYS=$DEMO_HOME/overlays
mkdir -p $OVERLAYS/staging
mkdir -p $OVERLAYS/production
```
__Next:__ [Staging](staging/manifest.md)

View File

@ -1,4 +0,0 @@
staging
production
compare
deploy

View File

@ -1,28 +0,0 @@
# Compare overlays
[original]: https://github.com/kinflate/example-hello
`DEMO_HOME` now contains:
- a _base_ directory - your slightly customized clone of the [original]
configuration, and
- an _overlays_ directory, containing the manifests and patches required to
create distinct _staging_ and _production_ instance in a cluster.
Review the directory structure and differences:
<!-- @listFiles @test -->
```
tree $DEMO_HOME
```
<!-- @compareOutput -->
```
diff \
<(kinflate inflate $OVERLAYS/staging) \
<(kinflate inflate $OVERLAYS/production) |\
more
```
__Next:__ [Deploy](deploy.md)

View File

@ -1,27 +0,0 @@
# Deploy
The individual resource sets are:
<!-- @runKinflateStaging @test -->
```
kinflate inflate $OVERLAYS/staging
```
<!-- @runKinflateProduction @test -->
```
kinflate inflate $OVERLAYS/production
```
To deploy, pipe the above commands to kubectl apply:
> ```
> kinflate inflate $OVERLAYS/staging |\
> kubectl apply -f -
> ```
> ```
> kinflate inflate $OVERLAYS/production |\
> kubectl apply -f -
> ```
__Next:__ [Editting](../editor.md)

View File

@ -1,26 +0,0 @@
# Production Manifest
In the production directory, make a manifest
with a different name prefix and labels.
<!-- @makeProductionManifest @test -->
```
cat <<EOF >$OVERLAYS/production/Kube-manifest.yaml
apiVersion: manifest.k8s.io/v1alpha1
kind: Package
metadata:
name: makes-production-tuthello
namePrefix: production-
objectLabels:
instance: production
org: acmeCorporation
objectAnnotations:
note: Hello, I am production!
bases:
- ../../base
patches:
- deployment.yaml
EOF
```
__Next:__ [Production Patch](patch.md)

View File

@ -1,18 +0,0 @@
# Production Patch
Make a production patch that increases the replica count (because production
takes more traffic).
<!-- @productionDeployment @test -->
```
cat <<EOF >$OVERLAYS/production/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: the-deployment
spec:
replicas: 6
EOF
```
__Next:__ [Compare](../compare.md)

View File

@ -1,25 +0,0 @@
# Staging Manifest
In the `staging` directory, make a manifest
defining a new name prefix, and some different labels.
<!-- @makeStagingManifest @test -->
```
cat <<'EOF' >$OVERLAYS/staging/Kube-manifest.yaml
apiVersion: manifest.k8s.io/v1alpha1
kind: Package
metadata:
name: makes-staging-hello
namePrefix: staging-
objectLabels:
instance: staging
org: acmeCorporation
objectAnnotations:
note: Hello, I am staging!
bases:
- ../../base
patches:
- map.yaml
EOF
```
__Next:__ [Staging Patch](patch.md)

View File

@ -1,21 +0,0 @@
# Staging patch
Add a configmap customization to change the server
greeting from _Good Morning!_ to _Have a pineapple!_
Also, enable the _risky_ flag.
<!-- @stagingMap @test -->
```
cat <<EOF >$OVERLAYS/staging/map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
altGreeting: "Have a pineapple!"
enableRisky: "true"
EOF
```
__Next:__ [Production Manifest](../production/manifest.md)

View File

@ -1,61 +0,0 @@
# Demo: hello world
[kubectl]: https://kubernetes.io/docs/user-guide/kubectl-overview/
Steps:
1. Clone an off-the-shelf configuration.
1. Customize its resources with a name prefix.
1. Apply the result to a cluster via [kubectl].
First make a place to work:
<!-- @makeDemoDir @test -->
```
DEMO_HOME=$(mktemp -d)
```
[example-hello]: https://github.com/kinflate/example-hello
Clone an example configuration ([example-hello]):
<!-- @cloneExample @test -->
```
cd $DEMO_HOME
git clone https://github.com/kinflate/example-hello
cd example-hello
```
Customize the base application by specifying a prefix
that will be applied to all resource names:
<!-- @customizeApp @test -->
```
kinflate set nameprefix acme-
```
Confirm that the edit happened:
<!-- @confirmEdit @test -->
```
grep --context=3 namePrefix Kube-manifest.yaml
```
Confirm that the prefix appears in the output:
<!-- @confirmResourceNames @test -->
```
kinflate inflate | grep --context=3 acme-
```
Optionally apply the modified configuration to a cluster
<!-- @applyToCluster -->
```
kinflate inflate | kubectl apply -f -
```
This fork of [example-hello] could be commited to a
private repo, and evolve independently of its upstream.
As desired, one could occasionally rebase from upstream
to capture updated base configuration.