commit
d550f7d666
|
|
@ -39,6 +39,6 @@ go get k8s.io/kubectl/cmd/kinflate
|
||||||
|
|
||||||
## Demos
|
## Demos
|
||||||
|
|
||||||
* [hello world one-pager](shortDemo.md)
|
* [hello world one-pager](demoHelloWorldShort.md)
|
||||||
* [hello world detailed, with instances](longerDemo/README.md)
|
* [hello world detailed, with instances](demoHelloWorldLong/README.md)
|
||||||
* [mysql](getting_started.md)
|
* [mysql](demoMySql.md)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,8 @@ Goal:
|
||||||
1. Customize it.
|
1. Customize it.
|
||||||
1. Create two different instances based on the customization.
|
1. Create two different instances based on the customization.
|
||||||
|
|
||||||
First install the tool, and define a place to work locally:
|
First define a place to work:
|
||||||
|
|
||||||
<!-- @install @test -->
|
|
||||||
```
|
|
||||||
go get k8s.io/kubectl/cmd/kinflate
|
|
||||||
```
|
|
||||||
<!-- @makeWorkplace @test -->
|
<!-- @makeWorkplace @test -->
|
||||||
```
|
```
|
||||||
DEMO_HOME=$(mktemp -d)
|
DEMO_HOME=$(mktemp -d)
|
||||||
|
|
@ -23,6 +19,4 @@ Alternatively, use
|
||||||
> DEMO_HOME=~/hello
|
> DEMO_HOME=~/hello
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__Next:__ [Clone an Example](clone.md)
|
__Next:__ [Clone an Example](clone.md)
|
||||||
|
|
@ -6,8 +6,8 @@ production scenario.
|
||||||
|
|
||||||
In the production environment we want:
|
In the production environment we want:
|
||||||
|
|
||||||
- MySQL resource names to be prefixed by 'prod-' to make them distinguishable.
|
- MySQL resource names to be prefixed by 'prod-'.
|
||||||
- MySQL resources to have 'env: prod' labels so that we can use label selector to query these.
|
- MySQL resources to have 'env: prod' labels.
|
||||||
- MySQL to use persistent disk for storing data.
|
- MySQL to use persistent disk for storing data.
|
||||||
|
|
||||||
### Download resources
|
### Download resources
|
||||||
|
|
@ -18,8 +18,7 @@ could add to a k8s cluster to run MySql.
|
||||||
|
|
||||||
<!-- @makeMySQLDir @test -->
|
<!-- @makeMySQLDir @test -->
|
||||||
```
|
```
|
||||||
DEMO_HOME=$HOME/kinflate_demo/mysql
|
DEMO_HOME=$(mktemp -d)
|
||||||
rm -rf $DEMO_HOME && mkdir -p $DEMO_HOME
|
|
||||||
cd $DEMO_HOME
|
cd $DEMO_HOME
|
||||||
|
|
||||||
# Get MySQL configs
|
# Get MySQL configs
|
||||||
|
|
@ -30,14 +29,13 @@ done
|
||||||
|
|
||||||
### Initialize a manifest
|
### Initialize a manifest
|
||||||
|
|
||||||
A manifest is needed to group these resources together.
|
A _manifest_ groups these resources together.
|
||||||
|
|
||||||
Create one:
|
Create one:
|
||||||
|
|
||||||
<!-- @initApp @test -->
|
<!-- @initApp @test -->
|
||||||
```
|
```
|
||||||
mkdir -p $DEMO_HOME/prod
|
cd $DEMO_HOME
|
||||||
cd $DEMO_HOME/prod
|
|
||||||
kinflate init
|
kinflate init
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -45,7 +43,7 @@ You should now have a file called `Kube-manifest.yaml`:
|
||||||
|
|
||||||
<!-- @catMan @test -->
|
<!-- @catMan @test -->
|
||||||
```
|
```
|
||||||
cat $DEMO_HOME/prod/Kube-manifest.yaml
|
cat $DEMO_HOME/Kube-manifest.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
containing something like:
|
containing something like:
|
||||||
|
|
@ -76,17 +74,15 @@ containing something like:
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
|
||||||
### Add resources
|
### Add the resources to the manifest
|
||||||
|
|
||||||
Add the resources to the manifest
|
|
||||||
|
|
||||||
<!-- @addResources @test -->
|
<!-- @addResources @test -->
|
||||||
```
|
```
|
||||||
cd $DEMO_HOME/prod
|
cd $DEMO_HOME
|
||||||
|
|
||||||
kinflate add resource ../secret.yaml
|
kinflate add resource secret.yaml
|
||||||
kinflate add resource ../service.yaml
|
kinflate add resource service.yaml
|
||||||
kinflate add resource ../deployment.yaml
|
kinflate add resource deployment.yaml
|
||||||
|
|
||||||
cat Kube-manifest.yaml
|
cat Kube-manifest.yaml
|
||||||
```
|
```
|
||||||
|
|
@ -97,14 +93,12 @@ cat Kube-manifest.yaml
|
||||||
> apiVersion: manifest.k8s.io/v1alpha1
|
> apiVersion: manifest.k8s.io/v1alpha1
|
||||||
> ....
|
> ....
|
||||||
> resources:
|
> resources:
|
||||||
> - ../secret.yaml
|
> - secret.yaml
|
||||||
> - ../service.yaml
|
> - service.yaml
|
||||||
> - ../deployment.yaml
|
> - deployment.yaml
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
Now we are ready to apply our first customization.
|
### Name Customization
|
||||||
|
|
||||||
### NamePrefix Customization
|
|
||||||
|
|
||||||
Arrange for the MySQL resources to begin with prefix
|
Arrange for the MySQL resources to begin with prefix
|
||||||
_prod-_ (since they are meant for the _production_
|
_prod-_ (since they are meant for the _production_
|
||||||
|
|
@ -112,7 +106,7 @@ environment):
|
||||||
|
|
||||||
<!-- @customizeLabel @test -->
|
<!-- @customizeLabel @test -->
|
||||||
```
|
```
|
||||||
cd $DEMO_HOME/prod
|
cd $DEMO_HOME
|
||||||
|
|
||||||
kinflate set nameprefix 'prod-'
|
kinflate set nameprefix 'prod-'
|
||||||
|
|
||||||
|
|
@ -127,16 +121,14 @@ cat Kube-manifest.yaml
|
||||||
> namePrefix: prod-
|
> namePrefix: prod-
|
||||||
> objectAnnotations:
|
> objectAnnotations:
|
||||||
> note: This is a example annotation
|
> note: This is a example annotation
|
||||||
|
> ```
|
||||||
|
|
||||||
This `namePrefix` directive adds _prod-_ to all
|
This `namePrefix` directive adds _prod-_ to all
|
||||||
resource names.
|
resource names.
|
||||||
|
|
||||||
Run kinflate:
|
|
||||||
|
|
||||||
<!-- @genNamePrefixConfig @test -->
|
<!-- @genNamePrefixConfig @test -->
|
||||||
```
|
```
|
||||||
cd $DEMO_HOME/prod
|
kinflate inflate -f $DEMO_HOME
|
||||||
kinflate inflate -f .
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The output should contain:
|
The output should contain:
|
||||||
|
|
@ -180,8 +172,8 @@ label, but we can edit `Kube-manifest.yaml` file under
|
||||||
|
|
||||||
<!-- @customizeLabels @test -->
|
<!-- @customizeLabels @test -->
|
||||||
```
|
```
|
||||||
cd $DEMO_HOME/prod
|
sed -i 's/app: helloworld/app: prod/' \
|
||||||
sed -i 's/app: helloworld/app: prod/' Kube-manifest.yaml
|
$DEMO_HOME/Kube-manifest.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
At this point, running `kinflate inflate -f .` will
|
At this point, running `kinflate inflate -f .` will
|
||||||
|
|
@ -197,12 +189,9 @@ environment. So we want to use Persistent Disk in
|
||||||
production. Kinflate lets you apply `patches` to the
|
production. Kinflate lets you apply `patches` to the
|
||||||
resources.
|
resources.
|
||||||
|
|
||||||
<!-- @customizeOverlay @test -->
|
<!-- @createPatchFile @test -->
|
||||||
```
|
```
|
||||||
cd $DEMO_HOME/prod
|
cat <<'EOF' > $DEMO_HOME/persistent-disk.yaml
|
||||||
|
|
||||||
# Create a patch for persistent-disk.yaml
|
|
||||||
cat <<'EOF' > persistent-disk.yaml
|
|
||||||
apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2
|
apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
|
|
@ -216,9 +205,13 @@ spec:
|
||||||
gcePersistentDisk:
|
gcePersistentDisk:
|
||||||
pdName: mysql-persistent-storage
|
pdName: mysql-persistent-storage
|
||||||
EOF
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
# Edit the manifest file to add the above patch:
|
Specify the patch file in the manifest:
|
||||||
cat <<'EOF' >> $DEMO_HOME/prod/Kube-manifest.yaml
|
|
||||||
|
<!-- @specifyPatch @test -->
|
||||||
|
```
|
||||||
|
cat <<'EOF' >> $DEMO_HOME/Kube-manifest.yaml
|
||||||
patches:
|
patches:
|
||||||
- persistent-disk.yaml
|
- persistent-disk.yaml
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -242,5 +235,5 @@ create the production environment.
|
||||||
|
|
||||||
<!-- @finalInflation @test -->
|
<!-- @finalInflation @test -->
|
||||||
```
|
```
|
||||||
kinflate inflate -f $DEMO_HOME/prod # | kubectl apply -f -
|
kinflate inflate -f $DEMO_HOME # | kubectl apply -f -
|
||||||
```
|
```
|
||||||
Loading…
Reference in New Issue