address comments

This commit is contained in:
Jingfang Liu
2018-06-11 13:52:18 -07:00
parent b6efde13eb
commit ab0c9b4118
2 changed files with 13 additions and 14 deletions

View File

@@ -30,4 +30,4 @@ go get github.com/kubernetes-sigs/kustomize
* [breakfast](breakfast.md) - Customize breakfast for * [breakfast](breakfast.md) - Customize breakfast for
Alice and Bob. 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).

View File

@@ -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 - access the service name of MySQL database from WordPress container
First make a place to work: First make a place to work:
@@ -44,7 +44,7 @@ curl -s -o "$MYSQL_HOME/#1.yaml" \
``` ```
### Create kustomization.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 --> <!-- @createKustomization @test -->
``` ```
@@ -57,9 +57,9 @@ EOF
``` ```
### Download patch for WordPress ### 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 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 --> <!-- @downloadPatch @test -->
``` ```
@@ -96,11 +96,10 @@ The patch has following content
> name: mysql-pass > name: mysql-pass
> key: password > 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).
### Bind the Variables to k8s Object Fields
### Add Variable Reference
Let us define the variables needed in the init container's command.
<!-- @addVarRef @test --> <!-- @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`. `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 ### Substitution
We can see the substitution by `kustomize build` Confirm the variable substitution:
<!-- @kustomizeBuild @test --> <!-- @kustomizeBuild @test -->
``` ```
kustomize build $DEMO_HOME kustomize build $DEMO_HOME
``` ```
We will see the init Container's command as Expect this in the output:
> ``` > ```
> (truncated) > (truncated)