Skip to content
Permalink
Browse files

address comments

  • Loading branch information...
Liujingfang1 committed Jun 11, 2018
1 parent b6efde1 commit ab0c9b41184efbcef8293645edd3495db23bbe84
Showing with 13 additions and 14 deletions.
  1. +1 −1 examples/README.md
  2. +12 −13 examples/wordpress/README.md
@@ -30,4 +30,4 @@ go get github.com/kubernetes-sigs/kustomize
* [breakfast](breakfast.md) - Customize breakfast for
Alice and Bob.

* [wordpress](wordpress/README.md) - Create wordpress with mysql
* [container args](wordpress/README.md) - Injecting k8s runtime data into container arguments (e.g. to point wordpress to a SQL service).
@@ -1,10 +1,10 @@
# Demo: WordPress
# Demo: Injecting k8s runtime data into containers

In this tutorial, you will learn - how to use `kustomize` to declare a variable reference and substitute it in container's command.
In this tutorial, you will learn how to use `kustomize` to declare a variable reference and substitute it in container's command.

In the WordPress example, we want
To run WordPress, it's necessary to

- to connect WordPress with a MySQL database
- connect WordPress with a MySQL database
- access the service name of MySQL database from WordPress container

First make a place to work:
@@ -44,7 +44,7 @@ curl -s -o "$MYSQL_HOME/#1.yaml" \
```

### Create kustomization.yaml
We create a new kustomization, which has two bases: mysql and wordpress.
Create a new kustomization with two bases:

<!-- @createKustomization @test -->
```
@@ -57,9 +57,9 @@ EOF
```

### Download patch for WordPress
In the new kustomization, we apply a patch for wordpress deployment. The patch does two things
In the new kustomization, apply a patch for wordpress deployment. The patch does two things
- Add an initial container to show the mysql service name
- Add environment variable for mysql database so that wordpress can connect to it
- Add environment variable that allow wordpress to find the mysql database

<!-- @downloadPatch @test -->
```
@@ -96,11 +96,10 @@ The patch has following content
> name: mysql-pass
> key: password
> ```
In the init container's command, there are two variables as `$(WORDPRESS_SERVICE)` and `$(MYSQL_SERVICE)`, which are for the service names of wordpress and mysql. If we define those variables in `kustomization.yaml`, they will be substituted in `kustomize build` to the correct names.
The init container's command requires information that depends on k8s resource object fields, represented by the placeholder variables
$(WORDPRESS_SERVICE) and $(MYSQL_SERVICE).

### Add Variable Reference
Let us define the variables needed in the init container's command.
### Bind the Variables to k8s Object Fields

<!-- @addVarRef @test -->
```
@@ -123,14 +122,14 @@ EOF
`WORDPRESS_SERVICE` is from the field `metadata.name` of Service `wordpress`. If we don't specify `fieldref`, the default is `metadata.name`. So `MYSQL_SERVICE` is from the field `metadata.name` of Service `mysql`.

### Substitution
We can see the substitution by `kustomize build`
Confirm the variable substitution:

<!-- @kustomizeBuild @test -->
```
kustomize build $DEMO_HOME
```

We will see the init Container's command as
Expect this in the output:

> ```
> (truncated)

0 comments on commit ab0c9b4

Please sign in to comment.
You can’t perform that action at this time.