From a8ff8cb144fcea00251069a8c25d41aa94246cd3 Mon Sep 17 00:00:00 2001 From: srinivasa-vasu Date: Wed, 7 Jul 2021 17:40:10 +0530 Subject: [PATCH 1/2] local --- stable/yugabyte/templates/service.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stable/yugabyte/templates/service.yaml b/stable/yugabyte/templates/service.yaml index 65d1f5df96..8fbca3656a 100644 --- a/stable/yugabyte/templates/service.yaml +++ b/stable/yugabyte/templates/service.yaml @@ -162,6 +162,10 @@ spec: {{- include "yugabyte.applabel" ($appLabelArgs) | indent 8 }} {{- include "yugabyte.labels" $root | indent 8 }} spec: + securityContext: + runAsUser: 1001 + runAsGroup: 1001 + fsGroup: 1001 {{- if $root.Values.Image.pullSecretName }} imagePullSecrets: - name: {{ $root.Values.Image.pullSecretName }} From fa9fea935a6100d457057e3a4637347916049162 Mon Sep 17 00:00:00 2001 From: Srinivasa Vasu Date: Tue, 20 Jul 2021 09:17:57 +0530 Subject: [PATCH 2/2] support for local persistent volumes Signed-off-by: Srinivasa Vasu --- stable/yugabyte/templates/_helpers.tpl | 21 ++++++++ stable/yugabyte/templates/local-pd-pv.yaml | 45 +++++++++++++++++ stable/yugabyte/templates/local-pd-sc.yaml | 10 ++++ stable/yugabyte/templates/service.yaml | 58 ++++++++++++---------- stable/yugabyte/values.yaml | 8 +++ 5 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 stable/yugabyte/templates/local-pd-pv.yaml create mode 100644 stable/yugabyte/templates/local-pd-sc.yaml diff --git a/stable/yugabyte/templates/_helpers.tpl b/stable/yugabyte/templates/_helpers.tpl index 57bb7ecdde..fee1de6773 100644 --- a/stable/yugabyte/templates/_helpers.tpl +++ b/stable/yugabyte/templates/_helpers.tpl @@ -187,3 +187,24 @@ Compute the maximum number of unavailable pods based on the number of master rep {{- $max_unavailable_master_replicas := 100 | div (100 | sub (2 | div ($master_replicas_100x | add 100))) -}} {{- printf "%d" $max_unavailable_master_replicas -}} {{- end -}} + +{{/* +Local persistent disk storage class name +*/}} +{{- define "yugabyte.localsc_name" -}} + {{- printf "%s-local-sc" (include "yugabyte.fullname" .) -}} +{{- end -}} + +{{/* +Local persistent disk name +*/}} +{{- define "yugabyte.localdisk_name" -}} + {{- printf "%s-local-pv" (include "yugabyte.fullname" .) -}} +{{- end -}} + +{{/* +Local persistent disk storage mount path +*/}} +{{- define "yugabyte.localdisk_mntpath" -}} + {{ default .Values.storage.localDisk.mountPath "/mnt/disks/ssd" }} +{{- end -}} diff --git a/stable/yugabyte/templates/local-pd-pv.yaml b/stable/yugabyte/templates/local-pd-pv.yaml new file mode 100644 index 0000000000..0ad2b1c1a7 --- /dev/null +++ b/stable/yugabyte/templates/local-pd-pv.yaml @@ -0,0 +1,45 @@ +{{- if .Values.storage.localDisk.enabled }} + {{- $replicaCounter := 1 }} + {{- $storageInfo := dict "count" 1 "size" "10G" }} + {{- range tuple "master" "tserver" }} + {{- if eq . "master" }} + {{- $replicaCounter = $.Values.replicas.master }} + {{- $storageInfo = dict "count" $.Values.storage.master.count "size" $.Values.storage.master.size }} + {{- else }} + {{- $replicaCounter = $.Values.replicas.tserver }} + {{- $storageInfo = dict "count" $.Values.storage.tserver.count "size" $.Values.storage.tserver.size }} + {{- end}} + {{- range $replicaIndex := until (int ($replicaCounter)) }} + {{- range $index := until (int ($storageInfo.count )) }} +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{- include "yugabyte.localdisk_name" $ | indent 1 }}-{{ $replicaCounter }}{{ $replicaIndex }}{{ $index }} + labels: + {{- include "yugabyte.labels" $ | indent 4 }} +spec: + capacity: + storage: {{ $storageInfo.size }} + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + storageClassName: {{- include "yugabyte.localsc_name" $ | indent 1 }} + local: + path: {{- include "yugabyte.localdisk_mntpath" $ | indent 1 }}{{ $index }} + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: failure-domain.beta.kubernetes.io/zone + operator: In + values: + - {{ $.Values.AZ }} + - matchExpressions: + - key: topology.kubernetes.io/zone + operator: In + values: + - {{ $.Values.AZ }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/stable/yugabyte/templates/local-pd-sc.yaml b/stable/yugabyte/templates/local-pd-sc.yaml new file mode 100644 index 0000000000..59ad0b0dfd --- /dev/null +++ b/stable/yugabyte/templates/local-pd-sc.yaml @@ -0,0 +1,10 @@ +{{- if .Values.storage.localDisk.enabled }} +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: {{- include "yugabyte.localsc_name" $ | indent 1 }} + labels: + {{- include "yugabyte.labels" $ | indent 4 }} +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer +{{- end }} diff --git a/stable/yugabyte/templates/service.yaml b/stable/yugabyte/templates/service.yaml index 8fbca3656a..87dfe9d0e9 100644 --- a/stable/yugabyte/templates/service.yaml +++ b/stable/yugabyte/templates/service.yaml @@ -55,6 +55,7 @@ data: apiVersion: v1 kind: Service metadata: + namespace: "{{ $root.Release.Namespace }}" name: {{ $root.Values.oldNamingStyle | ternary .name (printf "%s-%s" (include "yugabyte.fullname" $root) .name) | quote }} labels: {{- include "yugabyte.applabel" ($appLabelArgs) | indent 4 }} @@ -77,17 +78,20 @@ spec: apiVersion: v1 kind: Service metadata: + namespace: "{{ $root.Release.Namespace }}" name: {{ $root.Values.oldNamingStyle | ternary $endpoint.name (printf "%s-%s" (include "yugabyte.fullname" $root) $endpoint.name) | quote }} + {{- if $endpoint.annotations }} annotations: {{ toYaml $endpoint.annotations | indent 4 }} + {{- end }} labels: {{- include "yugabyte.applabel" ($appLabelArgs) | indent 4 }} {{- include "yugabyte.labels" $root | indent 4 }} spec: - {{ if eq $root.Release.Service "Tiller" }} + {{- if eq $root.Release.Service "Tiller" }} clusterIP: - {{ else }} - {{ if $endpoint.clusterIP }} + {{- else }} + {{- if $endpoint.clusterIP }} clusterIP: {{ $endpoint.clusterIP }} {{- end }} {{- end }} @@ -115,26 +119,29 @@ metadata: spec: serviceName: {{ $root.Values.oldNamingStyle | ternary .name (printf "%s-%s" (include "yugabyte.fullname" $root) .name) | quote }} podManagementPolicy: {{ $root.Values.PodManagementPolicy }} - {{ if eq .name "yb-masters" }} + {{- if eq .name "yb-masters" }} replicas: {{ $root.Values.replicas.master }} - {{ else }} + {{- else }} replicas: {{ $root.Values.replicas.tserver }} - {{ end }} + {{- end }} {{- $storageInfo := (eq .name "yb-masters") | ternary $root.Values.storage.master $root.Values.storage.tserver -}} - {{ if not $root.Values.storage.ephemeral }} + {{- $sclass := $root.Values.storage.localDisk.enabled | ternary (printf "%s" (include "yugabyte.localsc_name" $root)) $storageInfo.storageClass -}} + {{- if not $root.Values.storage.ephemeral }} volumeClaimTemplates: {{- range $index := until (int ($storageInfo.count )) }} - metadata: name: {{ $root.Values.oldNamingStyle | ternary (printf "datadir%d" $index) (printf "%s%d" (include "yugabyte.volume_name" $root) $index) }} + {{- if $sclass }} annotations: - volume.beta.kubernetes.io/storage-class: {{ $storageInfo.storageClass }} + volume.beta.kubernetes.io/storage-class: {{ $sclass }} + {{- end }} labels: {{- include "yugabyte.labels" $root | indent 10 }} spec: accessModes: - "ReadWriteOnce" - {{- if $storageInfo.storageClass }} - storageClassName: {{ $storageInfo.storageClass }} + {{- if $sclass }} + storageClassName: {{ $sclass }} {{- end }} resources: requests: @@ -144,28 +151,24 @@ spec: updateStrategy: type: RollingUpdate rollingUpdate: - {{ if eq .name "yb-masters" }} + {{- if eq .name "yb-masters" }} partition: {{ $root.Values.partition.master }} - {{ else }} + {{- else }} partition: {{ $root.Values.partition.tserver }} - {{ end }} + {{- end }} selector: matchLabels: {{- include "yugabyte.appselector" ($appLabelArgs) | indent 6 }} template: metadata: - {{ if $root.Values.networkAnnotation }} + {{- if $root.Values.networkAnnotation }} annotations: {{ toYaml $root.Values.networkAnnotation | indent 8}} - {{ end }} + {{- end }} labels: {{- include "yugabyte.applabel" ($appLabelArgs) | indent 8 }} {{- include "yugabyte.labels" $root | indent 8 }} spec: - securityContext: - runAsUser: 1001 - runAsGroup: 1001 - fsGroup: 1001 {{- if $root.Values.Image.pullSecretName }} imagePullSecrets: - name: {{ $root.Values.Image.pullSecretName }} @@ -176,7 +179,7 @@ spec: {{- end }} affinity: # Set the anti-affinity selector scope to YB masters. - {{ if $root.Values.AZ }} + {{- if $root.Values.AZ }} nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: @@ -190,7 +193,7 @@ spec: operator: In values: - {{ $root.Values.AZ }} - {{ end }} + {{- end }} podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 @@ -249,11 +252,11 @@ spec: value: /root/.yugabytedb/root.crt {{- end }} resources: - {{ if eq .name "yb-masters" }} + {{- if eq .name "yb-masters" }} {{ toYaml $root.Values.resource.master | indent 10 }} - {{ else }} + {{- else }} {{ toYaml $root.Values.resource.tserver | indent 10 }} - {{ end }} + {{- end }} # core dumps are collected to workingDir if # kernel.core_pattern is set to a relative path like # core.%e.%p.%t ref: @@ -381,7 +384,7 @@ spec: name: {{ $label | quote }} {{- end}} volumeMounts: - {{ if not $root.Values.storage.ephemeral }} + {{- if not $root.Values.storage.ephemeral }} {{- range $index := until (int ($storageInfo.count)) }} - name: {{ $root.Values.oldNamingStyle | ternary (printf "datadir%d" $index) (printf "%s%d" (include "yugabyte.volume_name" $root) $index) }} mountPath: /mnt/disk{{ $index }} @@ -396,7 +399,7 @@ spec: readOnly: true {{- end }} - {{ if not $root.Values.storage.ephemeral }} + {{- if not $root.Values.storage.ephemeral }} - name: yb-cleanup image: "{{ $root.Values.Image.repository }}:{{ $root.Values.Image.tag }}" imagePullPolicy: {{ $root.Values.Image.pullPolicy }} @@ -421,7 +424,7 @@ spec: {{- end }} volumes: - {{ if not $root.Values.storage.ephemeral }} + {{- if not $root.Values.storage.ephemeral }} {{- range $index := until (int ($storageInfo.count)) }} - name: {{ $root.Values.oldNamingStyle | ternary (printf "datadir%d" $index) (printf "%s%d" (include "yugabyte.volume_name" $root) $index) }} hostPath: @@ -443,6 +446,7 @@ spec: apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: + namespace: "{{ $root.Release.Namespace }}" name: {{ $root.Values.oldNamingStyle | ternary (printf "%s-pdb" .label) (printf "%s-%s-pdb" (include "yugabyte.fullname" $root) .name) }} spec: maxUnavailable: {{ template "yugabyte.max_unavailable_for_quorum" $root }} diff --git a/stable/yugabyte/values.yaml b/stable/yugabyte/values.yaml index 4732fa5325..6daac72e16 100644 --- a/stable/yugabyte/values.yaml +++ b/stable/yugabyte/values.yaml @@ -17,6 +17,14 @@ storage: count: 2 size: 10Gi storageClass: standard + localDisk: + # Turning this flag on would configure the local persistent disk. No of disks configured would still depend + # on storage.master.count and storage.tserver.count. Set those values appropriately based on the number of local + # disks configured during cluster creation. This would set the static PVs to be mounted instead of the dynamic + # storage provision. + enabled: false + # This would be the path referred in the static PVs. A running index starting from '0' will be suffixed to this path + mountPath: /mnt/disks/ssd resource: master: