При очередном деплое — новые поды не стартуют, а сам деплой падает со стандартной ошибкой «Upgrade «CHARTNAME» failed: timed out waiting for the condition«:
wait.go:225: [debug] Deployment is not ready: eks-dev-1-community-api-ns/community-api. 0 out of 3 expected pods are ready
upgrade.go:367: [debug] warning: Upgrade «community-api» failed: timed out waiting for the condition
upgrade.go:385: [debug] Upgrade failed and atomic is set, rolling back to last successful release
Проблема возникает на этапе запуска InitContainer для выполнения SQL-миграций. Сами миграции запускаются не лучшим образом, но — как есть.
Собственно ниже — подебажим запуск таких контейнеров, и зафиксим ошибку.
Содержание
InitContainer — Init:1/2
Проверяем статус подов:
kk -n eks-dev-1-community-api-ns get pod
NAME READY STATUS RESTARTS AGE
community-api-778dfdcd5b-7ckxj 0/1 Init:1/2 0 46m
community-api-778dfdcd5b-dppth 0/1 Init:1/2 0 46m
community-api-778dfdcd5b-wh4wh 1/1 Running 0 8
Статус пода «Init:1/2» — один из двух Init-конейнеров в поде не отработал.
Проверяем state пода:
kk -n eks-dev-1-community-api-ns get pod community-api-778dfdcd5b-7ckxj -o yaml
...
containerStatuses:
- image: projectname/community-api:16.b2cbe959
imageID: ""
lastState: {}
name: community-api
ready: false
restartCount: 0
state:
waiting:
reason: PodInitializing
...
PodInitializing — под ждёт Init-контейнер.
В деплойменте проверим, какие Init-контейнеры должны запуститься:
Тут два контейнера — git-clone, который свою задачу «выполнил» (reason:Completed), и второй контейнер — init-migration, который в статусе running.
Смотрим их логи.
Если просто попробовать посмотреть логи пода — то kubectl сообщит, что:
kk logs -f community-api-778dfdcd5b-7ckxj
Error from server (BadRequest): container "community-api" in pod "community-api-778dfdcd5b-7ckxj" is waiting to start: PodInitializing
Поэтому — указываем контейнер явно. Первым запускается git-clone, указываем его через -c git-clone:
kk -n eks-dev-1-community-api-ns logs community-api-778dfdcd5b-7ckxj -c git-clone
Setting up SSH settings...
Setting up SSH private key...
....
Warning: Permanently added 'github.com,140.82.114.3' (RSA) to the list of known hosts.
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Purging private key...
Собственно — всё понятно: git-clone попытался склонировать репозиторий, не смог, но завершил работу с кодом 0 (name:git-clone ready:true restartCount:0 [...] exitCode:0 в выводе .status.initContainerStatuses), после чего запустился контенер для запуска миграций баз данных, но он отработать не может, так как файлов миграции нет — и он висит.
Проверяем скрипт Гита, который указан в деплойменте — command: ['sh', '-c', '/opt/git/git.sh'] — и используется в нашем контейнере git-clone для клонирования репозитория:
docker run -ti projectname/git-cloner cat /opt/git/git.sh
...
Status: Downloaded newer image for projectname/git-cloner:latest
ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.