k8s.io/kubernetes@v1.29.3/test/e2e/testing-manifests/statefulset/mysql-upgrade/statefulset.yaml (about)

     1  apiVersion: apps/v1
     2  kind: StatefulSet
     3  metadata:
     4    name: mysql
     5  spec:
     6    serviceName: mysql
     7    replicas: 3
     8    selector:
     9      matchLabels:
    10        app: mysql
    11    template:
    12      metadata:
    13        labels:
    14          app: mysql
    15      spec:
    16        initContainers:
    17        - name: init-mysql
    18          image: mysql:5.7
    19          command:
    20          - bash
    21          - "-c"
    22          - |
    23            set -ex
    24            [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
    25            ordinal=${BASH_REMATCH[1]}
    26            echo [mysqld] > /mnt/conf.d/server-id.cnf
    27            echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
    28            if [[ $ordinal -eq 0 ]]; then
    29              cp /mnt/config-map/master.cnf /mnt/conf.d/
    30            else
    31              cp /mnt/config-map/slave.cnf /mnt/conf.d/
    32            fi
    33          volumeMounts:
    34          - name: conf
    35            mountPath: /mnt/conf.d
    36          - name: config-map
    37            mountPath: /mnt/config-map
    38        - name: clone-mysql
    39          image: gcr.io/google-samples/xtrabackup:1.0
    40          command:
    41          - bash
    42          - "-c"
    43          - |
    44            set -ex
    45            [[ -d /var/lib/mysql/mysql ]] && exit 0
    46            [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
    47            ordinal=${BASH_REMATCH[1]}
    48            [[ $ordinal -eq 0 ]] && exit 0
    49            ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql
    50            xtrabackup --prepare --target-dir=/var/lib/mysql
    51          volumeMounts:
    52          - name: data
    53            mountPath: /var/lib/mysql
    54            subPath: mysql
    55          - name: conf
    56            mountPath: /etc/mysql/conf.d
    57        containers:
    58        - name: mysql
    59          image: mysql:5.7.15
    60          env:
    61          - name: MYSQL_ALLOW_EMPTY_PASSWORD
    62            value: "1"
    63          ports:
    64          - name: mysql
    65            containerPort: 3306
    66          volumeMounts:
    67          - name: data
    68            mountPath: /var/lib/mysql
    69            subPath: mysql
    70          - name: conf
    71            mountPath: /etc/mysql/conf.d
    72          resources:
    73            requests:
    74              cpu: 1
    75              memory: 1Gi
    76          livenessProbe:
    77            exec:
    78              command: ["mysqladmin", "ping"]
    79            initialDelaySeconds: 30
    80            timeoutSeconds: 5
    81          readinessProbe:
    82            exec:
    83              command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
    84            initialDelaySeconds: 5
    85            timeoutSeconds: 1
    86        - name: xtrabackup
    87          image: gcr.io/google-samples/xtrabackup:1.0
    88          ports:
    89          - name: xtrabackup
    90            containerPort: 3307
    91          command:
    92          - bash
    93          - "-c"
    94          - |
    95            set -ex
    96            cd /var/lib/mysql
    97  
    98            if [[ -f xtrabackup_slave_info ]]; then
    99              mv xtrabackup_slave_info change_master_to.sql.in
   100              rm -f xtrabackup_binlog_info
   101            elif [[ -f xtrabackup_binlog_info ]]; then
   102              [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
   103              rm xtrabackup_binlog_info
   104              echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
   105                    MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
   106            fi
   107  
   108            if [[ -f change_master_to.sql.in ]]; then
   109              echo "Waiting for mysqld to be ready (accepting connections)"
   110              until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
   111  
   112              echo "Initializing replication from clone position"
   113              mv change_master_to.sql.in change_master_to.sql.orig
   114              mysql -h 127.0.0.1 <<EOF
   115            $(<change_master_to.sql.orig),
   116              MASTER_HOST='mysql-0.mysql',
   117              MASTER_USER='root',
   118              MASTER_PASSWORD='',
   119              MASTER_CONNECT_RETRY=10;
   120            START SLAVE;
   121            EOF
   122            fi
   123  
   124            exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
   125              "xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
   126          volumeMounts:
   127          - name: data
   128            mountPath: /var/lib/mysql
   129            subPath: mysql
   130          - name: conf
   131            mountPath: /etc/mysql/conf.d
   132          resources:
   133            requests:
   134              cpu: 100m
   135              memory: 100Mi
   136        volumes:
   137        - name: conf
   138          emptyDir: {}
   139        - name: config-map
   140          configMap:
   141            name: mysql
   142    volumeClaimTemplates:
   143    - metadata:
   144        name: data
   145      spec:
   146        accessModes: ["ReadWriteOnce"]
   147        storageClassName: default
   148        resources:
   149          requests:
   150            storage: 10Gi
   151  ---
   152  apiVersion: policy/v1
   153  kind: PodDisruptionBudget
   154  metadata:
   155   name: mysql-pdb
   156   labels:
   157     pdb: mysql
   158  spec:
   159   minAvailable: 2
   160   selector:
   161     matchLabels:
   162       app: mysql