github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/opensearch/templates/clusterdefinition.yaml (about)

     1  apiVersion: apps.kubeblocks.io/v1alpha1
     2  kind: ClusterDefinition
     3  metadata:
     4    name: opensearch
     5    labels:
     6      {{- include "opensearch.labels" . | nindent 4 }}
     7  spec:
     8    type: opensearch
     9    connectionCredential:
    10      username: root
    11      password: "$(RANDOM_PASSWD)"
    12      endpoint: "https://$(SVC_FQDN):$(SVC_PORT_http)"
    13      host: "$(SVC_FQDN)"
    14      port: "$(SVC_PORT_http)"
    15    componentDefs:
    16      - name: opensearch
    17        characterType: opensearch
    18        monitor:
    19          builtIn: false
    20          exporterConfig:
    21            scrapePath: /metrics
    22            scrapePort: 9600
    23        configSpecs:
    24        - name: opensearch-config-template
    25          templateRef: opensearch-config-template
    26          volumeName: opensearch-config
    27          namespace: {{.Release.Namespace}}
    28        workloadType: Stateful
    29        service:
    30          ports:
    31            - name: http
    32              port: 9200
    33              targetPort: http
    34            - name: transport
    35              port: 9300
    36              targetPort: transport
    37        volumeTypes:
    38          - name: data
    39            type: data
    40        podSpec:
    41          initContainers:
    42          - name: fsgroup-volume
    43            imagePullPolicy: IfNotPresent
    44            command: ['sh', '-c']
    45            args:
    46            - 'chown -R 1000:1000 /usr/share/opensearch/data'
    47            securityContext:
    48              runAsUser: 0
    49            volumeMounts:
    50            - name: data
    51              mountPath: /usr/share/opensearch/data
    52          - name: sysctl
    53            imagePullPolicy: IfNotPresent
    54            command:
    55            - sh
    56            - -c
    57            - |
    58              set -xe
    59              DESIRED="262144"
    60              CURRENT=$(sysctl -n vm.max_map_count)
    61              if [ "$DESIRED" -gt "$CURRENT" ]; then
    62                sysctl -w vm.max_map_count=$DESIRED
    63              fi
    64            securityContext:
    65              runAsUser: 0
    66              privileged: true
    67          containers:
    68            - name: opensearch
    69              imagePullPolicy: IfNotPresent
    70              readinessProbe:
    71                tcpSocket:
    72                  port: 9200
    73                periodSeconds: 5
    74                timeoutSeconds: 3
    75                failureThreshold: 3
    76              startupProbe:
    77                tcpSocket:
    78                  port: 9200
    79                initialDelaySeconds: 5
    80                periodSeconds: 10
    81                timeoutSeconds: 3
    82                failureThreshold: 30
    83              ports:
    84              - name: http
    85                containerPort: 9200
    86              - name: transport
    87                containerPort: 9300
    88              - name: metrics
    89                containerPort: 9600
    90              env:
    91              - name: node.name
    92                valueFrom:
    93                  fieldRef:
    94                    fieldPath: metadata.name
    95              - name: cluster.initial_master_nodes
    96                value: "$(KB_CLUSTER_NAME)-$(KB_COMP_NAME)-0"
    97              - name: discovery.seed_hosts
    98                value: "$(KB_CLUSTER_NAME)-$(KB_COMP_NAME)-headless"
    99              - name: cluster.name
   100                value: "$(KB_CLUSTER_NAME)"
   101              - name: network.host
   102                value: "0.0.0.0"
   103              - name: OPENSEARCH_JAVA_OPTS
   104                value: "-Xmx512M -Xms512M"
   105              - name: node.roles
   106                value: "master,ingest,data,remote_cluster_client"
   107              volumeMounts:
   108                - mountPath: /usr/share/opensearch/data
   109                  name: data
   110                - mountPath: /usr/share/opensearch/config/opensearch.yaml
   111                  subPath: opensearch.yaml
   112                  name: opensearch-config
   113            - name: opensearch-master-graceful-termination-handler
   114              imagePullPolicy: IfNotPresent
   115              command:
   116              - "sh"
   117              - -c
   118              - |
   119                #!/usr/bin/env bash
   120                set -eo pipefail
   121  
   122                http () {
   123                    local path="${1}"
   124                    if [ -n "${USERNAME}" ] && [ -n "${PASSWORD}" ]; then
   125                      BASIC_AUTH="-u ${USERNAME}:${PASSWORD}"
   126                    else
   127                      BASIC_AUTH=''
   128                    fi
   129                    curl -XGET -s -k --fail ${BASIC_AUTH} https://$(KB_CLUSTER_NAME)-$(KB_COMP_NAME)-headless:9200:${path}
   130                }
   131  
   132                cleanup () {
   133                  while true ; do
   134                    local master="$(http "/_cat/master?h=node" || echo "")"
   135                    if [[ $master == "$(KB_CLUSTER_NAME)-$(KB_COMP_NAME)"* && $master != "${NODE_NAME}" ]]; then
   136                      echo "This node is not master."
   137                      break
   138                    fi
   139                    echo "This node is still master, waiting gracefully for it to step down"
   140                    sleep 1
   141                  done
   142  
   143                  exit 0
   144                }
   145  
   146                trap cleanup SIGTERM
   147  
   148                sleep infinity &
   149                wait $!
   150      - name: dashboard
   151        characterType: opensearch-dashboard
   152        workloadType: Stateless
   153        service:
   154          ports:
   155          - name: http
   156            port: 5601
   157            targetPort: http
   158        podSpec:
   159          containers:
   160          - name: dashboard
   161            imagePullPolicy: "{{ .Values.image.pullPolicy }}"
   162            command:
   163            - sh
   164            - -c
   165            - |
   166              #!/usr/bin/bash
   167              set -e
   168              bash opensearch-dashboards-docker-entrypoint.sh opensearch-dashboards
   169            env:
   170            - name: OPENSEARCH_HOSTS
   171              valueFrom:
   172                secretKeyRef:
   173                  name: $(CONN_CREDENTIAL_SECRET_NAME)
   174                  key: endpoint
   175                  optional: false
   176            - name: SERVER_HOST
   177              value: "0.0.0.0"
   178            startupProbe:
   179              tcpSocket:
   180                port: 5601
   181              periodSeconds: 10
   182              timeoutSeconds: 5
   183              failureThreshold: 20
   184              successThreshold: 1
   185              initialDelaySeconds: 10
   186            livenessProbe:
   187              tcpSocket:
   188                port: 5601
   189              periodSeconds: 20
   190              timeoutSeconds: 5
   191              failureThreshold: 10
   192              successThreshold: 1
   193              initialDelaySeconds: 10
   194            readinessProbe:
   195              tcpSocket:
   196                port: 5601
   197              periodSeconds: 20
   198              timeoutSeconds: 5
   199              failureThreshold: 10
   200              successThreshold: 1
   201              initialDelaySeconds: 10
   202            ports:
   203            - containerPort: 5601
   204              name: http
   205              protocol: TCP