问题描述
下面是我的 statefulset。
apiVersion: apps/v1
kind: StatefulSet
Metadata:
namespace: dev
name: MysqL
spec:
selector:
matchLabels:
app: MysqL
serviceName: MysqL
replicas: 2
template:
Metadata:
labels:
app: MysqL
spec:
initContainers:
- name: init-MysqL
image: MysqL:5.7
command:
- bash
- "-c"
- |
set -ex
# Generate MysqL server-id from pod ordinal index.
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
echo [MysqLd] > /mnt/conf.d/server-id.cnf
# Add an offset to avoid reserved server-id=0 value.
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
# copy appropriate conf.d files from config-map to emptyDir.
if [[ $ordinal -eq 0 ]]; then
cp /mnt/config-map/master.cnf /mnt/conf.d/
else
cp /mnt/config-map/slave.cnf /mnt/conf.d/
fi
volumeMounts:
- name: conf
mountPath: /mnt/conf.d
- name: config-map
mountPath: /mnt/config-map
- name: clone-MysqL
image: gcr.io/google-samples/xtrabackup:1.0
command:
- bash
- "-c"
- |
set -ex
# Skip the clone if data already exists.
[[ -d /var/lib/MysqL/MysqL ]] && exit 0
# Skip the clone on leader (ordinal index 0).
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
[[ $ordinal -eq 0 ]] && exit 0
# Clone data from prevIoUs peer.
ncat --recv-only MysqL-$(($ordinal-1)).MysqL 3307 | xbstream -x -C /var/lib/MysqL
# Prepare the backup.
xtrabackup --prepare --target-dir=/var/lib/MysqL
volumeMounts:
- name: data
mountPath: /var/lib/MysqL
subPath: MysqL
- name: conf
mountPath: /etc/MysqL/conf.d
containers:
- name: MysqL
image: MysqL:5.7
env:
- name: MysqL_ALLOW_EMPTY_PASSWORD
value: "1"
ports:
- name: MysqL
containerPort: 3306
volumeMounts:
- name: data
mountPath: /var/lib/MysqL
subPath: MysqL
- name: conf
mountPath: /etc/MysqL/conf.d
resources:
requests:
cpu: 500m
memory: 1Gi
livenessProbe:
exec:
command: ["MysqLadmin","ping"]
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
readinessProbe:
exec:
# Check we can execute queries over TCP (skip-networking is off).
command: ["MysqL","-h","127.0.0.1","-e","SELECT 1"]
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
- name: xtrabackup
image: gcr.io/google-samples/xtrabackup:1.0
ports:
- name: xtrabackup
containerPort: 3307
command:
- bash
- "-c"
- |
set -ex
cd /var/lib/MysqL
# Determine binlog position of cloned data,if any.
if [[ -f xtrabackup_slave_info ]]; then
# XtraBackup already generated a partial "CHANGE MASTER TO" query
# because we're cloning from an existing follower.
mv xtrabackup_slave_info change_master_to.sql.in
# Ignore xtrabackup_binlog_info in this case (it's useless).
rm -f xtrabackup_binlog_info
elif [[ -f xtrabackup_binlog_info ]]; then
# We're cloning directly from leader. Parse binlog position.
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
rm xtrabackup_binlog_info
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
fi
# Check if we need to complete a clone by starting replication.
if [[ -f change_master_to.sql.in ]]; then
echo "Waiting for MysqLd to be ready (accepting connections)"
until MysqL -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
echo "Initializing replication from clone position"
# In case of container restart,attempt this at-most-once.
mv change_master_to.sql.in change_master_to.sql.orig
MysqL -h 127.0.0.1 <<EOF
$(<change_master_to.sql.orig),MASTER_HOST='MysqL-0.MysqL',MASTER_USER='root',MASTER_PASSWORD='',MASTER_CONNECT_RETRY=10;
START SLAVE;
EOF
fi
# Start a server to send backups when requested by peers.
exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
"xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"
volumeMounts:
- name: data
mountPath: /var/lib/MysqL
subPath: MysqL
- name: conf
mountPath: /etc/MysqL/conf.d
resources:
requests:
cpu: 100m
memory: 100Mi
volumes:
- name: conf
emptyDir: {}
- name: config-map
configMap:
name: MysqL-config
volumeClaimTemplates:
- Metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "MysqL-gp2-sc"
resources:
requests:
storage: 10Gi
申请后,我遇到了这个问题,
NAME READY STATUS RESTARTS AGE
MysqL-0 3/3 Running 0 8m13s
MysqL-1 0/3 Init:1/3 0 7m46s
看不到任何日志,因为它只是初始化阶段!
Kubectl 描述 pod
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
normal Scheduled 4m3s default-scheduler Successfully assigned dev/MysqL-1 to ip-10-8-0-50.ap-south-1.compute.internal
normal SuccessfulAttachVolume 4m1s attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-07f32fcd-5382-4cfe-a73d-19eea7404c13"
normal Pulled 3m53s kubelet Container image "MysqL:5.7" already present on machine
normal Created 3m53s kubelet Created container init-MysqL
normal Started 3m53s kubelet Started container init-MysqL
normal Pulled 3m52s kubelet Container image "gcr.io/google-samples/xtrabackup:1.0" already present on machine
normal Created 3m52s kubelet Created container clone-MysqL
normal Started 3m52s kubelet Started container clone-MysqL
Kubectl 获取 pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-MysqL-0 Bound pvc-6eada99d-fb72-4419-9181-adfeabe960a1 10Gi RWO MysqL-gp2-sc 9m55s
data-MysqL-1 Bound pvc-07f32fcd-5382-4cfe-a73d-19eea7404c13 10Gi RWO MysqL-gp2-sc 9m28s
见鬼去吧, 我坚持了 2 天,非常感谢任何帮助或调试。提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)