mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 18:10:59 +00:00
E2E Tests with multiple apps
This commit is contained in:
155
examples/alphaTestExamples/MultipleDeployments.md
Normal file
155
examples/alphaTestExamples/MultipleDeployments.md
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
[kind]: https://github.com/kubernetes-sigs/kind
|
||||||
|
|
||||||
|
# Demo: Multiple Deployments
|
||||||
|
|
||||||
|
This demo helps you to multiple services on same kubenetes cluster using kustomize.
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Create the resources files for wordpress service.
|
||||||
|
2. Create the resources files for mysql service.
|
||||||
|
3. Spin-up kubernetes cluster on local using [kind].
|
||||||
|
4. Deploy the wordpress app using kustomize and verify the status.
|
||||||
|
5. Deploy the mysql app using kustomize on same "kind" cluster and verify the status.
|
||||||
|
6. Add and remove a resource to mysql service and verify prune.
|
||||||
|
|
||||||
|
First define a place to work:
|
||||||
|
|
||||||
|
<!-- @makeWorkplace @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
DEMO_HOME=$(mktemp -d)
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, use
|
||||||
|
|
||||||
|
> ```
|
||||||
|
> DEMO_HOME=~/hello
|
||||||
|
> ```
|
||||||
|
|
||||||
|
## Establish the base
|
||||||
|
|
||||||
|
<!-- @createBase @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
BASE=$DEMO_HOME/base
|
||||||
|
mkdir -p $BASE
|
||||||
|
|
||||||
|
mkdir $BASE/wordpress
|
||||||
|
mkdir $BASE/mysql
|
||||||
|
|
||||||
|
curl -s -o "$BASE/wordpress/#1.yaml" "https://raw.githubusercontent.com\
|
||||||
|
/kubernetes-sigs/kustomize\
|
||||||
|
/master/examples/wordpress/wordpress\
|
||||||
|
/{deployment,kustomization,service}.yaml"
|
||||||
|
|
||||||
|
curl -s -o "$BASE/mysql/#1.yaml" "https://raw.githubusercontent.com\
|
||||||
|
/kubernetes-sigs/kustomize\
|
||||||
|
/master/examples/wordpress/mysql\
|
||||||
|
/{secret,deployment,kustomization,service}.yaml"
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a `grouping.yaml` resource. By this, you are defining the grouping of the current directory, `mysql`. Kustomize uses the unique label in this file to track any future state changes made to this directory. Make sure the label key is `kustomize.config.k8s.io/inventory-id` and give any unique label value and DO NOT change it in future.
|
||||||
|
<!-- @createGroupingYaml @testE2EAgainstLatestRelease-->
|
||||||
|
```
|
||||||
|
cat <<EOF >$BASE/mysql/grouping.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: inventory-map
|
||||||
|
labels:
|
||||||
|
kustomize.config.k8s.io/inventory-id: mysql-app
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- @setGoBin @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
MYGOBIN=$GOPATH/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete any existing kind cluster and create a new one. By default the name of the cluster is "kind"
|
||||||
|
<!-- @deleteAndCreateKindCluster @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
$MYGOBIN/kind delete cluster;
|
||||||
|
$MYGOBIN/kind create cluster;
|
||||||
|
```
|
||||||
|
|
||||||
|
Let's run the wordpress and mysql services.
|
||||||
|
<!-- @RunWordpressAndMysql @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
export KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true
|
||||||
|
|
||||||
|
$MYGOBIN/kustomize resources apply $BASE/mysql --status;
|
||||||
|
|
||||||
|
status=$(mktemp);
|
||||||
|
$MYGOBIN/resource status fetch $BASE/mysql > $status
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "mysql" $status | grep "Deployment is available. Replicas: 1" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "mysql-pass" $status | grep "Resource is always ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "mysql" $status | grep "Service is ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
$MYGOBIN/kustomize resources apply $BASE/wordpress --status;
|
||||||
|
|
||||||
|
status=$(mktemp);
|
||||||
|
$MYGOBIN/resource status fetch $BASE/wordpress > $status
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "wordpress" $status | grep "Deployment is available. Replicas: 1" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "wordpress" $status | grep "Service is ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
|
||||||
|
Let's replace the secret resource from mysql service and verify prune and addition of resource.
|
||||||
|
<!-- @ReplaceResourceInMysql @testE2EAgainstLatestRelease -->
|
||||||
|
|
||||||
|
```
|
||||||
|
cat <<EOF >$BASE/mysql/secret2.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: mysql-pass2
|
||||||
|
type: Opaque
|
||||||
|
data:
|
||||||
|
# Default password is "admin".
|
||||||
|
password: YWRtaW5=
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rm $BASE/mysql/secret.yaml
|
||||||
|
|
||||||
|
sed -i.bak 's/secret/secret2/' \
|
||||||
|
$BASE/mysql/kustomization.yaml
|
||||||
|
|
||||||
|
sed -i.bak 's/mysql-pass/mysql-pass2/' \
|
||||||
|
$BASE/mysql/deployment.yaml
|
||||||
|
|
||||||
|
$MYGOBIN/kustomize resources apply $BASE/mysql --status;
|
||||||
|
|
||||||
|
status=$(mktemp);
|
||||||
|
$MYGOBIN/resource status fetch $BASE/mysql > $status
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "mysql" $status | grep "Deployment is available. Replicas: 1" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "mysql-pass2" $status | grep "Resource is always ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "mysql" $status | grep "Service is ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
|
||||||
|
Clean-up the cluster
|
||||||
|
<!-- @deleteKindCluster @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
$MYGOBIN/kind delete cluster;
|
||||||
|
```
|
||||||
@@ -37,7 +37,7 @@ mkdir -p $BASE
|
|||||||
|
|
||||||
Now lets add a simple config map resource to the `base`
|
Now lets add a simple config map resource to the `base`
|
||||||
|
|
||||||
<!-- @createBase @testE2EAgainstLatestRelease-->
|
<!-- @createConfigMapYaml @testE2EAgainstLatestRelease-->
|
||||||
```
|
```
|
||||||
cat <<EOF >$BASE/configMap.yaml
|
cat <<EOF >$BASE/configMap.yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -52,7 +52,7 @@ EOF
|
|||||||
|
|
||||||
Create `deployment.yaml` with any image and with desired number of replicas
|
Create `deployment.yaml` with any image and with desired number of replicas
|
||||||
|
|
||||||
<!-- @createBase @testE2EAgainstLatestRelease-->
|
<!-- @createDeploymentYaml @testE2EAgainstLatestRelease-->
|
||||||
```
|
```
|
||||||
cat <<EOF >$BASE/deployment.yaml
|
cat <<EOF >$BASE/deployment.yaml
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -90,7 +90,7 @@ EOF
|
|||||||
|
|
||||||
Create `service.yaml` pointing to the deployment created above
|
Create `service.yaml` pointing to the deployment created above
|
||||||
|
|
||||||
<!-- @createBase @testE2EAgainstLatestRelease-->
|
<!-- @createServiceYaml @testE2EAgainstLatestRelease-->
|
||||||
```
|
```
|
||||||
cat <<EOF >$BASE/service.yaml
|
cat <<EOF >$BASE/service.yaml
|
||||||
kind: Service
|
kind: Service
|
||||||
@@ -110,7 +110,7 @@ EOF
|
|||||||
|
|
||||||
Create a `grouping.yaml` resource. By this, you are defining the grouping of the current directory, `base`. Kustomize uses the unique label in this file to track any future state changes made to this directory. Make sure the label key is `kustomize.config.k8s.io/inventory-id` and give any unique label value and DO NOT change it in future.
|
Create a `grouping.yaml` resource. By this, you are defining the grouping of the current directory, `base`. Kustomize uses the unique label in this file to track any future state changes made to this directory. Make sure the label key is `kustomize.config.k8s.io/inventory-id` and give any unique label value and DO NOT change it in future.
|
||||||
|
|
||||||
<!-- @createBase @testE2EAgainstLatestRelease-->
|
<!-- @createGroupingYaml @testE2EAgainstLatestRelease-->
|
||||||
```
|
```
|
||||||
cat <<EOF >$BASE/grouping.yaml
|
cat <<EOF >$BASE/grouping.yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -124,7 +124,7 @@ EOF
|
|||||||
|
|
||||||
Now, create `kustomization.yaml` add all your resources.
|
Now, create `kustomization.yaml` add all your resources.
|
||||||
|
|
||||||
<!-- @createBase @testE2EAgainstLatestRelease-->
|
<!-- @createKustomizationYaml @testE2EAgainstLatestRelease-->
|
||||||
```
|
```
|
||||||
cat <<EOF >$BASE/kustomization.yaml
|
cat <<EOF >$BASE/kustomization.yaml
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -173,7 +173,7 @@ $MYGOBIN/kind create cluster;
|
|||||||
```
|
```
|
||||||
|
|
||||||
Use the kustomize binary in MYGOBIN to apply a deployment, fetch the status and verify the status.
|
Use the kustomize binary in MYGOBIN to apply a deployment, fetch the status and verify the status.
|
||||||
<!-- @e2eTestUsingKustomize @testE2EAgainstLatestRelease -->
|
<!-- @runHelloApp @testE2EAgainstLatestRelease -->
|
||||||
```
|
```
|
||||||
export KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true
|
export KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true
|
||||||
|
|
||||||
@@ -195,11 +195,51 @@ test 1 == \
|
|||||||
echo $?
|
echo $?
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Now let's replace the configMap with configMap2 apply the config, fetch and verify the status. This should delete the-map from deployment and add the-map2.
|
||||||
|
<!-- @replaceConfigMapInHello @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
cat <<EOF >$BASE/configMap2.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: the-map2
|
||||||
|
data:
|
||||||
|
altGreeting: "Good Evening!"
|
||||||
|
enableRisky: "false"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rm $BASE/configMap.yaml
|
||||||
|
|
||||||
|
sed -i.bak 's/configMap/configMap2/' \
|
||||||
|
$BASE/kustomization.yaml
|
||||||
|
|
||||||
|
sed -i.bak 's/the-map/the-map2/' \
|
||||||
|
$BASE/deployment.yaml
|
||||||
|
|
||||||
|
$MYGOBIN/kustomize resources apply $BASE --status;
|
||||||
|
|
||||||
|
status=$(mktemp);
|
||||||
|
$MYGOBIN/resource status fetch $BASE > $status
|
||||||
|
$MYGOBIN/resource status fetch $BASE > /tmp/teste2eout/out.txt
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "the-deployment" $status | grep "Deployment is available. Replicas: 3" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "the-map2" $status | grep "Resource is always ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "the-service" $status | grep "Service is ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
|
||||||
Clean-up the cluster
|
Clean-up the cluster
|
||||||
<!-- @createKindCluster @testE2EAgainstLatestRelease -->
|
<!-- @deleteKindCluster @testE2EAgainstLatestRelease -->
|
||||||
```
|
```
|
||||||
$MYGOBIN/kind delete cluster;
|
$MYGOBIN/kind delete cluster;
|
||||||
```
|
```
|
||||||
|
|
||||||
###Next Exercise
|
### Next Exercise
|
||||||
Create overlays as described in the [helloWorld] section and verify the results. Good luck!
|
Create overlays as described in the [helloWorld] section and verify the results. Good luck!
|
||||||
Reference in New Issue
Block a user