Kubernetes - Load Balancing For
Virtual Machines (Pods)
4th of Feb 2018
Yanir Quinn Senior Software Engineer Red Hat
This presentation is licensed under a Creative Commons Attribution 4.0 International License About me and oVirt/Kubevirt
Yanir Quinn Working for Red Hat since 2016 oVirt SLA team / KubeVirt
● oVirt | Red Hat Virtualization ● KubeVirt
2 FOSDEM 2018 Agenda
A quick intro to Kubevirt Dry run functionality for Kubernetes What is Kubernetes + Kubevirt in a nutshell What is scheduling simulation
Scheduling in Kubernetes Dry run scheduling use cases Basic characteristics of scheduling in kubernetes
VM migration Why load balancing ? What is VM migration ? What is missing in current Kubernetes release How can it be reflected on pods ? What work can be done or in progress
Load balancing algorithm Dscheduler An example for a load balancing algorithm that can Kubernetes incubator project Make use of dry run scheduling
3 Kubernetes
• Kubernetes is about managing tasks and applications at cloud scale
• By using container runtimes It allows managing containers on a cluster-level
4 FOSDEM 2018 With Kubernetes You Can
● Orchestrate containers across multiple hosts
● Make better use of hardware to maximize resources needed to run your enterprise apps
● Control and automate application deployments and updates
● Mount and add storage to run stateful apps
5 FOSDEM 2018 With Kubernetes You Can
● Scale containerized applications and their resources on the fly
● Declaratively manage services, which guarantees the deployed applications are always running how you deployed them
● Health-check and self-heal your apps with autoplacement, autorestart, autoreplication, and autoscaling
6 FOSDEM 2018 Kubernetes
7 FOSDEM 2018 Kubernetes Node
Kubelet cAdvisor Kube-Proxy
POD POD POD
8 FOSDEM 2018 Kubernetes Master
DevOps Controller manager
API Server
Scheduler
etcd
9 FOSDEM 2018 KubeVirt
Tries to close the gap between containers and VMs by enabling VM management on top of Kubernetes and integrating the VM into Kubernetes infrastructure where possible
https://github.com/kubevirt
10 FOSDEM 2018 Converged Infrastructure
Virtual Machines
Containers
11 FOSDEM 2018 KubeVirt
12 FOSDEM 2018 KubeVirt
● Drops directly into existing Kubernetes Clusters ○ No additional host setup ○ Simple install ○ Extends Kubernetes so VMs can be scheduled alongside Containers ● Ties VMs into Pod Network ● Integrates with other Kubernetes concepts ● Manage VMs like Pods
13 FOSDEM 2018 Scheduling in Kubernetes
Kubectl apply -f pod-def.yaml Kubectl POD def
Im supposed to etcd / run that pod ! I’m running the API server Pod A new pod with no POD machine assigned ! For Assign the pod to Kubelet on nodedef X Node X node X Scheduler
14 FOSDEM 2018 Why Load Balancing? (Rescheduling)
Free “Holes”
Scheduling decisions are only made at the time Pods are created
Optimize cluster layout
15 FOSDEM 2018 Current Work Related to Rescheduling
● Autoscaling
● Eviction Policy
● Affinity + Taints and Tolerations
● Pod Priority and Preemption ○ Critical add-ons
16 FOSDEM 2018 Current Work Related to Rescheduling
● Cluster Capacity
● Dscheduler
Kubernetes Incubator
17 FOSDEM 2018 Dscheduler
● Set a strategy for balancing the cluster
● Find pods that could be evicted
● Scheduler will reschedule the evicted pods
● Minimal to no disturbance on the cluster
18 FOSDEM 2018 Dscheduler - Policies and Strategies
Node #Pods < N Node Node Node
POD POD Memory < X POD POD POD POD POD POD CPU < Y POD
Node #Pods > N Node Node Node POD
Memory > X POD POD POD POD POD POD CPU > Y POD POD
19 FOSDEM 2018 Dscheduler - Strategies apiVersion: "descheduler/v1alpha1" kind: "DeschedulerPolicy" strategies: "LowNodeUtilization": enabled: true params: nodeResourceUtilizationThresholds: thresholds: "cpu" : 20 Nodes under that bound indicate "memory": 20 Underutilization "pods": 20 targetThresholds: "cpu" : 50 "memory": 50 Potential nodes from where pods "pods": 50 Could be evicted
20 FOSDEM 2018 Dscheduler - Strategies
nodeResourceUtilizationThresholds: thresholds: "cpu" : 20 Nodes under that bound indicate "memory": 20 Underutilization "pods": 20 targetThresholds: "cpu" : 50 "memory": 50 Potential nodes from where pods Could be evicted "pods": 50
21 FOSDEM 2018 Dscheduler - Eviction Policy
● Pods that cannot be evicted : ○ Critical ○ Not expected to terminate ○ Provide machine specific service ○ Have local storage
● Best efforts pods are evicted before Burstable and Guaranteed pods.
22 FOSDEM 2018 What Might Be Missing ?
● Optionally verify if can schedule and where
● An accurate simulation of Pods reassignment
○ No duplicates of a Pod’s resource consumption
● Actual rescheduling of replacement pods to better nodes
23 FOSDEM 2018 Dry Run Functionality for Kubernetes
● Scheduler "dry run" endpoint that takes a pod and tells you which nodes it can schedule onto
● Output: A destination Node for a newly created Pod (without performing any real binding)
● Output: Can a Pod be scheduled on Node/Nodes ? Node Node
Scheduler ??? POD Node
24 FOSDEM 2018 Dry Run Functionality Use Cases
● Rescheduling / Load Balancing ● Simulation of the system’s state after pods creation
○ Including assignment to nodes
○ Cluster capacity analysis, Autoscaler, DeamonSet Controller, etc. ● Using a replacement scheduler with stricter predicates ● Obstacles
25 FOSDEM 2018 Load Balancing Virtual Machines
POD POD (VM) (VM)
26 FOSDEM 2018 Virtual Machines Migration
kind: Migration Backed by a controller: metadata: ● On object create, schedules a new Pod generateName: my-migration
spec: nodeSelector: ● On successful Pod start, it triggers the migration kubevirt.io/hostname: node1 selector: ● At the end of the migration the object is name: testvm moved to a final state status:
phase: Succeeded ● Always one VirtualMachine object you reference
The objects Migration with VirtualMachine provide a consistent entry point to anything VirtualMachine related, like the Pod does for Kubernetes.
27 FOSDEM 2018 So How Can It Work On KubeVirt ?
● Integrate Dscheduler
○ Pod gets marked for deletion ○ Pod deletion blocked
○ Virtual machine is migrated behind the scenes
● Explicit load balancing based on the migration object
28 FOSDEM 2018 Load Balancing Algorithm
POD
Node POD
Bes O r Scheduler POD
Cpu 1 Node X Mem 1 ------Ove l 2
29 FOSDEM 2018 Summary
● It's about balancing VMs
● Leveraging Kubernetes
● More to come
30 FOSDEM 2018 THANK YOU
http://www.ovirt.org
[email protected] [email protected]
This presentation is licensed under a Creative Commons Attribution 4.0 International License