...

Text file src/k8s.io/kubernetes/test/e2e/testing-manifests/statefulset/cockroachdb/statefulset.yaml

Documentation: k8s.io/kubernetes/test/e2e/testing-manifests/statefulset/cockroachdb

     1apiVersion: apps/v1
     2kind: StatefulSet
     3metadata:
     4  name: cockroachdb
     5spec:
     6  serviceName: "cockroachdb"
     7  replicas: 3
     8  selector:
     9    matchLabels:
    10      app: cockroachdb
    11  template:
    12    metadata:
    13      labels:
    14        app: cockroachdb
    15    spec:
    16      # Init containers are run only once in the lifetime of a pod, before
    17      # it's started up for the first time. It has to exit successfully
    18      # before the pod's main containers are allowed to start.
    19      # This particular init container does a DNS lookup for other pods in
    20      # the set to help determine whether or not a cluster already exists.
    21      # If any other pods exist, it creates a file in the cockroach-data
    22      # directory to pass that information along to the primary container that
    23      # has to decide what command-line flags to use when starting CockroachDB.
    24      # This only matters when a pod's persistent volume is empty - if it has
    25      # data from a previous execution, that data will always be used.
    26      initContainers:
    27      - name: bootstrap
    28        image: cockroachdb/cockroach-k8s-init:0.1
    29        imagePullPolicy: IfNotPresent
    30        args:
    31        - "-on-start=/on-start.sh"
    32        - "-service=cockroachdb"
    33        env:
    34        - name: POD_NAMESPACE
    35          valueFrom:
    36            fieldRef:
    37              fieldPath: metadata.namespace
    38        volumeMounts:
    39        - name: datadir
    40          mountPath: "/cockroach/cockroach-data"
    41      affinity:
    42        podAntiAffinity:
    43          preferredDuringSchedulingIgnoredDuringExecution:
    44          - weight: 100
    45            podAffinityTerm:
    46              labelSelector:
    47                matchExpressions:
    48                - key: app
    49                  operator: In
    50                  values:
    51                  - cockroachdb
    52              topologyKey: kubernetes.io/hostname
    53      containers:
    54      - name: cockroachdb
    55        image: cockroachdb/cockroach:v1.0
    56        imagePullPolicy: IfNotPresent
    57        ports:
    58        - containerPort: 26257
    59          name: grpc
    60        - containerPort: 8080
    61          name: http
    62        volumeMounts:
    63        - name: datadir
    64          mountPath: /cockroach/cockroach-data
    65        command:
    66          - "/bin/bash"
    67          - "-ecx"
    68          - |
    69            # The use of qualified `hostname -f` is crucial:
    70            # Other nodes aren't able to look up the unqualified hostname.
    71            CRARGS=("start" "--logtostderr" "--insecure" "--host" "$(hostname -f)" "--http-host" "0.0.0.0")
    72            # We only want to initialize a new cluster (by omitting the join flag)
    73            # if we're sure that we're the first node (i.e. index 0) and that
    74            # there aren't any other nodes running as part of the cluster that
    75            # this is supposed to be a part of (which indicates that a cluster
    76            # already exists and we should make sure not to create a new one).
    77            # It's fine to run without --join on a restart if there aren't any
    78            # other nodes.
    79            if [ ! "$(hostname)" == "cockroachdb-0" ] || \
    80               [ -e "/cockroach/cockroach-data/cluster_exists_marker" ]
    81            then
    82              # We don't join cockroachdb in order to avoid a node attempting
    83              # to join itself, which currently doesn't work
    84              # (https://github.com/cockroachdb/cockroach/issues/9625).
    85              CRARGS+=("--join" "cockroachdb-0.cockroachdb,cockroachdb-1.cockroachdb,cockroachdb-2.cockroachdb")
    86            fi
    87            exec /cockroach/cockroach ${CRARGS[*]}
    88      # No pre-stop hook is required, a SIGTERM plus some time is all that's
    89      # needed for graceful shutdown of a node.
    90      terminationGracePeriodSeconds: 60
    91      volumes:
    92      - name: datadir
    93        persistentVolumeClaim:
    94          claimName: datadir
    95  volumeClaimTemplates:
    96  - metadata:
    97      name: datadir
    98    spec:
    99      accessModes:
   100        - "ReadWriteOnce"
   101      resources:
   102        requests:
   103          storage: 1Gi

View as plain text