github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/cloud/kubernetes/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      # Use this annotation in addition to the actual publishNotReadyAddresses
    35      # field below because the annotation will stop being respected soon but the
    36      # field is broken in some versions of Kubernetes:
    37      # https://github.com/kubernetes/kubernetes/issues/58662
    38      service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
    39      # Enable automatic monitoring of all instances when Prometheus is running in the cluster.
    40      prometheus.io/scrape: "true"
    41      prometheus.io/path: "_status/vars"
    42      prometheus.io/port: "8080"
    43  spec:
    44    ports:
    45    - port: 26257
    46      targetPort: 26257
    47      name: grpc
    48    - port: 8080
    49      targetPort: 8080
    50      name: http
    51    # We want all pods in the StatefulSet to have their addresses published for
    52    # the sake of the other CockroachDB pods even before they're ready, since they
    53    # have to be able to talk to each other in order to become ready.
    54    publishNotReadyAddresses: true
    55    clusterIP: None
    56    selector:
    57      app: cockroachdb
    58  ---
    59  apiVersion: policy/v1beta1
    60  kind: PodDisruptionBudget
    61  metadata:
    62    name: cockroachdb-budget
    63    labels:
    64      app: cockroachdb
    65  spec:
    66    selector:
    67      matchLabels:
    68        app: cockroachdb
    69    maxUnavailable: 1
    70  ---
    71  apiVersion: apps/v1
    72  kind: StatefulSet
    73  metadata:
    74    name: cockroachdb
    75  spec:
    76    serviceName: "cockroachdb"
    77    replicas: 3
    78    selector:
    79      matchLabels:
    80        app: cockroachdb
    81    template:
    82      metadata:
    83        labels:
    84          app: cockroachdb
    85      spec:
    86        affinity:
    87          podAntiAffinity:
    88            preferredDuringSchedulingIgnoredDuringExecution:
    89            - weight: 100
    90              podAffinityTerm:
    91                labelSelector:
    92                  matchExpressions:
    93                  - key: app
    94                    operator: In
    95                    values:
    96                    - cockroachdb
    97                topologyKey: kubernetes.io/hostname
    98        containers:
    99        - name: cockroachdb
   100          image: cockroachdb/cockroach:v20.1.1
   101          imagePullPolicy: IfNotPresent
   102          # TODO: Change these to appropriate values for the hardware that you're running. You can see
   103          # the amount of allocatable resources on each of your Kubernetes nodes by running:
   104          #   kubectl describe nodes
   105          # resources:
   106          #   requests:
   107          #     cpu: "16"
   108          #     memory: "8Gi"
   109          #   limits:
   110              # NOTE: Unless you have enabled the non-default Static CPU Management Policy
   111              # and are using an integer number of CPUs, we don't recommend setting a CPU limit.
   112              # See:
   113              #   https://kubernetes.io/docs/tasks/administer-cluster/cpu-management-policies/#static-policy
   114              #   https://github.com/kubernetes/kubernetes/issues/51135
   115              #   cpu: "16"
   116              #   memory: "8Gi" 
   117          ports:
   118          - containerPort: 26257
   119            name: grpc
   120          - containerPort: 8080
   121            name: http
   122          livenessProbe:
   123            httpGet:
   124              path: "/health"
   125              port: http
   126            initialDelaySeconds: 30
   127            periodSeconds: 5
   128          readinessProbe:
   129            httpGet:
   130              path: "/health?ready=1"
   131              port: http
   132            initialDelaySeconds: 10
   133            periodSeconds: 5
   134            failureThreshold: 2
   135          volumeMounts:
   136          - name: datadir
   137            mountPath: /cockroach/cockroach-data
   138          env:
   139          - name: COCKROACH_CHANNEL
   140            value: kubernetes-insecure
   141          command:
   142            - "/bin/bash"
   143            - "-ecx"
   144            # The use of qualified `hostname -f` is crucial:
   145            # Other nodes aren't able to look up the unqualified hostname.
   146            - "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%"
   147        # No pre-stop hook is required, a SIGTERM plus some time is all that's
   148        # needed for graceful shutdown of a node.
   149        terminationGracePeriodSeconds: 60
   150        volumes:
   151        - name: datadir
   152          persistentVolumeClaim:
   153            claimName: datadir
   154    podManagementPolicy: Parallel
   155    updateStrategy:
   156      type: RollingUpdate
   157    volumeClaimTemplates:
   158    - metadata:
   159        name: datadir
   160      spec:
   161        accessModes:
   162          - "ReadWriteOnce"
   163        resources:
   164          requests:
   165            storage: 100Gi