实验环境的kubernetes服务器物理机忽然断电,重启后helm 部署的harbor出现了启动故障,首先查看harbor 相关容器运行状态:redis
前面两个CrashLoopBackOff的容器,能够的使用命令删除容器,就能够解决,关键的是redis 容器,删除是解决不了的。
使用命令查看容器的日志。api
[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>
简单理解:文件格式损坏,作个备份,使用命令修复。bash
关键问题是pod启动不起来,不能直接进去修复,因此关键问题仍是让redis的容器启动起来,想让pod起来就必须不让容器加载以前的appendonly.aof文件,找到appendonly.aof重命名,让redis容器从新生成appendonly.aof。服务器
接着查看容器的描述:app
# kubectl describe po hub-redis-master-0
能够获取到须要的信息:ide
/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的建立信息:oop
[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。spa
进入到容器:日志
[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
修复code
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自动从新创建就能够了。