Minikube上Redis集群Pod长期处于Pending状态求助
Redis集群部署Pod Pending问题排查
环境与部署资源
本地Windows机器安装Minikube,通过kubectl create -f <resource> -n <namespace>命令部署Redis集群,创建的资源如下:
1. StorageClass
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: local-storage provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer allowVolumeExpansion: true reclaimPolicy: Delete
2. PersistentVolumes
kind: PersistentVolume metadata: name: local-pv1 spec: storageClassName: local-storage capacity: storage: 1Gi accessModes: - ReadWriteOnce hostPath: path: "/storage/data1" --- apiVersion: v1 kind: PersistentVolume metadata: name: local-pv2 spec: storageClassName: local-storage capacity: storage: 1Gi accessModes: - ReadWriteOnce hostPath: path: "/storage/data2" --- apiVersion: v1 kind: PersistentVolume metadata: name: local-pv3 spec: storageClassName: local-storage capacity: storage: 2Gi accessModes: - ReadWriteOnce hostPath: path: "/storage/data3"
3. Redis ConfigMap
apiVersion: v1 kind: ConfigMap metadata: name: redis-cluster labels: app: redis-cluster data: fix-ip.sh: | #!/bin/sh CLUSTER_CONFIG="/data/nodes.conf" echo "creating nodes" if [ -f ${CLUSTER_CONFIG} ]; then echo "[ INFO ]File:${CLUSTER_CONFIG} is Found" else touch $CLUSTER_CONFIG fi if [ -z "${POD_IP}" ]; then echo "Unable to determine Pod IP address!" exit 1 fi echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}" sed -i.bak -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${CLUSTER_CONFIG} echo "done" exec "$@" redis.conf: |+ cluster-enabled yes cluster-require-full-coverage no cluster-node-timeout 15000 cluster-config-file /data/nodes.conf cluster-migration-barrier 1 appendonly yes protected-mode no
4. Redis集群StatefulSet
apiVersion: apps/v1 kind: StatefulSet metadata: name: redis spec: serviceName: redis replicas: 3 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: initContainers: - name: config image: redis:6.2.3-alpine command: [ "sh", "-c" ] args: - | cp /tmp/redis/redis.conf /etc/redis/redis.conf echo "finding master..." MASTER_FDQN=`hostname -f | sed -e 's/redis-[0-9]\./redis-0./'` if [ "$(redis-cli -h sentinel -p 5000 ping)" != "PONG" ]; then echo "master not found, defaulting to redis-0" if [ "$(hostname)" == "redis-0" ]; then echo "this is redis-0, not updating config..." else echo "updating redis.conf..." echo "slaveof $MASTER_FDQN 6379" >> /etc/redis/redis.conf fi else echo "sentinel found, finding master" MASTER="$(redis-cli -h sentinel -p 5000 sentinel get-master-addr-by-name mymaster | grep -E '(^redis-\d{1,})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})')" echo "master found : $MASTER, updating redis.conf" echo "slaveof $MASTER 6379" >> /etc/redis/redis.conf fi volumeMounts: - name: redis-config mountPath: /etc/redis/ - name: config mountPath: /tmp/redis/ containers: - name: redis image: redis:6.2.3-alpine command: ["redis-server"] args: ["/etc/redis/redis.conf"] ports: - containerPort: 6379 name: redis volumeMounts: - name: data mountPath: /data - name: redis-config mountPath: /etc/redis/ volumes: - name: redis-config emptyDir: {} - name: config configMap: name: redis-config volumeClaimTemplates: - metadata: name: data spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "local-storage" resources: requests: storage: 500Mi
5. Redis无头Service
apiVersion: v1 kind: Service metadata: name: redis-cluster namespace: redis spec: type: ClusterIP ports: - port: 6379 targetPort: 6379 name: client - port: 16379 targetPort: 16379 name: gossip selector: app: redis-cluster
当前问题状态
Pod状态:
redis-cluster-0 0/1 Pending 0 2d
描述Pod时的警告信息:
Warning FailedScheduling 6m24s (x110 over 46h) default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
问题排查方向
- 命名空间一致性检查:无头Service指定了
namespace: redis,需确认其他资源(StatefulSet、PVC)是否也部署在redis命名空间。执行kubectl get pvc -n redis和kubectl get pvc查看PVC存在状态,若跨命名空间会导致PVC无法绑定PV。 - Minikube节点路径验证:PV使用的
/storage/data1等路径是Minikube虚拟机内的路径,而非Windows主机。执行minikube ssh进入节点,检查路径是否存在、权限是否满足redis进程读写:sudo mkdir -p /storage/data1 /storage/data2 /storage/data3 sudo chmod -R 777 /storage - PVC与PV匹配检查:执行
kubectl get pv查看PV状态是否为Available;执行kubectl describe pvc <pvc-name>查看PVC绑定事件,确认是否存在匹配失败的错误信息。 - 标签匹配修正:StatefulSet的Pod标签为
app: redis,但无头Service的selector是app: redis-cluster,标签不匹配会影响集群功能,建议将Service的selector改为app: redis。 - 节点资源与调度检查:执行
kubectl describe node minikube查看节点CPU、内存资源是否充足,确保Pod能被调度到节点(StorageClass设置WaitForFirstConsumer,需Pod调度后才会绑定PV)。
内容的提问来源于stack exchange,提问作者Prakash
相关产品推荐
相关产品推荐

