georgew5656 commented on code in PR #14674: URL: https://github.com/apache/druid/pull/14674#discussion_r1277680137
########## extensions-contrib/kubernetes-overlord-extensions/README.md: ########## @@ -0,0 +1,222 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +# Kubernetes Task Scheduling Extension +The Kubernetes Task Scheduling extension allows a Druid cluster running on Kubernetes to schedule +its tasks as Kubernetes Jobs instead of sending them to workers (middle managers or indexers). + +## How the Kubernetes Task Scheduler works. +The Kubernetes Task Scheduler replaces the HTTP or Zookeeper based task runner (which both send tasks to workers) on the overlord. +Based on which TaskAdapter (`druid.indexer.runner.k8s.adapter.type`) is selected, every task that the overlord runs is transformed into a Kubernetes Job that runs +the Druid peon process for that task and then exits. The overlord then watches the K8s API for the Job's success or failure. + +## Configuration + +## Enabling +1. Create a role binding for the overlord's service account that provides the needed permissions for interacting with Kubernetes. + ``` + kind: Role + apiVersion: rbac.authorization.k8s.io/v1 + metadata: + namespace: <druid-namespace> + name: druid-k8s-task-scheduler + rules: + - apiGroups: ["batch"] + resources: ["jobs"] + verbs: ["get", "watch", "list", "delete", "create"] + - apiGroups: [""] + resources: ["pods", "pods/log"] + verbs: ["get", "watch", "list", "delete", "create"] + --- + kind: RoleBinding + apiVersion: rbac.authorization.k8s.io/v1 + metadata: + name: druid-k8s-binding + namespace: <druid-namespace> + subjects: + - kind: ServiceAccount + name: <druid-overlord-k8s-service-account> + namespace: <druid-namespace> + roleRef: + kind: Role + name: druid-k8s-task-scheduler + apiGroup: rbac.authorization.k8s.io + ``` + +2. Configure the overlord's runtime properties to use the Kubernetes task scheduler. + ``` + druid.indexer.runner.type=k8s + druid.indexer.task.encapsulatedTask=true + druid.indexer.runner.namespace=<druid-namespace> + druid.indexer.runner.capacity=100 (number of concurrent jobs that can be sent to kubernetes at once) + ``` + +3. Choose a Task Adapter (determines how tasks will be converted to a Kubernetes Job) + #### Option 1. Copy the overlord's pod template to use as the base job template + This adapter takes the overlord's own pod specification and injects needed information (like the task id) on top of it. + + Required overlord runtime properties + ``` + druid.indexer.runner.k8s.adapter.type=overlordSingleContainer (defaults to this if not specified) + druid.indexer.runner.k8s.adapter.type=overlordMultiContainer (same as overlordSingleContainer except sidecars are respected) + ``` + Additional overlord runtime properties + ``` + druid.indexer.runner.javaOptsArray=[] (JVM args for the peon running in the Job, If -Xmx is specified, the adapter will attempt to scale the Kubernetes requests of the pod to correspond with it) + druid.indexer.runner.labels={} (Additional labels to add to the Job) + druid.indexer.runner.annotations={} (Additional annotations to add to the Job) + druid.indexer.runner.peonMonitors={} (Override the list of Druid monitors for the peon, otherwise the overlord's list will be used) + ``` + + #### Option 2. Bring your own pod template to use as the base job pod template + This adapter expects a [PodTemplate](https://kubernetes.io/docs/concepts/workloads/pods/#pod-templates) to be available on the overlord's file system. + This pod template is used as the base of the job template (additional info like the task id is injected on top of it). + You can override things like labels, environment variables, resources, annotation, or even the base image with this template. + + Required overlord runtime properties + ``` + druid.indexer.runner.k8s.adapter.type=customTemplateAdapter + druid.indexer.runner.k8s.podTemplate.base=/opt/druid/conf/druid/cluster/pod-template.yaml` (location of pod template on overlord) + ``` + + The following PodTemplate is an example that uses the regular druid docker image. + ``` + apiVersion: "v1" + kind: "PodTemplate" + template: + metadata: + annotations: + custom-annotation: "hello" + labels: + custom-label: "hello" + spec: + affinity: {} + containers: + - command: + - sh + - -c + - | + /peon.sh /druid/data 1 Review Comment: this is from the druid docker image https://github.com/apache/druid/blob/master/distribution/docker/peon.sh, although if you build your own docker image the command might be different -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
