diff --git a/repository/cockroachdb/operator/operator.yaml b/repository/cockroachdb/operator/operator.yaml new file mode 100644 index 0000000..a96567f --- /dev/null +++ b/repository/cockroachdb/operator/operator.yaml @@ -0,0 +1,53 @@ +apiVersion: kudo.dev/v1beta1 +name: "CockroachDB" +version: "0.1.0" +kudoVersion: 0.8.0 +kubernetesVersion: 1.13.0 +appVersion: 19.2.1 +maintainers: + - name: liwei + email: "liw327@chinaunicom.cn" +url: "https://www.cockroachlabs.com/" +tasks: +- name: svc + kind: Apply + spec: + resources: + - services.yaml +- name: poddisruptionbudget + kind: Apply + spec: + resources: + - poddisruptionbudget.yaml +- name: sts + kind: Apply + spec: + resources: + - statefulset.yaml +- name: init + kind: Apply + spec: + resources: + - job.yaml +plans: + deploy: + strategy: parallel + phases: + - name: base + strategy: serial + steps: + - name: svc + tasks: + - svc + - name: poddisruptionbudget + tasks: + - poddisruptionbudget + - name: sts + tasks: + - sts + - name: init + strategy: serial + steps: + - name: init + tasks: + - init diff --git a/repository/cockroachdb/operator/params.yaml b/repository/cockroachdb/operator/params.yaml new file mode 100644 index 0000000..821a745 --- /dev/null +++ b/repository/cockroachdb/operator/params.yaml @@ -0,0 +1,46 @@ +apiVersion: kudo.dev/v1beta1 +parameters: + - name: namespace + default: default + - name: serviceAccountName + default: cockroachdb + - name: clusterRoleName + default: cockroachdb + - name: roleName + default: cockroachdb + - name: serviceName + default: cockroachdb + - name: grpcPort + default: 26257 + - name: httpPort + default: 8080 + - name: grpcPortDNSSuffix + default: grpc + - name: httpPortDNSSuffix + default: http + - name: publicServiceName + default: cockroachdb-public + - name: publicGrpcPort + default: 26257 + - name: publicHttpPort + default: 8080 + - name: publicGrpcPortDNSSuffix + default: grpc + - name: publicHttpPortDNSSuffix + default: http + - name: requestCPU + default: 0.1 + - name: requestMemory + default: 1Gi + - name: limitCPU + default: 0.2 + - name: limitMemory + default: 1Gi + - name: initImageVersion + default: 0.4 + - name: imageVersion + default: v19.2.1 + - name: storageClassName + default: default + - name: storageSize + default: 1Gi diff --git a/repository/cockroachdb/operator/templates/job.yaml b/repository/cockroachdb/operator/templates/job.yaml new file mode 100644 index 0000000..0b587ff --- /dev/null +++ b/repository/cockroachdb/operator/templates/job.yaml @@ -0,0 +1,20 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: cluster-init + namespace: {{ .Params.namespace }} + labels: + app: cockroachdb +spec: + template: + spec: + containers: + - name: cluster-init + image: cockroachdb/cockroach:{{ .Params.imageVersion }} + imagePullPolicy: IfNotPresent + command: + - "/cockroach/cockroach" + - "init" + - "--insecure" + - "--host=cockroachdb-0.cockroachdb" + restartPolicy: OnFailure diff --git a/repository/cockroachdb/operator/templates/poddisruptionbudget.yaml b/repository/cockroachdb/operator/templates/poddisruptionbudget.yaml new file mode 100644 index 0000000..c152581 --- /dev/null +++ b/repository/cockroachdb/operator/templates/poddisruptionbudget.yaml @@ -0,0 +1,12 @@ +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: cockroachdb-budget + namespace: {{ .Params.namespace }} + labels: + app: cockroachdb +spec: + selector: + matchLabels: + app: cockroachdb + maxUnavailable: 1 diff --git a/repository/cockroachdb/operator/templates/services.yaml b/repository/cockroachdb/operator/templates/services.yaml new file mode 100644 index 0000000..45c1d5a --- /dev/null +++ b/repository/cockroachdb/operator/templates/services.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Params.publicServiceName }} + namespace: {{ .Params.namespace }} + labels: + app: cockroachdb +spec: + ports: + - port: {{ .Params.grpcPort }} + targetPort: 26257 + name: {{ .Params.grpcPortDNSSuffix }} + - port: {{ .Params.httpPort }} + targetPort: 8080 + name: {{ .Params.httpPortDNSSuffix }} + selector: + app: cockroachdb +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ .Params.serviceName }} + namespace: {{ .Params.namespace }} + labels: + app: cockroachdb + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" + prometheus.io/scrape: "true" + prometheus.io/path: "_status/vars" + prometheus.io/port: "8080" +spec: + ports: + - port: {{ .Params.publicGrpcPort }} + targetPort: 26257 + name: {{ .Params.publicGrpcPortDNSSuffix }} + - port: {{ .Params.publicHttpPort }} + targetPort: 8080 + name: {{ .Params.publicHttpPortDNSSuffix }} + publishNotReadyAddresses: true + clusterIP: None + selector: + app: cockroachdb diff --git a/repository/cockroachdb/operator/templates/statefulset.yaml b/repository/cockroachdb/operator/templates/statefulset.yaml new file mode 100644 index 0000000..449362f --- /dev/null +++ b/repository/cockroachdb/operator/templates/statefulset.yaml @@ -0,0 +1,94 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: cockroachdb + namespace: {{ .Params.namespace }} + labels: + app: cockroachdb +spec: + serviceName: {{ .Params.serviceName }} + replicas: 3 + selector: + matchLabels: + app: cockroachdb + template: + metadata: + labels: + app: cockroachdb + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - cockroachdb + topologyKey: kubernetes.io/hostname + containers: + - name: cockroachdb + image: cockroachdb/cockroach:{{ .Params.imageVersion }} + imagePullPolicy: IfNotPresent + resources: + requests: + cpu: {{ .Params.requestCPU }} + memory: {{ .Params.requestMemory }} + limits: + cpu: {{ .Params.limitCPU }} + memory: {{ .Params.limitMemory }} + ports: + - containerPort: 26257 + name: grpc + - containerPort: 8080 + name: http + livenessProbe: + httpGet: + path: '/health' + port: http + initialDelaySeconds: 30 + periodSeconds: 5 + readinessProbe: + httpGet: + path: '/health?ready=1' + port: http + initialDelaySeconds: 10 + periodSeconds: 5 + failureThreshold: 2 + volumeMounts: + - name: datadir + mountPath: /cockroach/cockroach-data + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: COCKROACH_CHANNEL + value: kubernetes-insecure + command: + - '/bin/bash' + - '-ecx' + - 'exec /cockroach/cockroach start --logtostderr --insecure --advertise-host $(echo $POD_NAME).cockroachdb --http-addr 0.0.0.0 --join cockroachdb-0.cockroachdb,cockroachdb-1.cockroachdb,cockroachdb-2.cockroachdb --cache 25% --max-sql-memory 25%' + terminationGracePeriodSeconds: 60 + volumes: + - name: datadir + persistentVolumeClaim: + claimName: datadir + podManagementPolicy: Parallel + updateStrategy: + type: RollingUpdate + volumeClaimTemplates: + - metadata: + name: datadir + spec: + {{ if ne .Params.storageClassName "default" }} + storageClassName: {{ .Params.storageClassName }} + {{ end }} + accessModes: + - 'ReadWriteOnce' + resources: + requests: + storage: {{ .Params.storageSize }} +