From 26763e4774eb497ba1dd8bbb2195df69a87e9bf9 Mon Sep 17 00:00:00 2001 From: Rohan Kumar <131854912+rohank-deepsource@users.noreply.github.com> Date: Wed, 16 Aug 2023 16:38:19 +0530 Subject: [PATCH] feat: add kube-scheduler helm chart (#6) * feat: add kube-scheduler helm chart * fix: remove service --- charts/kube-scheduler/.helmignore | 23 +++ charts/kube-scheduler/Chart.yaml | 24 +++ charts/kube-scheduler/README.md | 32 +++ charts/kube-scheduler/templates/NOTES.txt | 3 + charts/kube-scheduler/templates/_helpers.tpl | 66 ++++++ .../kube-scheduler/templates/clusterrole.yaml | 192 ++++++++++++++++++ .../templates/clusterrolebinding.yaml | 12 ++ .../kube-scheduler/templates/configmap.yaml | 9 + .../kube-scheduler/templates/deployment.yaml | 72 +++++++ charts/kube-scheduler/templates/hpa.yaml | 28 +++ charts/kube-scheduler/templates/role.yaml | 16 ++ .../kube-scheduler/templates/rolebinding.yaml | 12 ++ .../templates/serviceaccount.yaml | 12 ++ charts/kube-scheduler/values.yaml | 130 ++++++++++++ 14 files changed, 631 insertions(+) create mode 100644 charts/kube-scheduler/.helmignore create mode 100644 charts/kube-scheduler/Chart.yaml create mode 100644 charts/kube-scheduler/README.md create mode 100644 charts/kube-scheduler/templates/NOTES.txt create mode 100644 charts/kube-scheduler/templates/_helpers.tpl create mode 100644 charts/kube-scheduler/templates/clusterrole.yaml create mode 100644 charts/kube-scheduler/templates/clusterrolebinding.yaml create mode 100644 charts/kube-scheduler/templates/configmap.yaml create mode 100644 charts/kube-scheduler/templates/deployment.yaml create mode 100644 charts/kube-scheduler/templates/hpa.yaml create mode 100644 charts/kube-scheduler/templates/role.yaml create mode 100644 charts/kube-scheduler/templates/rolebinding.yaml create mode 100644 charts/kube-scheduler/templates/serviceaccount.yaml create mode 100644 charts/kube-scheduler/values.yaml diff --git a/charts/kube-scheduler/.helmignore b/charts/kube-scheduler/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/kube-scheduler/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/kube-scheduler/Chart.yaml b/charts/kube-scheduler/Chart.yaml new file mode 100644 index 0000000..d8e165a --- /dev/null +++ b/charts/kube-scheduler/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: kube-scheduler +description: Helm Chart for the Kubernetes Scheduler + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 1.0.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "v1.24.13" diff --git a/charts/kube-scheduler/README.md b/charts/kube-scheduler/README.md new file mode 100644 index 0000000..e11c416 --- /dev/null +++ b/charts/kube-scheduler/README.md @@ -0,0 +1,32 @@ +## Parameters + +### kube-scheduler configuration parameters + +| Name | Description | Value | +| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | +| `config` | The configuration values for kube-scheduler. Ref: https://kubernetes.io/docs/reference/config-api/kube-scheduler-config.v1beta3/ | `nil` | +| `replicaCount` | Number of kube-scheduler pods to run (if running in HA mode, enable `leaderElection` in config) | `1` | +| `image.repository` | The repository to use for the kube-scheduler image | `registry.k8s.io/kube-scheduler` | +| `image.pullPolicy` | The pull policy for the kube-scheduler image | `IfNotPresent` | +| `image.tag` | The tag for the kube-scheduler image | `v1.24.13` | +| `imagePullSecrets` | Specify docker-registry secret names as an array | `[]` | +| `nameOverride` | String to partially override kube-scheduler.name | `""` | +| `fullnameOverride` | String to partially override kube-scheduler.name | `""` | +| `serviceAccount.create` | Specifies whether a ServiceAccount should be created | `true` | +| `serviceAccount.annotations` | Annotations for service account. Evaluated as a template. Only used if `create` is `true`. | `{}` | +| `serviceAccount.name` | Name of the service account to use. If not set and create is true, a name is generated using the fullname template. | `""` | +| `podAnnotations` | Annotations for the kube-scheduler pods | `{}` | +| `podSecurityContext` | Security context policies to add to the kube-scheduler pods | `{}` | +| `securityContext` | Security context policies to add to the containers | `{}` | +| `resources.limits.cpu` | The resources limits for the kube-scheduler containers | `100m` | +| `resources.limits.memory` | The resources limits for the kube-scheduler containers | `128Mi` | +| `resources.requests.cpu` | The requested cpu for the kube-scheduler containers | `100m` | +| `resources.requests.memory` | The requested memory for the kube-scheduler containers | `128Mi` | +| `autoscaling.enabled` | Enable Horizontal POD autoscaling for kube-scheduler, make sure to enable `leaderElection` in config | `false` | +| `autoscaling.minReplicas` | Minimum number of kube-scheduler replicas | `1` | +| `autoscaling.maxReplicas` | Maximum number of kube-scheduler replicas | `100` | +| `autoscaling.targetCPUUtilizationPercentage` | Target CPU utilization percentage | `80` | +| `autoscaling.targetMemoryUtilizationPercentage` | Target Memory utilization percentage | `80` | +| `nodeSelector` | Node labels for kube-scheduler pods assignment | `{}` | +| `tolerations` | Tolerations for kube-scheduler pods assignment | `[]` | +| `affinity` | Affinity for kube-scheduler pods assignment | `{}` | diff --git a/charts/kube-scheduler/templates/NOTES.txt b/charts/kube-scheduler/templates/NOTES.txt new file mode 100644 index 0000000..ad5b966 --- /dev/null +++ b/charts/kube-scheduler/templates/NOTES.txt @@ -0,0 +1,3 @@ +CHART NAME: {{ .Chart.Name }} +CHART VERSION: {{ .Chart.Version }} +APP VERSION: {{ .Chart.AppVersion }} diff --git a/charts/kube-scheduler/templates/_helpers.tpl b/charts/kube-scheduler/templates/_helpers.tpl new file mode 100644 index 0000000..58335d6 --- /dev/null +++ b/charts/kube-scheduler/templates/_helpers.tpl @@ -0,0 +1,66 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "kube-scheduler.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "kube-scheduler.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "kube-scheduler.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "kube-scheduler.labels" -}} +component: scheduler +tier: control-plane +helm.sh/chart: {{ include "kube-scheduler.chart" . }} +{{ include "kube-scheduler.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "kube-scheduler.selectorLabels" -}} +component: scheduler +tier: control-plane +app.kubernetes.io/name: {{ include "kube-scheduler.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "kube-scheduler.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "kube-scheduler.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/kube-scheduler/templates/clusterrole.yaml b/charts/kube-scheduler/templates/clusterrole.yaml new file mode 100644 index 0000000..ed2a376 --- /dev/null +++ b/charts/kube-scheduler/templates/clusterrole.yaml @@ -0,0 +1,192 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "kube-scheduler.fullname" . }} +rules: +- apiGroups: + - "" + - events.k8s.io + resources: + - events + verbs: + - create + - patch + - update +- apiGroups: + - "" + resources: + - endpoints + verbs: + - create +- apiGroups: + - "" + resourceNames: + - {{ include "kube-scheduler.fullname" . }} + resources: + - endpoints + verbs: + - delete + - get + - patch + - update +- apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - watch +- apiGroups: + - "" + resources: + - pods + verbs: + - delete + - get + - list + - watch +- apiGroups: + - "" + resources: + - bindings + - pods/binding + verbs: + - create +- apiGroups: + - "" + resources: + - pods/status + verbs: + - patch + - update +- apiGroups: + - "" + resources: + - replicationcontrollers + - services + verbs: + - get + - list + - watch +- apiGroups: + - apps + - extensions + resources: + - replicasets + verbs: + - get + - list + - watch +- apiGroups: + - apps + resources: + - statefulsets + verbs: + - get + - list + - watch +- apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - get + - list + - watch +- apiGroups: + - "" + resources: + - persistentvolumeclaims + - persistentvolumes + verbs: + - get + - list + - watch +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +- apiGroups: + - storage.k8s.io + resources: + - csinodes + verbs: + - get + - list + - watch +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - create +- apiGroups: + - coordination.k8s.io + resourceNames: + - {{ include "kube-scheduler.fullname" . }} + resources: + - leases + verbs: + - get + - update +- apiGroups: + - "" + resources: + - namespaces + verbs: + - get + - list + - watch +- apiGroups: + - storage.k8s.io + resources: + - csidrivers + verbs: + - get + - list + - watch +- apiGroups: + - storage.k8s.io + resources: + - csistoragecapacities + verbs: + - get + - list + - watch +- apiGroups: + - "" + resources: + - persistentvolumes + verbs: + - get + - list + - patch + - update + - watch +- apiGroups: + - storage.k8s.io + resources: + - storageclasses + verbs: + - get + - list + - watch +- apiGroups: + - "" + resources: + - persistentvolumeclaims + verbs: + - get + - list + - patch + - update + - watch diff --git a/charts/kube-scheduler/templates/clusterrolebinding.yaml b/charts/kube-scheduler/templates/clusterrolebinding.yaml new file mode 100644 index 0000000..aa615c3 --- /dev/null +++ b/charts/kube-scheduler/templates/clusterrolebinding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "kube-scheduler.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ include "kube-scheduler.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +roleRef: + kind: ClusterRole + name: {{ include "kube-scheduler.fullname" . }} + apiGroup: rbac.authorization.k8s.io diff --git a/charts/kube-scheduler/templates/configmap.yaml b/charts/kube-scheduler/templates/configmap.yaml new file mode 100644 index 0000000..147cd89 --- /dev/null +++ b/charts/kube-scheduler/templates/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "kube-scheduler.fullname" . }} + labels: + {{- include "kube-scheduler.labels" . | nindent 4 }} +data: + config.yaml: | +{{ .Values.config | toYaml | toString | indent 4 }} diff --git a/charts/kube-scheduler/templates/deployment.yaml b/charts/kube-scheduler/templates/deployment.yaml new file mode 100644 index 0000000..1414fd8 --- /dev/null +++ b/charts/kube-scheduler/templates/deployment.yaml @@ -0,0 +1,72 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "kube-scheduler.fullname" . }} + labels: + {{- include "kube-scheduler.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "kube-scheduler.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "kube-scheduler.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "kube-scheduler.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + command: + - /usr/local/bin/kube-scheduler + - --config=/etc/kubernetes/kube-scheduler/config.yaml + imagePullPolicy: {{ .Values.image.pullPolicy }} + livenessProbe: + httpGet: + path: /healthz + port: 10259 + scheme: HTTPS + readinessProbe: + httpGet: + path: /healthz + port: 10259 + scheme: HTTPS + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: config-volume + mountPath: /etc/kubernetes/kube-scheduler + volumes: + - name: config-volume + configMap: + name: {{ include "kube-scheduler.fullname" . }} + items: + - key: config.yaml + path: config.yaml + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/kube-scheduler/templates/hpa.yaml b/charts/kube-scheduler/templates/hpa.yaml new file mode 100644 index 0000000..a0dd97b --- /dev/null +++ b/charts/kube-scheduler/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "kube-scheduler.fullname" . }} + labels: + {{- include "kube-scheduler.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "kube-scheduler.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/kube-scheduler/templates/role.yaml b/charts/kube-scheduler/templates/role.yaml new file mode 100644 index 0000000..2c8548d --- /dev/null +++ b/charts/kube-scheduler/templates/role.yaml @@ -0,0 +1,16 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "kube-scheduler.fullname" . }} + namespace: {{ .Release.Namespace }} +rules: +- apiGroups: + - "" + resourceNames: + - extension-apiserver-authentication + resources: + - configmaps + verbs: + - get + - list + - watch diff --git a/charts/kube-scheduler/templates/rolebinding.yaml b/charts/kube-scheduler/templates/rolebinding.yaml new file mode 100644 index 0000000..5c3f0d2 --- /dev/null +++ b/charts/kube-scheduler/templates/rolebinding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "kube-scheduler.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ include "kube-scheduler.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +roleRef: + kind: Role + name: {{ include "kube-scheduler.fullname" . }} + apiGroup: rbac.authorization.k8s.io diff --git a/charts/kube-scheduler/templates/serviceaccount.yaml b/charts/kube-scheduler/templates/serviceaccount.yaml new file mode 100644 index 0000000..674f0c4 --- /dev/null +++ b/charts/kube-scheduler/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "kube-scheduler.serviceAccountName" . }} + labels: + {{- include "kube-scheduler.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/kube-scheduler/values.yaml b/charts/kube-scheduler/values.yaml new file mode 100644 index 0000000..2683420 --- /dev/null +++ b/charts/kube-scheduler/values.yaml @@ -0,0 +1,130 @@ +## @section kube-scheduler configuration parameters +## + +## @param config The configuration values for kube-scheduler. Ref: https://kubernetes.io/docs/reference/config-api/kube-scheduler-config.v1beta3/ +config: + # apiVersion: kubescheduler.config.k8s.io/v1beta3 + # kind: KubeSchedulerConfiguration + # leaderElection: + # leaderElect: false + # profiles: + # - schedulerName: deepsource-kube-scheduler + # plugins: + # score: + # enabled: + # - name: NodeResourcesFit + # weight: 1 + # disabled: + # - name: NodeResourcesBalancedAllocation + # weight: 1 + # pluginConfig: + # - name: NodeResourcesFit + # args: + # scoringStrategy: + # type: MostAllocated + # resources: + # - name: cpu + # weight: 1 + # - name: memory + # weight: 1 + +## @param replicaCount Number of kube-scheduler pods to run (if running in HA mode, enable `leaderElection` in config) +replicaCount: 1 + +## kube-scheduler image parameters +## @param image.repository The repository to use for the kube-scheduler image +## @param image.pullPolicy The pull policy for the kube-scheduler image +## @param image.tag The tag for the kube-scheduler image +image: + repository: registry.k8s.io/kube-scheduler + pullPolicy: IfNotPresent + tag: v1.24.13 + +## @param imagePullSecrets Specify docker-registry secret names as an array +imagePullSecrets: [] + +## @param nameOverride String to partially override kube-scheduler.name +## +nameOverride: "" + +## @param fullnameOverride String to partially override kube-scheduler.name +## +fullnameOverride: "" + +## ServiceAccount configuration +## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ +## @param serviceAccount.create Specifies whether a ServiceAccount should be created +## @param serviceAccount.annotations Annotations for service account. Evaluated as a template. Only used if `create` is `true`. +## @param serviceAccount.name Name of the service account to use. If not set and create is true, a name is generated using the fullname template. +## +serviceAccount: + create: true + annotations: {} + name: "" + +## @param podAnnotations Annotations for the kube-scheduler pods +## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +## +podAnnotations: {} + +## @param podSecurityContext Security context policies to add to the kube-scheduler pods +## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod +## +podSecurityContext: {} + +## @param securityContext Security context policies to add to the containers +## +securityContext: {} + +## kube-scheduler resource requests and limits +## ref: https://kubernetes.io/docs/user-guide/compute-resources/ +## +resources: + ## The resources limits for the kube-scheduler containers + ## + limits: + ## @param resources.limits.cpu The resources limits for the kube-scheduler containers + ## + cpu: 100m + ## @param resources.limits.memory The resources limits for the kube-scheduler containers + ## + memory: 128Mi + ## The requested resources for the kube-scheduler containers + ## + requests: + ## @param resources.requests.cpu The requested cpu for the kube-scheduler containers + ## + cpu: 100m + ## @param resources.requests.memory The requested memory for the kube-scheduler containers + ## + memory: 128Mi + +## Autoscaling parameters +## ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ +## @param autoscaling.enabled Enable Horizontal POD autoscaling for kube-scheduler, make sure to enable `leaderElection` in config +## @param autoscaling.minReplicas Minimum number of kube-scheduler replicas +## @param autoscaling.maxReplicas Maximum number of kube-scheduler replicas +## @param autoscaling.targetCPUUtilizationPercentage Target CPU utilization percentage +## @param autoscaling.targetMemoryUtilizationPercentage Target Memory utilization percentage +## +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + targetMemoryUtilizationPercentage: 80 + +## @param nodeSelector Node labels for kube-scheduler pods assignment +## ref: https://kubernetes.io/docs/user-guide/node-selection/ +## +nodeSelector: {} + +## @param tolerations Tolerations for kube-scheduler pods assignment +## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ +## +tolerations: [] + +## @param affinity Affinity for kube-scheduler pods assignment +## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity +## +affinity: {}