-
Notifications
You must be signed in to change notification settings - Fork 14
/
traffic.yaml
129 lines (125 loc) · 3.15 KB
/
traffic.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
apiVersion: v1
kind: Namespace
metadata:
name: kube-traffic-generator
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: traffic-generator-service-account
namespace: kube-traffic-generator
---
apiVersion: v1
kind: Pod
metadata:
name: traffic-generator
namespace: kube-traffic-generator
spec:
serviceAccount: traffic-generator-service-account
containers:
- name: kube-traffic-generator
image: lachlanevenson/k8s-kubectl
command:
- /bin/sh
- -ec
- |
apk add --no-cache curl
kubectl apply -f /etc/config/petclinic-config.yaml
i=0
scaleup="1"
while true; do
if [[ $(( $i % 100 )) -eq "0" ]]; then
if [[ $scaleup -eq "1" ]]; then
kubectl scale deployment spring-petclinic-web --replicas 40
echo "Scaled up"
scaleup="0"
else
kubectl scale deployment spring-petclinic-web --replicas 20
echo "Scaled down"
scaleup="1"
fi
fi
curl http://petclinic:28080/owners > /dev/null || true
curl http://petclinic:28080/ > /dev/null || true
curl http://petclinic:28080/vets > /dev/null|| true
sleep 1
i=$((i+1))
echo "Incremented counter to $i"
done
volumeMounts:
- name: petclinic-config
mountPath: /etc/config
volumes:
- name: petclinic-config
configMap:
name: traffic-generator-configmap
items:
- key: petclinic-config
path: petclinic-config.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: traffic-generator-configmap
namespace: kube-traffic-generator
data:
petclinic-config: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-petclinic-web
namespace: kube-traffic-generator
spec:
selector:
matchLabels:
app: petclinic
replicas: 2
template:
metadata:
labels:
app: petclinic
spec:
containers:
- name: petclinic
image: jbrisbin/spring-petclinic
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: petclinic
namespace: kube-traffic-generator
spec:
selector:
app: petclinic
ports:
- protocol: TCP
port: 28080
targetPort: 8080
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: kube-traffic-generator
name: deployments-updater
rules:
- apiGroups: ["extensions", "apps"]
resources: ["deployments", "deployments/scale"]
verbs: ["get", "watch", "update", "patch", "create", "delete", "list"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "watch", "create", "patch", "update", "delete", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: update-deployments
namespace: kube-traffic-generator
subjects:
- kind: ServiceAccount
name: traffic-generator-service-account
roleRef:
kind: Role
name: deployments-updater
apiGroup: rbac.authorization.k8s.io