fbpx
Unlock the power of choice with CloudPlex and DigitalOcean Get CloudPlex free for 3 months, and Digital Ocean for 1 month

Kubernetes Autoscaling

Pain Point

In Docker container based applications, developers have the ability to scale up an individual service based on demand. Autoscaling is an important feature of Kubernetes. As containers grow in use by developers, it becomes all the more relevant for them to learn how to scale a service up or down based on demand.

Autoscaling requires installing Metrics Server as an add-on to Kubernetes. Configuring Metrics Server is complex. Each public cloud provider requires developers to learn their unique set of configuration parameters. The developer is also required to manually configure k8s autoscaler for each public cloud. Developers need a deep understanding of the cloud provider’s scaling group abstractions to configure k8s autoscaler for the specific cloud. Also, in the case of node autoscaling, after starting each node, the node needs to be manually bootstrapped to join the k8s cluster.

The following YAML snippets show how to manually configure k8s autoscaler, install a Metrics Server, and configure pod scaling and node scaling.

autoscaler.yaml

https://github.com/helm/charts/tree/master/stable/cluster-autoscaler/templates

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cluster-autoscaler
  namespace: kube-system
...
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cluster-autoscaler
  template:
    metadata:
      labels:
        app: cluster-autoscaler
     spec:
      serviceAccountName: cluster-autoscaler
      tolerations:
        - effect: NoSchedule
          operator: "Equal"
          value: "true"
          key: node-role.kubernetes.io/master
      nodeSelector:
        kubernetes.io/role: master
      containers:
        - image: k8s.gcr.io/cluster-autoscaler:v1.12.3
          name: cluster-autoscaler
          resources:
            limits:
              cpu: 100m
              memory: 300Mi
            requests:
              cpu: 100m
              memory: 300Mi
          command:
            - ./cluster-autoscaler
            - --v=4
            - --stderrthreshold=info
            - --cloud-provider=aws
            - --skip-nodes-with-local-storage=false
            - --nodes={{ node_asg_min }}:{{ node_asg_max }}:{{ name }}
          volumeMounts:
            - name: ssl-certs
              mountPath: /etc/ssl/certs/ca-certificates.crt
              readOnly: true
          imagePullPolicy: "Always"
      volumes:
        - name: ssl-certs
          hostPath:
            path: "/etc/ssl/certs/ca-bundle.crt"

metrics-server.yaml

https://github.com/helm/charts/tree/master/stable/metrics-server/templates

...
 spec:
      priorityClassName: system-cluster-critical
      serviceAccountName: metrics-server
      nodeSelector:
        kubernetes.io/os: linux
      containers:
      - name: metrics-server
        image: k8s.gcr.io/metrics-server-amd64:v0.3.6
        command:
        - /metrics-server
        - --metric-resolution=30s

	//different specs for different cloud providers
        # These are needed for GKE, which doesn't support secure communication yet.
        # Remove these lines for non-GKE clusters, and when GKE supports token-based auth.
        - --kubelet-port=10255
        - --deprecated-kubelet-completely-insecure=true
        - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP
        ports:
        - 
           containerPort: 443
            name: https
             protocol: TCP
...

hpa.yaml

https://raw.githubusercontent.com/CloudplexPlatform/manifest-files/master/kubernetes-manifest/autoscaling/hpa.yaml

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

How CloudPlex addresses your pain

CloudPlex automatically sets up the Metrics Server for each public cloud provider without burdening the developer with cloud-specific details. In the case of pod autoscaling, developers provide minimum and maximum values for replicas and resource quotas. In the case of node autoscaling, developers select a CloudPlex provided node template.

The following screenshot shows how easy it is to visually configure k8s pod scaling and node scaling policies in CloudPlex:

scaling
nodepool-auto-scaling