kubernetes redis pod CrashLoopBackOff修復心得

前言

實驗環境的kubernetes服務器物理機突然斷電,重啓後helm 部署的harbor出現了啓動故障,首先查看harbor 相關容器運行狀態:
kubernetes redis pod CrashLoopBackOff修復心得

解決方法

前面兩個CrashLoopBackOff的容器,可以的使用命令刪除容器,就可以解決,關鍵的是redis 容器,刪除是解決不了的。
kubernetes redis pod CrashLoopBackOff修復心得
使用命令查看容器的日誌。

[root@master ~]# kubectl logs hub-redis-master-0 

Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>

簡單理解:文件格式損壞,做個備份,使用命令修復。

關鍵問題是pod啓動不起來,不能直接進去修復,所以關鍵問題還是讓redis的容器啓動起來,想讓pod起來就必須不讓容器加載之前的appendonly.aof文件,找到appendonly.aof重命名,讓redis容器重新生成appendonly.aof。

查找appendonly.aof

接着查看容器的描述:

# kubectl describe po hub-redis-master-0 

kubernetes redis pod CrashLoopBackOff修復心得
可以獲取到需要的信息:

/bitnami/redis/data   #aof在容器上的路徑
Volumes:   #redis pod的pvc信息
  redis-data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  redis-data-hub-redis-master-0

確認redis 容器使用的 pv,獲取pv的創建信息:

[root@master ~]# kubectl get pv | grep redis
pv006      100Gi      RWO            Recycle          Bound     default/redis-data-hub-redis-master-0 
[root@master ~]# kubectl describe pv pv006
Name:            pv006
Labels:          <none>
Annotations:     kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"name":"pv006","namespace":""},"spec":{"accessModes":["ReadWriteOnce"],"capac...
                 pv.kubernetes.io/bound-by-controller=yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    
Status:          Bound
Claim:           default/redis-data-hub-redis-master-0
Reclaim Policy:  Recycle
Access Modes:    RWO
Capacity:        100Gi
Node Affinity:   <none>
Message:         
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    192.168.2.4
    Path:      /volume1/harbor/nfs6
    ReadOnly:  false
Events:        <none>

這裏可以找到nfs對應的路徑,直接進入nfs服務器對應路徑下重命名appendonly.aof,redis的pod就立即啓動狀態爲running了,接下來就是修復appendonly.aof。
kubernetes redis pod CrashLoopBackOff修復心得

修復appendonly.aof

進入到容器:

[root@master ~]# kubectl exec -it hub-redis-master-0 bash
I have no name!@hub-redis-master-0:/$ ls /bitnami/redis/data/
appendonly.aof      appendonly.bak.aof  dump.rdb            

修復

redis-check-aof --fix /bitnami/redis/data/appendonly.bak.aof
0x           10f69: Expected prefix '*', got: '
AOF analyzed: size=10316900, ok_up_to=69481, diff=10247419
This will shrink the AOF from 10316900 bytes, with 10247419 bytes, to 69481 bytes
Continue? [y/N]: y
Successfully truncated AOF

現在就可以把正在使用的appendonly.aof 重命名,把修復後的aof命名爲appendonly.aof ,刪除容器,kubernetes自動重新創建redis容器,如果其它容器還是CrashLoopBackOff,這可能是redis沒有啓動導致的,redis修復好後,刪除CrashLoopBackOff的容器,kubernetes自動重新建立就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章