Performing rolling updates with autoscaling

Rolling updates are the cornerstone of managing large clusters. Kubernetes support rolling updates at the replication controller level and by using deployments. Rolling updates using replication controllers are incompatible with the horizontal pod autoscaler. The reason is that, during the rolling deployment, a new replication controller is created and the horizontal pod autoscaler remains bound to the old replication controller. Unfortunately, the intuitive Kubectl rolling-update command triggers a replication controller rolling update.

Since rolling updates are such an important capability, I recommend that you always bind horizontal pod autoscalers to a deployment object instead of a replication controller or a replica set. When the horizontal pod autoscaler is bound to a deployment, it can set the replicas in the deployment spec and let the deployment take care of the necessary underlying rolling update and replication.

Here is a deployment configuration file we've used for deploying the hue-reminders service:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: hue-reminders
spec:
  replicas: 2  
  template:
    metadata:
      name: hue-reminders
      labels:
        app: hue-reminders
    spec:    
      containers:
      - name: hue-reminders
        image: g1g1/hue-reminders:v2.2    
        ports:
        - containerPort: 80 

To support it with autoscaling and ensure we always have between 10 to 15 instances running, we can create an autoscaler configuration file:

apiVersion: autoscaling/v1
 kind: HorizontalPodAutoscaler
 metadata:
   name: hue-reminders
   namespace: default
 spec:
   maxReplicas: 15
   minReplicas: 10
   targetCPUUtilizationPercentage: 90
   scaleTargetRef:
     apiVersion: v1
     kind: Deployment
     name: hue-reminders

The kind of the scaleTargetRef field is now Deployment instead of ReplicationController. This is important because we may have a replication controller with the same name. To disambiguate and ensure that the horizontal pod autoscaler is bound to the correct object, the kind and the name must match.

Alternatively, we can use the kubectl autoscale command:

> kubectl autoscale deployment hue-reminders --min=10--max=15
  --cpu-percent=90
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset