From f59d9258543481a594a5da26577fdd8288d56df5 Mon Sep 17 00:00:00 2001 From: Mahendra Raghuwanshi Date: Wed, 20 Feb 2019 06:54:46 +0000 Subject: Instantiate common cassandra cluster Issue-ID: OOM-1198 Change-Id: Ie49a34cfbe5bdb2620312e8780dccbc0b86a0d6e Signed-off-by: Mahendra Raghuwanshi --- .../common/cassandra/templates/configmap.yaml | 15 ++++ kubernetes/common/cassandra/templates/pv.yaml | 39 +++++++++++ kubernetes/common/cassandra/templates/service.yaml | 58 ++++++---------- .../common/cassandra/templates/statefulset.yaml | 79 +++++++++++++--------- kubernetes/common/cassandra/templates/volumes.yaml | 39 ----------- 5 files changed, 121 insertions(+), 109 deletions(-) create mode 100644 kubernetes/common/cassandra/templates/configmap.yaml create mode 100644 kubernetes/common/cassandra/templates/pv.yaml delete mode 100644 kubernetes/common/cassandra/templates/volumes.yaml (limited to 'kubernetes/common/cassandra/templates') diff --git a/kubernetes/common/cassandra/templates/configmap.yaml b/kubernetes/common/cassandra/templates/configmap.yaml new file mode 100644 index 0000000000..a9420d7e5b --- /dev/null +++ b/kubernetes/common/cassandra/templates/configmap.yaml @@ -0,0 +1,15 @@ +{{- if .Values.configOverrides }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "common.fullname" . }}-configOverrides + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: +{{ toYaml .Values.configOverrides | indent 2 }} +{{- end }} + diff --git a/kubernetes/common/cassandra/templates/pv.yaml b/kubernetes/common/cassandra/templates/pv.yaml new file mode 100644 index 0000000000..06f41e7683 --- /dev/null +++ b/kubernetes/common/cassandra/templates/pv.yaml @@ -0,0 +1,39 @@ +# Copyright © 2018 Amdocs, Bell Canada, AT&T +# +# Licensed 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. + +{{ if .Values.persistence.enabled }} +{{- $root := . -}} +{{ range $i, $e := until (int $root.Values.replicaCount) }} +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ $root.Release.Name }}-{{ $root.Values.service.name }}-{{ $i }} + namespace: {{ $root.Release.Namespace }} + labels: + type: {{ $root.Values.persistence.storageType }} + app: {{ $root.Values.service.name }} + chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version | replace "+" "_" }} + release: {{ $root.Release.Name }} + heritage: {{ $root.Release.Service }} +spec: + capacity: + storage: {{ $root.Values.persistence.size }} + accessModes: + - {{ $root.Values.persistence.accessMode }} + hostPath: + path: {{ $root.Values.persistence.mountPath }}/{{ $root.Release.Name }}/{{ $root.Values.persistence.mountSubPath }}-{{ $i }} + persistentVolumeReclaimPolicy: {{ $root.Values.persistence.volumeReclaimPolicy }} +{{ end }} +{{ end }} diff --git a/kubernetes/common/cassandra/templates/service.yaml b/kubernetes/common/cassandra/templates/service.yaml index 467a6a9d44..cda519115d 100644 --- a/kubernetes/common/cassandra/templates/service.yaml +++ b/kubernetes/common/cassandra/templates/service.yaml @@ -22,48 +22,28 @@ metadata: chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" spec: type: {{ .Values.service.type }} + publishNotReadyAddresses: true ports: - {{if eq .Values.service.type "NodePort" -}} - - port: {{ .Values.service.externalPort }} - targetPort: {{ .Values.service.internalPort }} - nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort }} - name: {{ .Values.service.portName }} - - port: {{ .Values.service.externalPort2 }} - targetPort: {{ .Values.service.internalPort2 }} - nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort2 }} - name: {{ .Values.service.portName }}2 - - port: {{ .Values.service.externalPort3 }} - targetPort: {{ .Values.service.internalPort3 }} - nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort3 }} - name: {{ .Values.service.portName }}3 - - port: {{ .Values.service.externalPort4 }} - targetPort: {{ .Values.service.internalPort4 }} - nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort4 }} - name: {{ .Values.service.portName }}4 - - port: {{ .Values.service.externalPort5 }} - targetPort: {{ .Values.service.internalPort5 }} - nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort5 }} - name: {{ .Values.service.portName }}5 - - {{- else -}} - - port: {{ .Values.service.externalPort }} - targetPort: {{ .Values.service.internalPort }} - name: {{ .Values.service.portName }} - - port: {{ .Values.service.externalPort2 }} - targetPort: {{ .Values.service.internalPort2 }} - name: {{ .Values.service.portName }}2 - - port: {{ .Values.service.externalPort3 }} - targetPort: {{ .Values.service.internalPort3 }} - name: {{ .Values.service.portName }}3 - - port: {{ .Values.service.externalPort4 }} - targetPort: {{ .Values.service.internalPort4 }} - name: {{ .Values.service.portName }}4 - - port: {{ .Values.service.externalPort5 }} - targetPort: {{ .Values.service.internalPort5 }} - name: {{ .Values.service.portName }}5 - {{- end}} + {{if eq .Values.service.type "NodePort" -}} + {{- $global := . }} + {{- range $index, $ports := .Values.service.ports }} + - port: {{ $ports.port }} + targetPort: {{ $ports.port }} + nodePort: {{ $global.Values.global.nodePortPrefix | default $global.Values.nodePortPrefix }}{{ $ports.nodePort }} + name: {{ $ports.name }} + {{- end }} +{{- else -}} + {{- range $index, $ports := .Values.service.ports }} + - port: {{ $ports.port }} + targetPort: {{ $ports.port }} + name: {{ $ports.name }} + {{- end }} +{{- end}} selector: app: {{ include "common.name" . }} release: {{ .Release.Name }} + clusterIP: None diff --git a/kubernetes/common/cassandra/templates/statefulset.yaml b/kubernetes/common/cassandra/templates/statefulset.yaml index 960d97ed52..86cf46751e 100644 --- a/kubernetes/common/cassandra/templates/statefulset.yaml +++ b/kubernetes/common/cassandra/templates/statefulset.yaml @@ -23,6 +23,10 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} spec: + selector: + matchLabels: + app: {{ include "common.name" . }} + release: {{ .Release.Name }} serviceName: {{ include "common.servicename" . }} replicas: {{ .Values.replicaCount }} podManagementPolicy: {{ .Values.podManagementPolicy }} @@ -35,24 +39,26 @@ spec: release: {{ .Release.Name }} name: {{ include "common.name" . }} spec: + hostNetwork: {{ .Values.hostNetwork }} containers: - name: {{ include "common.name" . }} image: {{ .Values.image }} imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }} ports: - - containerPort: {{ .Values.service.internalPort }} - - containerPort: {{ .Values.service.internalPort2 }} - - containerPort: {{ .Values.service.internalPort3 }} - - containerPort: {{ .Values.service.internalPort4 }} - - containerPort: {{ .Values.service.internalPort5 }} + {{- range $index, $ports := .Values.service.ports }} + - containerPort: {{ $ports.port }} + {{- end }} volumeMounts: - - name: {{ .Values.service.name }} + - name: cassandra-data mountPath: /var/lib/cassandra - {{ if eq .Values.configmapping true }} - - name: {{ .Values.service.name }}-docker-entry-initd - mountPath: /{{ .Values.service.name }}-docker-entrypoint-initdb.d/cassandra.cql - subPath: cassandra.cql - {{ end }} + - name: localtime + mountPath: /etc/localtime + readOnly: true + {{- range $key, $value := .Values.configOverrides }} + - name: cassandra-config-{{ $key | replace "." "-" }} + mountPath: /etc/cassandra/{{ $key }} + subPath: {{ $key }} + {{- end }} {{- if eq .Values.liveness.enabled true }} livenessProbe: exec: @@ -62,6 +68,9 @@ spec: - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }' initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }} periodSeconds: {{ .Values.liveness.periodSeconds }} + timeoutSeconds: {{ .Values.liveness.timeoutSeconds }} + successThreshold: {{ .Values.liveness.successThreshold }} + failureThreshold: {{ .Values.liveness.failureThreshold }} {{ end -}} readinessProbe: exec: @@ -70,10 +79,19 @@ spec: - -c - nodetool status | grep $POD_IP | awk '$1!="UN" { exit 1; }' initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }} - timeoutSeconds: {{ .Values.liveness.periodSeconds }} + periodSeconds: {{ .Values.readiness.periodSeconds }} + timeoutSeconds: {{ .Values.readiness.timeoutSeconds }} + successThreshold: {{ .Values.readiness.successThreshold }} + failureThreshold: {{ .Values.readiness.failureThreshold }} env: - {{- $seed_size := default 1 .Values.replicaCount | int -}} - {{- $global := . }} + {{- $seed_size := default 1 .Values.replicaCount | int -}} + {{- $global := . }} + - name: CASSANDRA_SEEDS + {{- if .Values.hostNetwork }} + value: {{ required "You must fill \".Values.config.seeds\" with list of Cassandra seeds when hostNetwork is set to true" .Values.config.seeds | quote }} + {{- else }} + value: "{{- range $i, $e := until $seed_size }}{{ template "common.fullname" $global }}-{{ $i }}.{{ template "common.servicename" $global }}.{{ $global.Release.Namespace }}.svc.{{ $global.Values.config.cluster_domain }}{{- if (lt ( add1 $i ) $seed_size ) }},{{- end }}{{- end }}" + {{- end }} - name: MAX_HEAP_SIZE value: {{ .Values.config.heap.max }} - name: HEAP_NEWSIZE @@ -88,22 +106,22 @@ spec: value: {{ .Values.config.rackName | quote }} - name: CASSANDRA_AUTO_BOOTSTRAP value: {{ .Values.config.autoBootstrap | quote }} + - name: CASSANDRA_START_RPC + value: {{ default "true" .Values.config.start_rpc | quote }} + - name: CASSANDRA_ENDPOINT_SNITCH + value: {{ default "SimpleSnitch" .Values.config.endpoint_snitch | quote }} - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP - {{ if eq .Values.configmapping true }} lifecycle: - postStart: + preStop: exec: - command: - - /bin/sh - - -c - - > - /bin/sleep {{ .Values.readiness.initialDelaySeconds }}; - cd /{{ .Values.service.name }}-docker-entrypoint-initdb.d; - cqlsh -u root -p root -f cassandra.cql - {{ end }} + {{- if not .Values.persistence.enabled }} + command: ["/bin/sh", "-c", "exec nodetool decommission"] + {{- else }} + command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"] + {{- end }} resources: {{ toYaml .Values.resources | indent 10 }} {{- if .Values.nodeSelector }} @@ -118,21 +136,20 @@ spec: - name: localtime hostPath: path: /etc/localtime - {{ if eq .Values.configmapping true }} - - name: {{ .Values.service.name }}-docker-entry-initd + {{- range $key, $value := .Values.configOverrides }} + - name: cassandra-config-{{ $key | replace "." "-" }} configMap: - name: {{ .Values.service.name }}-docker-entry-initd - {{ end }} + name: {{ include "common.fullname" . }}-configOverrides + {{- end }} {{- if not .Values.persistence.enabled }} - - name: {{ .Values.service.name }} + - name: cassandra-data emptyDir: {} {{- else }} volumeClaimTemplates: - metadata: - name: {{ .Values.service.name }} + name: cassandra-data labels: app: {{ template "common.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" annotations: diff --git a/kubernetes/common/cassandra/templates/volumes.yaml b/kubernetes/common/cassandra/templates/volumes.yaml deleted file mode 100644 index 9640aef7e3..0000000000 --- a/kubernetes/common/cassandra/templates/volumes.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright © 2018 Amdocs, Bell Canada, AT&T -# -# Licensed 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. - -#{{ if .Values.persistence.enabled }} -{{- $root := . -}} -{{ range $i, $e := until (int $root.Values.replicaCount) }} ---- -apiVersion: v1 -kind: PersistentVolume -metadata: - name: {{ $root.Release.Name }}-{{ $root.Values.service.name }}-{{ $i }} - namespace: {{ $root.Release.Namespace }} - labels: - type: {{ $root.Values.persistence.storageType }} - app: {{ $root.Values.service.name }} - chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version | replace "+" "_" }} - release: {{ $root.Release.Name }} - heritage: {{ $root.Release.Service }} -spec: - capacity: - storage: {{ $root.Values.persistence.size }} - accessModes: - - {{ $root.Values.persistence.accessMode }} - hostPath: - path: {{ $root.Values.persistence.mountPath }}/{{ $root.Release.Name }}/{{ $root.Values.persistence.mountSubPath }}-{{ $i }} - persistentVolumeReclaimPolicy: {{ $root.Values.persistence.volumeReclaimPolicy }} -{{ end }} -#{{ end }} -- cgit 1.2.3-korg