github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/cloud/kubernetes/v1.6/cockroachdb-statefulset.yaml (about)

     1  apiVersion: v1
     2  kind: Service
     3  metadata:
     4    # This service is meant to be used by clients of the database. It exposes a ClusterIP that will
     5    # automatically load balance connections to the different database pods.
     6    name: cockroachdb-public
     7    labels:
     8      app: cockroachdb
     9  spec:
    10    ports:
    11    # The main port, served by gRPC, serves Postgres-flavor SQL, internode
    12    # traffic and the cli.
    13    - port: 26257
    14      targetPort: 26257
    15      name: grpc
    16    # The secondary port serves the UI as well as health and debug endpoints.
    17    - port: 8080
    18      targetPort: 8080
    19      name: http
    20    selector:
    21      app: cockroachdb
    22  ---
    23  apiVersion: v1
    24  kind: Service
    25  metadata:
    26    # This service only exists to create DNS entries for each pod in the stateful
    27    # set such that they can resolve each other's IP addresses. It does not
    28    # create a load-balanced ClusterIP and should not be used directly by clients
    29    # in most circumstances.
    30    name: cockroachdb
    31    labels:
    32      app: cockroachdb
    33    annotations:
    34      # This is needed to make the peer-finder work properly and to help avoid
    35      # edge cases where instance 0 comes up after losing its data and needs to
    36      # decide whether it should create a new cluster or try to join an existing
    37      # one. If it creates a new cluster when it should have joined an existing
    38      # one, we'd end up with two separate clusters listening at the same service
    39      # endpoint, which would be very bad.
    40      service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
    41      # Enable automatic monitoring of all instances when Prometheus is running in the cluster.
    42      prometheus.io/scrape: "true"
    43      prometheus.io/path: "_status/vars"
    44      prometheus.io/port: "8080"
    45  spec:
    46    ports:
    47    - port: 26257
    48      targetPort: 26257
    49      name: grpc
    50    - port: 8080
    51      targetPort: 8080
    52      name: http
    53    clusterIP: None
    54    selector:
    55      app: cockroachdb
    56  ---
    57  apiVersion: apps/v1beta1
    58  kind: StatefulSet
    59  metadata:
    60    name: cockroachdb
    61  spec:
    62    serviceName: "cockroachdb"
    63    replicas: 3
    64    template:
    65      metadata:
    66        labels:
    67          app: cockroachdb
    68      spec:
    69        affinity:
    70          podAntiAffinity:
    71            preferredDuringSchedulingIgnoredDuringExecution:
    72            - weight: 100
    73              podAffinityTerm:
    74                labelSelector:
    75                  matchExpressions:
    76                  - key: app
    77                    operator: In
    78                    values:
    79                    - cockroachdb
    80                topologyKey: kubernetes.io/hostname
    81        containers:
    82        - name: cockroachdb
    83          image: cockroachdb/cockroach:v20.1.1
    84          imagePullPolicy: IfNotPresent
    85          ports:
    86          - containerPort: 26257
    87            name: grpc
    88          - containerPort: 8080
    89            name: http
    90          volumeMounts:
    91          - name: datadir
    92            mountPath: /cockroach/cockroach-data
    93          env:
    94          - name: COCKROACH_CHANNEL
    95            value: kubernetes-insecure
    96          command:
    97            - "/bin/bash"
    98            - "-ecx"
    99            # The use of qualified `hostname -f` is crucial:
   100            # Other nodes aren't able to look up the unqualified hostname.
   101            - "exec /cockroach/cockroach start --logtostderr --insecure --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join cockroachdb-0.cockroachdb,cockroachdb-1.cockroachdb,cockroachdb-2.cockroachdb --cache 25% --max-sql-memory 25%"
   102        # No pre-stop hook is required, a SIGTERM plus some time is all that's
   103        # needed for graceful shutdown of a node.
   104        terminationGracePeriodSeconds: 60
   105        volumes:
   106        - name: datadir
   107          persistentVolumeClaim:
   108            claimName: datadir
   109    updateStrategy:
   110      type: RollingUpdate
   111    volumeClaimTemplates:
   112    - metadata:
   113        name: datadir
   114      spec:
   115        accessModes:
   116          - "ReadWriteOnce"
   117        resources:
   118          requests:
   119            storage: 100Gi