diff --git a/Makefile b/Makefile index b55fd33beb..de33c58b2d 100644 --- a/Makefile +++ b/Makefile @@ -225,6 +225,9 @@ UPX_OPTIONS ?= -9 K8S_EXTERNAL_SCYLLA_MANIFEST ?= k8s/external/scylla/scyllacluster.yaml +K8S_KUBECTL_VERSION ?= $(eval K8S_KUBECTL_VERSION := $(shell kubectl version --short))$(K8S_KUBECTL_VERSION) +K8S_SERVER_VERSION ?= $(eval K8S_SERVER_VERSION := $(shell echo "$(K8S_KUBECTL_VERSION)" | sed -e "s/.*Server.*\(v[0-9]\.[0-9]*\)\..*/\1/g"))$(K8S_SERVER_VERSION) + COMMA := , SHELL = bash diff --git a/Makefile.d/k8s.mk b/Makefile.d/k8s.mk index 496bbfe8da..aaa245ad1e 100644 --- a/Makefile.d/k8s.mk +++ b/Makefile.d/k8s.mk @@ -117,6 +117,7 @@ k8s/vald/deploy/cassandra: \ --set defaults.image.tag=$(VERSION) \ --output-dir $(TEMP_DIR) \ charts/vald + kubectl apply -f $(TEMP_DIR)/vald/templates/jobs/db/initialize/cassandra kubectl apply -f $(TEMP_DIR)/vald/templates/manager/backup kubectl apply -f $(TEMP_DIR)/vald/templates/manager/compressor kubectl apply -f $(TEMP_DIR)/vald/templates/manager/index @@ -140,6 +141,7 @@ k8s/vald/delete/cassandra: \ --set defaults.image.tag=$(VERSION) \ --output-dir $(TEMP_DIR) \ charts/vald + kubectl delete -f $(TEMP_DIR)/vald/templates/jobs/db/initialize/cassandra kubectl delete -f $(TEMP_DIR)/vald/templates/manager/backup kubectl delete -f $(TEMP_DIR)/vald/templates/manager/compressor kubectl delete -f $(TEMP_DIR)/vald/templates/manager/index @@ -237,14 +239,20 @@ k8s/external/redis/initialize: .PHONY: k8s/external/cassandra/deploy ## deploy cassandra to k8s k8s/external/cassandra/deploy: - kubectl apply -f k8s/jobs/db/initialize/cassandra/configmap.yaml + kubectl apply -f https://raw.githubusercontent.com/datastax/cass-operator/master/docs/user/cass-operator-manifests-$(K8S_SERVER_VERSION).yaml + sleep 2 + kubectl apply -n cass-operator -f k8s/jobs/db/initialize/cassandra/secret.yaml + kubectl wait -n cass-operator --for=condition=ready pod -l name=cass-operator --timeout=600s kubectl apply -f k8s/external/cassandra + sleep 20 + kubectl wait -n cass-operator --for=condition=ready pod -l statefulset.kubernetes.io/pod-name=cluster0-dc0-default-sts-0 --timeout=600s .PHONY: k8s/external/cassandra/delete ## delete cassandra from k8s k8s/external/cassandra/delete: + kubectl delete -n cass-operator -f k8s/jobs/db/initialize/cassandra/secret.yaml kubectl delete -f k8s/external/cassandra - kubectl delete configmap cassandra-initdb + kubectl delete -f https://raw.githubusercontent.com/datastax/cass-operator/master/docs/user/cass-operator-manifests-$(K8S_SERVER_VERSION).yaml .PHONY: k8s/external/cassandra/initialize ## initialize cassandra on k8s diff --git a/charts/vald/values-cassandra.yaml b/charts/vald/values-cassandra.yaml index d630a01300..8770f11888 100644 --- a/charts/vald/values-cassandra.yaml +++ b/charts/vald/values-cassandra.yaml @@ -30,9 +30,7 @@ manager: image: cassandra:latest cassandra: hosts: - - cassandra-0.default.svc.cluster.local - - cassandra-1.default.svc.cluster.local - - cassandra-2.default.svc.cluster.local + - cluster0-dc0-service.cass-operator.svc.cluster.local options: - "-uroot" - "-p${CASSANDRA_PASSWORD}" @@ -55,9 +53,7 @@ manager: enabled: true config: hosts: - - cassandra-0.cassandra.default.svc.cluster.local - - cassandra-1.cassandra.default.svc.cluster.local - - cassandra-2.cassandra.default.svc.cluster.local + - cluster0-dc0-service.cass-operator.svc.cluster.local meta: image: @@ -68,9 +64,7 @@ meta: image: cassandra:latest cassandra: hosts: - - cassandra-0.default.svc.cluster.local - - cassandra-1.default.svc.cluster.local - - cassandra-2.default.svc.cluster.local + - cluster0-dc0-service.cass-operator.svc.cluster.local options: - "-uroot" - "-p${CASSANDRA_PASSWORD}" @@ -93,6 +87,18 @@ meta: enabled: true config: hosts: - - cassandra-0.cassandra.default.svc.cluster.local - - cassandra-1.cassandra.default.svc.cluster.local - - cassandra-2.cassandra.default.svc.cluster.local + - cluster0-dc0-service.cass-operator.svc.cluster.local + +initializer: + cassandra: + enabled: true + env: + - name: CASSANDRA_HOST + value: cluster0-dc0-service.cass-operator.svc.cluster.local + configmap: + enabled: true + secret: + enabled: true + data: + username: cm9vdA== + password: cGFzc3dvcmQ= diff --git a/k8s/external/cassandra/cassandracluster.yaml b/k8s/external/cassandra/cassandracluster.yaml new file mode 100644 index 0000000000..00c75d0c77 --- /dev/null +++ b/k8s/external/cassandra/cassandracluster.yaml @@ -0,0 +1,60 @@ +# +# Copyright (C) 2019-2021 vdaas.org vald team +# +# 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 +# +# https://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. +# +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: cassandra-pv-volume + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 3Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/data" +--- +apiVersion: cassandra.datastax.com/v1beta1 +kind: CassandraDatacenter +metadata: + name: dc0 + namespace: cass-operator +spec: + clusterName: cluster0 + serverType: cassandra + serverVersion: 3.11.7 + managementApiAuth: + insecure: {} + size: 1 + superuserSecretName: cassandra-secret + storageConfig: + cassandraDataVolumeClaimSpec: + storageClassName: manual + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + config: + cassandra-yaml: + authenticator: org.apache.cassandra.auth.PasswordAuthenticator + authorizer: org.apache.cassandra.auth.CassandraAuthorizer + role_manager: org.apache.cassandra.auth.CassandraRoleManager + jvm-options: + initial_heap_size: 400M + max_heap_size: 400M diff --git a/k8s/external/cassandra/statefulset.yaml b/k8s/external/cassandra/statefulset.yaml deleted file mode 100644 index 76cbd92570..0000000000 --- a/k8s/external/cassandra/statefulset.yaml +++ /dev/null @@ -1,80 +0,0 @@ -# -# Copyright (C) 2019-2021 vdaas.org vald team -# -# 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 -# -# https://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. -# -apiVersion: apps/v1 -kind: StatefulSet -metadata: - labels: - app: cassandra - name: cassandra -spec: - serviceName: cassandra - replicas: 3 - selector: - matchLabels: - app: cassandra - template: - metadata: - labels: - app: cassandra - spec: - containers: - - name: cassandra - image: cassandra:latest - imagePullPolicy: Always - lifecycle: - postStart: - exec: - command: - - /bin/sh - - -c - - | - until cqlsh -e 'describe cluster' - do - echo 'waiting for cassandra ready' - sleep 2 - done - cqlsh < /initdb/init.cql - preStop: - exec: - command: - - /bin/sh - - -c - - nodetool drain - env: - - name: CASSANDRA_SEEDS - value: "cassandra-0.cassandra.default.svc.cluster.local" - volumeMounts: - - name: cassandra-initdb - mountPath: /initdb - ports: - - containerPort: 9042 - name: cassandra - protocol: TCP - resources: - requests: - cpu: 100m - memory: 100Mi - terminationMessagePath: /dev/termination-log - terminationMessagePolicy: File - volumes: - - name: cassandra-initdb - configMap: - name: cassandra-initdb - dnsPolicy: ClusterFirst - restartPolicy: Always - schedulerName: default-scheduler - securityContext: {} - terminationGracePeriodSeconds: 30 diff --git a/k8s/external/cassandra/svc.yaml b/k8s/external/cassandra/svc.yaml deleted file mode 100644 index fc130fcca6..0000000000 --- a/k8s/external/cassandra/svc.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright (C) 2019-2021 vdaas.org vald team -# -# 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 -# -# https://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. -# -apiVersion: v1 -kind: Service -metadata: - name: cassandra - labels: - app: cassandra -spec: - ports: - - port: 9042 - targetPort: 9042 - selector: - app: cassandra - clusterIP: None