Skip to content

Commit

Permalink
add web-show example (chaos-mesh#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwen0 authored Mar 3, 2020
1 parent aa63d02 commit bb1026d
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
58 changes: 58 additions & 0 deletions examples/web-show/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

set -e

usage() {
cat << EOF
This script is used to install web-show.
USAGE:
install.sh [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
--docker-mirror Use docker mirror to pull image
EOF
}

DOCKER_MIRROR=false

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
--docker-mirror)
DOCKER_MIRROR=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown option: $key"
usage
exit 1
;;
esac
done

TARGET_IP=$(kubectl get pod -n kube-system -o wide| grep kube-controller | head -n 1 | awk '{print $6}')

sed "s/TARGETIP/$TARGET_IP/g" deployment.yaml > deployment-target.yaml

if [ ${DOCKER_MIRROR} == "true" ]; then
docker pull dockerhub.azk8s.cn/pingcap/web-show || true
docker tag dockerhub.azk8s.cn/pingcap/web-show pingcap/web-show || true
kind load docker-image pingcap/web-show > /dev/null 2>&1 || true
fi

kubectl apply -f service.yaml
kubectl apply -f deployment-target.yaml

rm -rf deployment-target.yaml

while [[ $(kubectl get pods -l app=web-show -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "Waiting for pod running" && sleep 1; done

kill $(lsof -t -i:8081) 2>&1 >/dev/null || true

nohup kubectl port-forward svc/web-show 8081:8081 >/dev/null 2>&1 &
27 changes: 27 additions & 0 deletions examples/web-show/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-show
labels:
app: web-show
spec:
replicas: 1
selector:
matchLabels:
app: web-show
template:
metadata:
labels:
app: web-show
spec:
containers:
- name: web-show
image: pingcap/web-show
imagePullPolicy: Always
command:
- /usr/local/bin/web-show
- --target-ip=TARGETIP
ports:
- name: web-port
containerPort: 8081
hostPort: 8081
19 changes: 19 additions & 0 deletions examples/web-show/network-delay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: pingcap.com/v1alpha1
kind: NetworkChaos
metadata:
name: network-delay-example
spec:
action: delay
mode: one
selector:
namespaces:
- default
labelSelectors:
"app": "web-show"
delay:
latency: "10ms"
correlation: "100"
jitter: "0ms"
duration: "30s"
scheduler:
cron: "@every 60s"
13 changes: 13 additions & 0 deletions examples/web-show/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: web-show
labels:
app: web-show
spec:
selector:
app: web-show
ports:
- protocol: TCP
port: 8081
targetPort: 8081

0 comments on commit bb1026d

Please sign in to comment.