diff --git a/incubator/sparkoperator/Chart.yaml b/incubator/sparkoperator/Chart.yaml new file mode 100644 index 0000000000..79fa6dedfe --- /dev/null +++ b/incubator/sparkoperator/Chart.yaml @@ -0,0 +1,11 @@ +name: sparkoperator +description: A Helm chart for Spark on Kubernetes operator +version: 0.1.0 +appVersion: latest +kubeVersion: ">=1.8.0-0" +keywords: + - spark +home: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator +maintainers: + - name: yuchaoran2011 + email: yuchaoran2011@gmail.com diff --git a/incubator/sparkoperator/README.md b/incubator/sparkoperator/README.md new file mode 100644 index 0000000000..745df16dbe --- /dev/null +++ b/incubator/sparkoperator/README.md @@ -0,0 +1,33 @@ +### Helm Chart for Spark Operator + +This is the Helm chart for the [Spark-on-Kubernetes Operator](https://github.com/GoogleCloudPlatform/spark-on-k8s-operator). + +#### Prerequisites + +The Operator requires Kubernetes version 1.8 and above because it relies on garbage collection of custom resources. If customization of driver and executor pods (through mounting custom configMaps and volumes) is desired, then the [Mutating Admission Webhook](https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/quick-start-guide.md#using-the-mutating-admission-webhook) needs to be enabled and it only became beta in Kubernetes 1.9. + +#### Installing the chart + +The chart can be installed by running: + +```bash +$ helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator +$ helm install incubator/sparkoperator +``` + +By default, the operator is installed in a namespace called "spark-operator". It would be created if it does not exist. + +#### Configuration + +The following table lists the configurable parameters of the Spark operator chart and their default values. + +| Parameter | Description | Default | +| ------------------- | ----------------------------------------------------- | ------------------------- | +| `operatorImageName` | The name of the operator image | `lightbend/sparkoperator` | +| `operatorVersion` | The version of the operator to install | `2.3.1` | +| `operatorNamespace` | K8s namespace where operator is installed | `spark-operator` | +| `enableWebhook` | Whether to enable mutating admission webhook | true | +| `enableMetrics` | Whether to expose metrics to be scraped by Premetheus | true | + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. + diff --git a/incubator/sparkoperator/templates/spark-operator-rbac.yaml b/incubator/sparkoperator/templates/spark-operator-rbac.yaml new file mode 100644 index 0000000000..9cd970f98e --- /dev/null +++ b/incubator/sparkoperator/templates/spark-operator-rbac.yaml @@ -0,0 +1,39 @@ +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRole +metadata: + name: sparkoperator +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["*"] +- apiGroups: [""] + resources: ["services", "configmaps", "secrets"] + verbs: ["create", "get", "delete"] +- apiGroups: [""] + resources: ["nodes"] + verbs: ["get"] +- apiGroups: [""] + resources: ["events"] + verbs: ["create", "update", "patch"] +- apiGroups: ["apiextensions.k8s.io"] + resources: ["customresourcedefinitions"] + verbs: ["create", "get", "update", "delete"] +- apiGroups: ["admissionregistration.k8s.io"] + resources: ["mutatingwebhookconfigurations"] + verbs: ["create", "get", "update", "delete"] +- apiGroups: ["sparkoperator.k8s.io"] + resources: ["sparkapplications", "scheduledsparkapplications"] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRoleBinding +metadata: + name: sparkoperator +subjects: + - kind: ServiceAccount + name: sparkoperator + namespace: {{ .Values.operatorNamespace }} +roleRef: + kind: ClusterRole + name: sparkoperator + apiGroup: rbac.authorization.k8s.io diff --git a/incubator/sparkoperator/templates/spark-operator.yaml b/incubator/sparkoperator/templates/spark-operator.yaml new file mode 100644 index 0000000000..8e5f68ead8 --- /dev/null +++ b/incubator/sparkoperator/templates/spark-operator.yaml @@ -0,0 +1,143 @@ +# If the admission webhook is enabled, then a post-install step is required +# to generate and install the secret in the operator namespace. + +# In the post-install hook, the token corresponding to the operator service account +# is used to authenticate with the Kubernetes API server to install the secret bundle. + +{{ if .Values.enableWebhook }} +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.operatorNamespace }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: sparkoperator + namespace: {{ .Values.operatorNamespace }} +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: sparkoperator-init + namespace: {{ .Values.operatorNamespace }} + annotations: + "helm.sh/hook": post-install + "helm.sh/hook-delete-policy": hook-succeeded + labels: + app.kubernetes.io/name: sparkoperator + app.kubernetes.io/version: {{ .Values.operatorVersion }} +spec: + template: + metadata: + labels: + app.kubernetes.io/name: sparkoperator + app.kubernetes.io/version: {{ .Values.operatorVersion }} + spec: + serviceAccountName: sparkoperator + restartPolicy: OnFailure + containers: + - name: main + image: {{ .Values.operatorImageName }}:{{ .Values.operatorVersion }} + imagePullPolicy: Always + command: ["/usr/bin/gencerts.sh", "-n", "{{ .Values.operatorNamespace }}", "-p"] +{{ else }} +--- +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.operatorNamespace }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: sparkoperator + namespace: {{ .Values.operatorNamespace }} +{{ end }} +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: sparkoperator + namespace: {{ .Values.operatorNamespace }} + labels: + app.kubernetes.io/name: sparkoperator + app.kubernetes.io/version: {{ .Values.operatorVersion }} +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: sparkoperator + app.kubernetes.io/version: {{ .Values.operatorVersion }} + strategy: + type: Recreate + template: + metadata: + {{- if .Values.enableMetrics }} + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "10254" + prometheus.io/path: "/metrics" + {{- end }} + labels: + app.kubernetes.io/name: sparkoperator + app.kubernetes.io/version: {{ .Values.operatorVersion }} + initializers: + pending: [] + spec: + serviceAccountName: sparkoperator + {{- if .Values.enableWebhook }} + volumes: + - name: webhook-certs + secret: + secretName: spark-webhook-certs + {{- end }} + containers: + - name: sparkoperator + image: {{ .Values.operatorImageName }}:{{ .Values.operatorVersion }} + imagePullPolicy: Always + {{- if .Values.enableWebhook }} + volumeMounts: + - name: webhook-certs + mountPath: /etc/webhook-certs + {{- end }} + {{- if .Values.enableMetrics }} + ports: + - containerPort: 10254 + {{ end }} + command: ["/usr/bin/spark-operator"] + {{- if and (.Values.enableMetrics) (.Values.enableWebhook) }} + args: + - -enable-metrics=true + - -metrics-labels=app_type + - -enable-webhook=true + - -logtostderr + {{- else if (.Values.enableMetrics) }} + args: + - -enable-metrics=true + - -metrics-labels=app_type + - -logtostderr + {{- else if (.Values.enableWebhook) }} + args: + - -enable-webhook=true + - -logtostderr + {{- else }} + args: + - -logtostderr + {{- end }} +--- +{{ if .Values.enableWebhook }} +kind: Service +apiVersion: v1 +metadata: + name: spark-webhook + namespace: {{ .Values.operatorNamespace }} +spec: + ports: + - port: 443 + targetPort: 8080 + name: webhook + selector: + app.kubernetes.io/name: sparkoperator + app.kubernetes.io/version: {{ .Values.operatorVersion }} +{{ end }} \ No newline at end of file diff --git a/incubator/sparkoperator/templates/spark-rbac.yaml b/incubator/sparkoperator/templates/spark-rbac.yaml new file mode 100644 index 0000000000..91629e0aa1 --- /dev/null +++ b/incubator/sparkoperator/templates/spark-rbac.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: spark + namespace: default +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: Role +metadata: + namespace: default + name: spark-role +rules: +- apiGroups: + - "" # "" indicates the core API group + resources: + - "pods" + verbs: + - "*" +- apiGroups: + - "" # "" indicates the core API group + resources: + - "services" + verbs: + - "*" +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: RoleBinding +metadata: + name: spark-role-binding + namespace: default +subjects: +- kind: ServiceAccount + name: spark + namespace: default +roleRef: + kind: Role + name: spark-role + apiGroup: rbac.authorization.k8s.io diff --git a/incubator/sparkoperator/values.yaml b/incubator/sparkoperator/values.yaml new file mode 100644 index 0000000000..332c718e8e --- /dev/null +++ b/incubator/sparkoperator/values.yaml @@ -0,0 +1,6 @@ +operatorImageName: lightbend/sparkoperator +operatorVersion: 2.3.1 +operatorNamespace: spark-operator + +enableWebhook: true +enableMetrics: true