Slide 1

Slide 1 text

Control Theory, Controllers and Kubernetes: The Holy Trilogy Madhav Jivrajani, VMware

Slide 2

Slide 2 text

$ whoami Hi! ● Currently a senior @ PES University, Bangalore, India ● Been with the Kubernetes community for ~ 1 year ● Work on upstream Kubernetes @ VMware ● SIG-{ContribEx, API-Machinery, Node, Architecture}

Slide 3

Slide 3 text

Outline ● Containerized workloads and orchestration ● Can we build systems that can self-assess and self-heal? ● Control Theory and PID Control ● Where does Kubernetes come in? ● Extending Kubernetes ● Demo ● How does CAPI use CRs?

Slide 4

Slide 4 text

Containerized Workloads and Orchestration

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

What happens if something goes wrong?

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

How do we rectify this and who does it?

Slide 16

Slide 16 text

What if we want to run another app?

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

The answer to these questions is: orchestration!

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

The question that aries now is: how does the orchestrator make decisions?

Slide 29

Slide 29 text

The question that aries now is: how does the orchestrator make decisions? Does a sysadmin monitor the health of the applications and decide what actions to take?

Slide 30

Slide 30 text

The question that aries now is: how does the orchestrator make decisions? Can the orchestrator be intelligent in some form and make these decisions, and if so, what information would it require?

Slide 31

Slide 31 text

The question that aries now is: how does the orchestrator make decisions? Given the information needed, how can the orchestrator keep the system in a stable state?

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Let’s start with the Control Theory “Hello World” example

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

A Few Terms ● The entity that we want to control - System ○ A system can take inputs and produce outputs. ● Where we want to go/our desired state/intent - Set Variable (SV) ● Where we currently are/observed state - Process Variable (PV) ○ System output ● How “far” are we currently from our desired state? - Error (e) ○ e = SP - PV ● Who drives the system to where it needs to be? - Controller ● A controller that provides system inputs based on system outputs - Closed Loop Controller

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

However, it’s often not this ideal. With the controller applying adjustments, the following questions come to mind: ● What if the adjustment applied overshoots or undershoots the SV? ○ If it does, its likely to cause a thrashing effect. ● Can we take past experiences into account and adjust accordingly or in other words, can we compensate? ● Can we look at our current error and predict what the error is going to be in the future?

Slide 50

Slide 50 text

Past, Present and Future - PID Controller

Slide 51

Slide 51 text

Past, Present and Future - PID Controller ● P - Proportional: Adjust proportional to the error

Slide 52

Slide 52 text

Past, Present and Future - PID Controller ● I - Integral: Adjust based on what the current error is and what the error has been in the past

Slide 53

Slide 53 text

Past, Present and Future - PID Controller ● D - Derivative: Predict the future error based on rate of change of current error

Slide 54

Slide 54 text

Can we look at our orchestrator as a control system?

Slide 55

Slide 55 text

Is it possible for the orchestrator to self-assess and self-heal?

Slide 56

Slide 56 text

Is it possible for the orchestrator to self-assess and self-heal? Yes.

Slide 57

Slide 57 text

In order to do this, you need two pieces of information: 1. Where do you want to go? 2. Where are you currently?

Slide 58

Slide 58 text

This largely shapes up to be a closed-loop controller.

Slide 59

Slide 59 text

Where does Kubernetes fit in as an orchestrator?

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Let’s dive a little deeper into how Kubernetes does things using these concepts.

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

All Kubernetes controllers are P controllers!

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

Kubernetes has a few build-in resources such as pod, deployments, replicasets, etc.

Slide 90

Slide 90 text

Each of which are accessed through the Kubernetes API (which is a REST based API)

Slide 91

Slide 91 text

kubectl get pods --namespace mynamespace GET /api/v1/namespaces/mynamespace/pods

Slide 92

Slide 92 text

Other than the built-in resources, Kubernetes allows us to create custom resources. For ex: we can have a custom resource called foo and we can access it through kubectl like any other resource: kubectl get foo GET /apis/{group}/{version}/namespaces/{namespace}/foos

Slide 93

Slide 93 text

Custom Resources are created from Custom Resources Definitions (CRDs). For custom resources created, we can also write custom controllers that have sufficient intelligence baked in to reconcile any state changes.

Slide 94

Slide 94 text

Demo https://github.com/kubernetes/sample-controller/

Slide 95

Slide 95 text

This is extremely powerful for a multitude of reasons, because now you don’t have to look at Kubernetes as only a container orchestration platform.

Slide 96

Slide 96 text

With CRs, Kubernetes can now be looked at as a “Universal Control Plane” or a “Platform For Building Platforms” ● With this extensibility, we can now create a custom resource that maybe represents an Infrastructure component, ex - VMs. ● We can also write custom controllers, similar to the built-in controllers that Kubernetes has, to try and reconcile state. ● With this, we can declaratively manage and provision infrastructure, by using Kubernetes as a base layer.

Slide 97

Slide 97 text

Projects such as Cluster API (CAPI) and Crossplane make use of this extensibility in a similar manner to provision and/or manage infrastructure.

Slide 98

Slide 98 text

For ex: CAPI defines a few CRDs, some of which are: ● Machine ○ Analogous to Kubernetes Pods ● MachineDeployment ○ Analogous to Kubernetes Deployment ● MachineSet ○ Analogous to Kubernetes ReplicaSet

Slide 99

Slide 99 text

https://itnext.io/kubernetes-cluster-creation-on-baremetal-host-using-cluster-api-1c2373230a17

Slide 100

Slide 100 text

References and Resources ● Control Theory In Container Fleet Management ● PID Loops and The Art of Keeping Systems Stable ● Kubernetes Design Principles - Understanding The Why ● The Magic of Kubernetes Self-Healing Capabilities ● Imperative, Declarative and Kubernetes ● Deep Dive into Kubernetes Internals for Builders and Operators ● The Cluster API Book

Slide 101

Slide 101 text

Thank you! Twitter: @MadhavJivrajani GitHub: github.com/MadhavJivrajani K8s slack (slack.k8s.io): @madhav