Understanding Kubernetes Controllers: Managing State and Reacting to Changes

Slide Note
Embed
Share

Kubernetes controllers play a crucial role in managing the state of resources within a Kubernetes cluster by watching for changes in the API server and ensuring the desired state matches the current state. They take actions to bring the system into alignment, helping to maintain stability and efficiency. This involves creating, updating, deleting resources as needed based on the defined specifications. Controllers ensure that the cluster operates as intended, reacting to changes proactively.


Uploaded on Sep 21, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Extending Kubernetes with Custom Resources https://leannet.eu

  2. $> whoami Co-founder & CTO @ LeanNet Ltd. Consulting, training, implementing Cloud Native, Kubernetes, Microservices, DevOps PhD in Telecommunications @ Budapest University of Technology Worked with 5G technology SDN & NFV Cloud Native Network Functions Graduated in the EIT Digital Doctoral School megyesi@leannet.eu twitter.com/M3gy0 linkedin.com/in/M3gy0 https://leannet.eu

  3. Kubernetes Architecture Cloud Provider Controller Manager Cloud Controller API server kube-proxy kube-proxy kube-proxy kubelet kubelet kubelet Scheduler cont.runtime cont.runtime cont.runtime etcd Control Plane Worker Nodes https://leannet.eu

  4. Control Loops Temp 22.5 Time https://leannet.eu

  5. Control Loops in Kubernetes Job create a job via an API call 1 Controller Controller Manager persist state to etcd 2 the job controller sees the newly crated job and creates a pod based on the template 1 3 3 7 the scheduler sees that there is a pod without an assigned node, so it does the assignment the kubelet on the node sees that there is a pod assigned to it, and starts it via the CRI after the container exits, kubelet reports back the exit code to the pod s state 4 API server 5 kube-proxy 2 4 6 kubelet 6 5 Scheduler the job controller notices the change in the pod s state and makes a decision exit code = 0 marks the job as complete exit code 0 and reached the backoff limit: marks the job as failed else increases the count and starts a new pod (back to step 4) 7 cont.runtime etcd Control Plane Worker Node 1 https://leannet.eu

  6. Kubernetes Controllers Watch the changes in the API server and compares the desired state with the current state If these states differ they carry out actions to bring the current state closer to the desired state The spec field describes the desired state The status field describes the current state https://leannet.eu

  7. Kubernetes Controllers Watch the changes in the API server and compares the desired state with the current state If these states differ they carry out actions to bring the current state closer to the desired state The spec field describes the desired state The status field describes the current state https://leannet.eu

  8. Kubernetes Controllers Watch the changes in the API server and compares the desired state with the current state If these states differ they carry out actions to bring the current state closer to the desired state working with desired states is also referred as declarative infrastructure acting on the deference between the desired state and the current state is also referred as reconcile pattern foundation of every cloud native infrastructure https://leannet.eu

  9. Custom Resources Custom resources are extensions of the Kubernetes API Built-in object: e.g. pod, job, deployment, service, ingress, persistent volume Custom resources simply let you store and retrieve structured data kubectl create f Megyo.yaml kubectl get developers kubectl get developer Megyo kubectl get devs https://leannet.eu

  10. Custom Resources + Custom Controllers = Operators You can write your own controller logic Works the same way as built in controllers: watches resources in the Kubernetes API carry out action if there are changes in either the spec (desired state) or the status (current state) watch build-in resources and config your own software e.g. Ingress controllers (e.g. Nginx, Traefik, Envoy), KubeDNS/CoreDNS, Prometheus SD change the behavior of your software based on a CRD use the Kubernetes API as your API e.g. Calico, OpenShift, Istio interact with external systems / APIs e.g. kubelet, kube-proxy, DynamoDB operator create other Kubernetes resources (e.g. pods, deployments, statefulsets, services, ingresses) e.g. MySQL operator, GitLab operator A custom controller working over a custom resource is usually referred as an Operator https://leannet.eu

  11. Example: Zalando Postgres Operator Postgres Operator Secrets kubectl create Kubernetes API Users Robots Standby StatefulSet Services Primary Replica Pod Template Pods Endpoints Primary Replica Replica Primary Replicas Persistent Volume Claims Primary Replica Replica https://leannet.eu

  12. Example: Zalando Postgres Operator Postgres Operator Secrets kubectl create Kubernetes API Users Robots Standby StatefulSet Services Primary Replica Pod Template Pods Endpoints Replica Primary Primary Replica Replica Primary Replicas Persistent Volume Claims Primary Replica Replica https://leannet.eu

  13. Where to Find Operators https://leannet.eu

  14. Write Your Own Operator KOPF Kubernetes Operator Pythonic Framework https://github.com/zalando-incubator/kopf java-operator-sdk https://github.com/ContainerSolutions/java-operator-sdk https://leannet.eu

  15. Remember: Custom Resources + Custom Controllers = Operators Custom resources are extensions of the Kubernetes API Built-in object with controllers: e.g. pod, job, deployment, service, ingress, persistent volume Custom resources simply let you store and retrieve structured data Schema is defined with OpenAPI spec But you can write custom controllers over custom resources: operator pattern Example operators: Serverless CI/CD Machine Learning Virtual Machines MySQL PostgreSQL Kafka Cassandra https://leannet.eu

Related