Skip to content

Commit

Permalink
using env variable in deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
irvifa committed Apr 14, 2018
1 parent 5308d92 commit 69715e4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ After a few minutes, you'll have a working Kubernetes cluster with three nodes (

Now that `kubectl` is setup, deploy the `kubernetes configuration`:

$ ./deploy.sh [PROJECT_ID]
$ ./deploy.sh [TARGET_HOST] [IMAGE_NAME]

To confirm that the deployment and Pod are created, run the following:

Expand Down
15 changes: 9 additions & 6 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/bin/bash -xe

PROJECT_ID=$1
IMAGE_NAME=$1
TARGET_HOST=$2

if [[ -z "${PROJECT_ID}" ]]; then
if [[ -z "${IMAGE_NAME}" && -z "${TARGET_HOST}" ]]; then
exit 1
fi

sed -i "s/\$targetHost/http:\/\/${PROJECT_ID}.appspot.com/g;s/\$projectId/${PROJECT_ID}/g" kubernetes-config/locust-master-deployment.yaml
sed -i "s/\$targetHost/http:\/\/${PROJECT_ID}.appspot.com/g;s/\$projectId/${PROJECT_ID}/g" kubernetes-config/locust-worker-deployment.yaml
sed -i s/\$targetHost/${TARGET_HOST}/g kubernetes-config/environment-variable.yaml
sed -i s/\$imageName/${IMAGE_NAME}/g kubernetes-config/locust-master-deployment.yaml
sed -i s/\$imageName/${IMAGE_NAME}/g kubernetes-config/locust-worker-deployment.yaml

kubectl create configmap locust-tasks-configuration --from-file=config/tasks.py
kubectl apply -f kubernetes-config
kubectl apply -f kubernetes-config --dry-run
#kubectl create configmap locust-tasks-configuration --from-file=config/tasks.py
#kubectl apply -f kubernetes-config
6 changes: 6 additions & 0 deletions kubernetes-config/environment-variable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: environment-variable
data:
TARGET_HOST: $targetHost
7 changes: 4 additions & 3 deletions kubernetes-config/locust-master-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ spec:
spec:
containers:
- name: locust
image: gcr.io/$projectId/locust-tasks:latest
image: $imageName
command: [ "/bin/bash", "-c", "--" ]
args: [ "/locust-tasks/run.sh" ]
env:
- name: LOCUST_MODE
value: master
- name: TARGET_HOST
value: $targetHost
envFrom:
- configMapRef:
name: environment-variable
ports:
- name: loc-master-web
containerPort: 8089
Expand Down
7 changes: 4 additions & 3 deletions kubernetes-config/locust-worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ spec:
spec:
containers:
- name: locust
image: gcr.io/$projectId/locust-tasks:latest
image: $imageName
command: [ "/bin/bash", "-c", "--" ]
args: [ "/locust-tasks/run.sh" ]
env:
- name: LOCUST_MODE
value: worker
- name: LOCUST_MASTER
value: locust-master
- name: TARGET_HOST
value: $targetHost
envFrom:
- configMapRef:
name: environment-variable
volumeMounts:
- name: locust-tasks-configuration
mountPath: /locust-tasks/script
Expand Down

0 comments on commit 69715e4

Please sign in to comment.