@@ -176,18 +176,88 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
176
176
})
177
177
178
178
Describe ("with a linux agent pool" , func () {
179
+ It ("should be able to autoscale" , func () {
180
+ version , err := node .Version ()
181
+ Expect (err ).NotTo (HaveOccurred ())
182
+ re := regexp .MustCompile ("v1.9" )
183
+ if eng .HasLinuxAgents () && re .FindString (version ) == "" {
184
+ // Inspired by http://blog.kubernetes.io/2016/07/autoscaling-in-kubernetes.html
185
+ r := rand .New (rand .NewSource (time .Now ().UnixNano ()))
186
+ phpApacheName := fmt .Sprintf ("php-apache-%s-%v" , cfg .Name , r .Intn (99999 ))
187
+ phpApacheDeploy , err := deployment .CreateLinuxDeploy ("gcr.io/google_containers/hpa-example" , phpApacheName , "default" , "--requests=cpu=50m,memory=50M" )
188
+ if err != nil {
189
+ fmt .Println (err )
190
+ }
191
+ Expect (err ).NotTo (HaveOccurred ())
192
+
193
+ running , err := pod .WaitOnReady (phpApacheName , "default" , 3 , 30 * time .Second , cfg .Timeout )
194
+ Expect (err ).NotTo (HaveOccurred ())
195
+ Expect (running ).To (Equal (true ))
196
+
197
+ phpPods , err := phpApacheDeploy .Pods ()
198
+ Expect (err ).NotTo (HaveOccurred ())
199
+ // We should have exactly 1 pod to begin
200
+ Expect (len (phpPods )).To (Equal (1 ))
201
+
202
+ err = phpApacheDeploy .Expose ("ClusterIP" , 80 , 80 )
203
+ Expect (err ).NotTo (HaveOccurred ())
204
+ s , err := service .Get (phpApacheName , "default" )
205
+ Expect (err ).NotTo (HaveOccurred ())
206
+
207
+ // Apply autoscale characteristics to deployment
208
+ _ , err = exec .Command ("kubectl" , "autoscale" , "deployment" , phpApacheName , "--cpu-percent=5" , "--min=1" , "--max=10" ).CombinedOutput ()
209
+ Expect (err ).NotTo (HaveOccurred ())
210
+
211
+ phpPods , err = phpApacheDeploy .Pods ()
212
+ Expect (err ).NotTo (HaveOccurred ())
213
+ // We should still have exactly 1 pod after autoscale config but before load
214
+ Expect (len (phpPods )).To (Equal (1 ))
215
+
216
+ // Launch a simple busybox pod that wget's continuously to the apache serviceto simulate load
217
+ commandString := fmt .Sprintf ("while true; do wget -q -O- http://%s.default.svc.cluster.local; done" , phpApacheName )
218
+ loadTestName := fmt .Sprintf ("load-test-%s-%v" , cfg .Name , r .Intn (99999 ))
219
+ numLoadTestPods := 3
220
+ loadTestDeploy , err := deployment .RunLinuxDeploy ("busybox" , loadTestName , "default" , commandString , numLoadTestPods )
221
+ Expect (err ).NotTo (HaveOccurred ())
222
+
223
+ running , err = pod .WaitOnReady (loadTestName , "default" , 3 , 30 * time .Second , cfg .Timeout )
224
+ Expect (err ).NotTo (HaveOccurred ())
225
+ Expect (running ).To (Equal (true ))
226
+
227
+ // We should have three load tester pods running
228
+ loadTestPods , err := loadTestDeploy .Pods ()
229
+ Expect (err ).NotTo (HaveOccurred ())
230
+ Expect (len (loadTestPods )).To (Equal (numLoadTestPods ))
231
+
232
+ // Wait 3 minutes for autoscaler to respond to load
233
+ time .Sleep (3 * time .Minute )
234
+
235
+ phpPods , err = phpApacheDeploy .Pods ()
236
+ Expect (err ).NotTo (HaveOccurred ())
237
+ // We should have > 1 pods after autoscale effects
238
+ Expect (len (phpPods ) > 1 ).To (BeTrue ())
239
+
240
+ err = loadTestDeploy .Delete ()
241
+ Expect (err ).NotTo (HaveOccurred ())
242
+ err = phpApacheDeploy .Delete ()
243
+ Expect (err ).NotTo (HaveOccurred ())
244
+ err = s .Delete ()
245
+ Expect (err ).NotTo (HaveOccurred ())
246
+ }
247
+ })
248
+
179
249
It ("should be able to deploy an nginx service" , func () {
180
250
if eng .HasLinuxAgents () {
181
251
r := rand .New (rand .NewSource (time .Now ().UnixNano ()))
182
252
deploymentName := fmt .Sprintf ("nginx-%s-%v" , cfg .Name , r .Intn (99999 ))
183
- nginxDeploy , err := deployment .CreateLinuxDeploy ("library/nginx:latest" , deploymentName , "default" )
253
+ nginxDeploy , err := deployment .CreateLinuxDeploy ("library/nginx:latest" , deploymentName , "default" , "" )
184
254
Expect (err ).NotTo (HaveOccurred ())
185
255
186
256
running , err := pod .WaitOnReady (deploymentName , "default" , 3 , 30 * time .Second , cfg .Timeout )
187
257
Expect (err ).NotTo (HaveOccurred ())
188
258
Expect (running ).To (Equal (true ))
189
259
190
- err = nginxDeploy .Expose (80 , 80 )
260
+ err = nginxDeploy .Expose ("LoadBalancer" , 80 , 80 )
191
261
Expect (err ).NotTo (HaveOccurred ())
192
262
193
263
s , err := service .Get (deploymentName , "default" )
@@ -231,7 +301,7 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
231
301
Expect(err).NotTo(HaveOccurred())
232
302
Expect(running).To(Equal(true))
233
303
234
- err = iisDeploy.Expose(80, 80)
304
+ err = iisDeploy.Expose("LoadBalancer", 80, 80)
235
305
Expect(err).NotTo(HaveOccurred())
236
306
237
307
s, err := service.Get(deploymentName, "default")
0 commit comments