workload-resources-and-controllers.md (1869B)
1 +++ 2 title = 'Workload resources and controllers' 3 +++ 4 ## Workload resources and controllers 5 Instead of running individual pods, you create workload resources that manage set of pods based on a declared desired state. 6 7 When you submit workload resource, K8s control plane configures corresponding controller. 8 Controllers run control loops, where controller periodically makes sure that status of resource corresponds to declared desired state. 9 10 Most Kubernetes objects have two fields: 11 - spec: desired object state 12 - status: current object state 13 14 Deployment: suitable for stateless apps, like web servers. can have one or more containers. 15 - you can scale a deployment with `kubectl edit`, or `kubectl scale deployment <name> --replicas=n` 16 - autoscaling can happen based on conditions, e.g. `kubectl autoscale deployment <name> --min=7 --max=8 --cpu-percent=60` 17 - this creates a HorizontalPodAutoscaler (hpa). 18 19 ReplicaSet: maintains desired number of instances of a pod defined by a template 20 - in general you can instead specify desired number of replicas in a Deployment 21 22 DaemonSet: ensures pods run on each node of the cluster, even if nodes added at later time 23 - for example, to collect a log on each node of the cluster. one tool for that is Fluentd 24 25 Job: ensures that specific task completes even if pod that should run the task fails 26 - if a node where the pod is running fails, the scheduler launches the pod on another noe 27 - can run pods sequentially or in parallel 28 29 CronJob: causes pod to execute at specific times determined by `schedule` parameter (like `cron`) 30 31 Garbage Collector: responsible for deleting objects when their parent no longer exists 32 - in foreground: parent marked for deletion, then all objects with `blockOwnerDeletion: true` are deleted, then the parent is deleted 33 - in background: first parent deleted, then all children found and deleted.