最近將Config docker化,部署到Kubernetes的過程中,遇到配置文件拿不到的問題。發現如果是github可以拿到,但是換成私有的倉庫gitlab.xxx.com就拿不到。
通過將git url直接寫成ip地址,避免host映射出現錯誤;還有將SSH的配置掛載到鏡像里,還是拿不到配置文件。最后通過搜索發現官方文檔里有這樣一句話:
It is important that an entry for the Git server be present in the ~/.ssh/known_hosts file and that it is in ssh-rsa format. Other formats (like ecdsa-sha2-nistp256) are not supported.
通過查看known_hosts文件,發現連接github用的是ssh_rsa, 而gitlab.xxx.com是ecdsa-sha2-nistp256。所以為了強制將連接gitlab.xxx.com的簽名類型換成ssh-rsa,首先刪掉known_hosts對應的記錄,在~/.ssh/config和/etc/ssh/ssh_config中添加:
Host 192.168.58.6
RSAAuthentication yes
HostKeyAlgorithms ssh-rsa
Hostname 192.168.58.6
Port 2222
User xxx
IdentityFile /root/.ssh/id_rsa
嘗試ssh -T git@192.168.58.6后,連接類型就變成ssh-rsa。配置文件就拿到了。