Refer to these instructions to test an installed cluster autoscaler.

Requirements

This task assumes you have installed the cluster autoscaler on a TKG cluster.

Test Cluster Autoscaler

To verify that the autoscaler automatically scales worker nodes, deploy an application and then scale the number of replicas in the deployment. The autoscaler will scale up worker nodes once the node resources are insufficient.

  1. Create the following application definition named app.yaml.
    apiVersion: v1
    kind: Namespace
    metadata:  
      name: app  
      labels:    
        pod-security.kubernetes.io/enforce: privileged
    ---
    apiVersion: v1
    kind: Service
    metadata:  
      name: application-cpu  
      namespace: app  
      labels:    
        app: application-cpu
    spec:  
      type: ClusterIP  
      selector:    
        app: application-cpu  
      ports:    
        - protocol: TCP      
          name: http      
          port: 80      
          targetPort: 80
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:  
      name: application-cpu  
      namespace: app  
      labels:    app: application-cpu
    spec:  
      selector:    
        matchLabels:      
          app: application-cpu  
        replicas: 1  
        strategy:    
          type: RollingUpdate    
          rollingUpdate:      
            maxSurge: 1      
            maxUnavailable: 0  
        template:    
          metadata:      
            labels:        
              app: application-cpu    
          spec:      
            containers:      
            - name: application-cpu        
              image: wcp-docker-ci.artifactory.eng.vmware.com/app-cpu:v1.0.0        
              imagePullPolicy: Always        
              ports:          
                - containerPort: 80        
              resources:          
                requests:            
                  memory: 50Mi            
                  cpu: 500m          
                limits:            
                  memory: 500Mi            
                  cpu: 2000m
  2. Create the application.
    kubectl apply -f app.yaml
  3. Scale up the application's replicas to trigger the autoscaler.

    For example, increase the number of spec.selector.replicas from 1 to a larger number such that additional worker nodes are required.

  4. Update the application.
    kubectl apply -f app.yaml
  5. Verify that additional worker nodes are created to handle the load.

    The autoscaler will scale up the number of worker nodes once the node resources are insufficient.