-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
224 lines (209 loc) · 3.96 KB
/
setup.sh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
###this script will create 200 isolated namespaces;
###all namespaces will be labeld by ns: test$i and a different network policy will be applied.
###in each ns; there will create several service; by default they cann't visit public network.
set +o errexit
###args $1 is the cluster number going to define ...
function Setup() {
for i in `seq 1 $1`; do
kubectl create -f -<<EOF
apiVersion: v1
kind: Namespace
metadata:
name: ns-test$i
labels:
ns: test$i
EOF
done
for i in `seq 1 $1`; do
kubectl create -f -<<EOF
#make pods visitable in the same ns
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: default-deny
namespace: ns-test$i
spec:
podSelector:
matchLabels:
user: test$i
ingress:
- from:
- ipBlock:
cidr: 10.0.0.0/8
- namespaceSelector:
matchLabels:
ns: test$i
egress:
- to:
- namespaceSelector:
matchLabels:
ns: test$i
- ipBlock:
cidr: 10.0.0.0/8
EOF
done
for i in `seq 1 $1`; do
kubectl create -f -<<EOF
# Example replication controller for an iperf service.
apiVersion: v1
kind: ReplicationController
metadata:
name: iperf-server-controller
namespace: ns-test$i
spec:
replicas: 3
selector:
user: test$i
template:
metadata:
labels:
user: test$i
spec:
containers:
- name: iperf-server
image: docker-registry.telecom.com/chenqiang/nginx-hello:v2.0
EOF
done
for i in `seq 9 19`; do
kubectl create -f -<<EOF
# Example replication controller for an iperf service.
apiVersion: v1
kind: ReplicationController
metadata:
name: iperf-server-controller2
namespace: ns-test$i
spec:
replicas: 3
selector:
name: test2$i
template:
metadata:
labels:
user: test$i
name: test2$i
spec:
containers:
- name: iperf-server
image: docker-registry.telecom.com/chenqiang/nginx-hello:v2.0
EOF
done
for i in `seq 9 19`; do
kubectl create -f -<<EOF
# Example replication controller for an iperf service.
apiVersion: v1
kind: ReplicationController
metadata:
name: iperf-server-controller3
namespace: ns-test$i
spec:
replicas: 3
selector:
name: test3$i
template:
metadata:
labels:
user: test$i
name: test3$i
spec:
containers:
- name: iperf-server
image: docker-registry.telecom.com/chenqiang/nginx-hello:v2.0
EOF
done
for i in `seq 9 19`; do
kubectl create -f -<<EOF
# Example replication controller for an iperf service.
apiVersion: v1
kind: ReplicationController
metadata:
name: iperf-server-controller4
namespace: ns-test$i
spec:
replicas: 3
selector:
name: test4$i
template:
metadata:
labels:
name: test4$i
user: test$i
spec:
containers:
- name: iperf-server
image: docker-registry.telecom.com/chenqiang/nginx-hello:v2.0
EOF
done
for i in `seq 9 19`; do
kubectl create -f -<<EOF
apiVersion: v1
kind: Service
metadata:
name: networking-service$i
namespace: ns-test$i
labels:
name: networking-service$i
spec:
ports:
- port: 5089
targetPort: 80
protocol: TCP
selector:
user: test2$i
EOF
done
for i in `seq 9 19`; do
kubectl create -f -<<EOF
apiVersion: v1
kind: Service
metadata:
name: networking-service4
namespace: ns-test$i
labels:
name: networking-service4
spec:
ports:
- port: 5085
targetPort: 80
protocol: TCP
selector:
user: test4$i
EOF
done
for i in `seq 9 19`; do
kubectl create -f -<<EOF
apiVersion: v1
kind: Service
metadata:
name: networking-service3
namespace: ns-test$i
labels:
name: networking-service3
spec:
ports:
- port: 5087
targetPort: 80
protocol: TCP
selector:
user: test3$i
EOF
done
for i in `seq 1 $1`; do
kubectl create -f -<<EOF
apiVersion: v1
kind: Service
metadata:
name: networking-service
namespace: ns-test$i
labels:
name: networking-service
spec:
ports:
- port: 5081
targetPort: 80
protocol: TCP
selector:
name: test$i
EOF
done
}